cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_UART_RxCpltCallback stops reading on 0x00

vancom
Associate
Posted on November 20, 2016 at 00:32

Hallo,

I try to read binary data from PC to STM32 F Data are framed in following format. DLE STX DATA DLE ETX (0x10 0x02 DATA 0x10 0x03). My goal is to read DATA bytes. I'm usingHAL_UART_RxCpltCallback andHAL_UART_Receive_IT to receive data. Everything works fine until there is no 0x00 in data. For example if I send from PC0x10 0x02 0x50 0x01 0x01 0x20 0x10 0x03 on STM i will get following0x50 0x01 0x01 0x20 which is correct. But when there is 0x00 in data, for example 0x01 0x00 0x08 0xaa 0xbb 0xcc 0xdd 0xee 0xff 0xab 0xcd, on STM I will get only 0x Here is my code.


void
HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

uint8_t i;


if
(huart->Instance == UART4)

{

if
(Rx_index == 0)

{

for
(i = 0; i < 100; i++) Rx_Buffer[i] = 0;

}


if
(Rx_data[0] == DLE && wasDLE == 
false
)

{

wasDLE = 
true
;

HAL_UART_Receive_IT(&huart4, Rx_data, 1);

return
;

}


if
(Rx_data[0] == STX && wasDLE == 
true
&& packet == 
false
)

{

packet = 
true
;

wasDLE = 
false
;

HAL_UART_Receive_IT(&huart4, Rx_data, 1);

return
;

}


if
(Rx_data[0] == ETX && wasDLE == 
true
&& packet == 
true
)

{

Rx_index = 0;

TX_cplt = 1;

packet = 
false
;

HAL_UART_Receive_IT(&huart4, Rx_data, 1);

return
;

}


if
(packet == 
true
)

{

Rx_Buffer[Rx_index++] = Rx_data[0];

wasDLE = 
false
;

} 


HAL_UART_Receive_IT(&huart4, Rx_data, 1);

}

}

Baudrate is set to 115 Thanks Martin #!cubemx-!code-generation #stm32-usart
0 REPLIES 0