cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F746 unknown length packet receive throught UART

chrischris94
Associate
Posted on June 07, 2016 at 19:06

Hi,

I have an STM32F746 connected to an other processor through UART (TX-RX). The goal is to exchange data with this other processor with a library provided by the supplier. The only things I have to do is to re write the read and write function to communicate.

The write function works well. The issue is about the read function.

There is two kinds of communication via the UART bus.

- the F746 send a request via TX and wait for the response via RX

- asynchronous events appears on the other side of the bus, and a message is send to the F746 via RX

So I need to manage booth cases.

In all of them, the length of the received packet is unknown. The library provided divide each packet in subpacket of 32 bytes. So the receive function had to put in a buffer the received data and return the number of received bytes (up to 32). At the end of a timeout manager (already programmed) the library recreate a packet with all the subpacket received and try to manage it with the library.

For the moment I tried to use the easyiest way :

static uint32_t read_data()

{

uint32_t num_data = 0;

uint8_t test = 0;

uint8_t temp[UHIP_CHUNK_SIZE];

HAL_StatusTypeDef uartStatus;

while(test < 32)

{

uartStatus = HAL_UART_Receive(&UartHandle,&temp[num_data],1,10);

if(uartStatus == HAL_OK)

{

rx_in_buffer[num_data] = temp[num_data];

num_data = num_data + 1;

test = test + 1;

}

else

{

test = 32;

}

}

return num_data;

}

I only have one value received, but with my oscilloscope I see a complete packet.

What can I do to manage such kind of packet reception ?

For the future, I also looking for a non blocking receive function.

#stm-32-f746-uart-hal
1 REPLY 1