AnsweredAssumed Answered

HAL_UART_RxCpltCallback stops reading on 0x00

Question asked by van_o.martin on Nov 20, 2016
Hallo,

I try to read binary data from PC to STM32 F405. 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 using HAL_UART_RxCpltCallback and HAL_UART_Receive_IT to receive data.

Everything works fine until there is no 0x00 in data.

For example if I send from PC  0x10 0x02 0x50 0x01 0x01 0x20 0x10 0x03 on STM i will get following 0x50 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 0x01.

Here is my code.
01.void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
02.{
03.    uint8_t i;
04.     
05.    if (huart->Instance == UART4)
06.    {
07.        if (Rx_index == 0)
08.        {
09.            for (i = 0; i < 100; i++) Rx_Buffer[i] = 0;
10.        }
11. 
12.        if(Rx_data[0] == DLE && wasDLE == false)
13.        {
14.            wasDLE = true;
15.            HAL_UART_Receive_IT(&huart4, Rx_data, 1);
16.            return;
17.        }
18.         
19.        if(Rx_data[0] == STX && wasDLE == true && packet == false)
20.        {
21.            packet = true;
22.            wasDLE = false;
23.            HAL_UART_Receive_IT(&huart4, Rx_data, 1);
24.            return;
25.        }
26. 
27.        if(Rx_data[0] == ETX && wasDLE == true && packet == true)
28.        {
29.            Rx_index = 0;
30.            TX_cplt = 1;
31.            packet = false;
32.            HAL_UART_Receive_IT(&huart4, Rx_data, 1);
33.            return;
34.        }
35.         
36.        if(packet == true)
37.        {
38.            Rx_Buffer[Rx_index++] = Rx_data[0];
39.            wasDLE = false;
40.        }      
41.         
42.        HAL_UART_Receive_IT(&huart4, Rx_data, 1);
43.    }
44.}

Baudrate is set to 115200.

Thanks

Martin

Outcomes