cancel
Showing results for 
Search instead for 
Did you mean: 

IBUS Signal Reading From UART

HEKEN.1
Associate

I have FlySky X6B Receiver and it has IBUS output. I'm trying to read IBUS signal from UART port of STM32F407VGT6 Discovery card. Baudrate is 115200. My private codes in below. I'm expecting to read values 1000 to 2000 but my results are like 5900 4899 . What is wrong in my code? The logic of IBUS is that it has 32 bytes signal. First 2 byte is header. First byte is 0x20 and second byte ise 0x40. After that each channel messages of transmitter signal is 2 bytes. Last 2 bytes is checksum. I'm using STMCube IDE and in my code i'm calling function in while(1) in main.c file. I'm thinking it about UART Receive or Transmit error but i'm not sure.

#define IBUS_BUFFSIZE 32
#define IBUS_MAXCHANNELS 14
#########################################################
static uint8_t ibusIndex = 0;
static uint8_t ibus[IBUS_BUFFSIZE] = {0};
static uint16_t rcValue[IBUS_MAXCHANNELS];
uint8_t val=0;
char value[32]= {0};
#########################################################
void readRx() {
	HAL_UART_Receive(&huart2, &val, sizeof(val), 200);
	//HAL_UART_Transmit(&huart2, val, sizeof(val), 200);
	if (val == 0x20 || ibus[0] == 0x20) {
		ibus[0] = 0x20;
		if (val == 0x40 || ibus[1] == 0x40) {
			ibus[1] = 0x40;
			if (ibusIndex == IBUS_BUFFSIZE) {
				ibusIndex = 0;
				int high = 3;
				int low = 2;
				for (int i = 0; i < IBUS_MAXCHANNELS; i++) {
					//left shift away the first 8 bits of the first byte and add the whole value of the previous one
					rcValue[i] = (ibus[high] << 8) + ibus[low];
					sprintf(value,"%hu", rcValue[i]);
					HAL_UART_Transmit(&huart2, value, sizeof(value), 200);
					HAL_UART_Transmit(&huart2, "\n\r", sizeof("\n\r"), 200);
 
					high += 2;
					low += 2;
				}
				return;
			} else {
				ibus[ibusIndex] = val;
				ibusIndex++;
			}
 
		} else {
			return;
		}
	} else {
		return;
	}
 
}

1 REPLY 1
TDK
Guru

Put a logic analyzer on the line so you can separate your program logic from what's happening on the bus.

One strong possibility is your code isn't ready to receive characters even though they're coming in on the line. Consider receiving all 32 characters at once, or receiving via circular DMA and polling for new characters as they come on.

If you feel a post has answered your question, please click "Accept as Solution".