UART communication between two PSoC

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi all,

I was trying to for UART communication between two PSoCs.

The first PSoC keeps sending 5bytes of data at every 10ms. The first bytes is constant say 0x08 and rest 4 byte is a float value.

And the second PSoC is recieving.

Both UART were configured at 57600baud rate.

The second PSoC receives everything in correct order, when it is programmed. But after a power cycle, it receives 5 bytes but sometimes not in the correct order.

eg.

if you are sending 200 as float. 200 --> 0x42c80000

first psoc is sending 08 00 00 c8 42.

But SOMETIMES after power cycle, second might receive  c8 42 08 00 00. but sometimes in the rights order.

CY_ISR(uart_rx)

{

    uint8 Index = 0;

    float value;

    if (UART_GetRxBufferSize() == 5)

        {

            for(Index = 0; Index < UART_RX_BUFFER_SIZE; Index++)

                COM_UART_Rx_Buffer[Index]= UART_GetChar();

            if (COM_UART_Rx_Buffer[0] == 0x08 )

                {

                    memcpy(&value,&COM_UART_Rx_Buffer[1],4);  

                }

             UART_ClearRxBuffer(); 

        }      

}

The Rx buffer of second PSoC is 5.

I dont know how can i synchronise the two PSoCs.

Thanks in advance

0 Likes
1 Solution
Anonymous
Not applicable

Hello,

It is possible that your device is booting while in the middle of a packet transmission. So naturally the received bytes are shifted.

I would recommend that you expand your protocol, say have a fixed start byte + 5 bytes of data + fixed end byte. The PSoC receiving this would look for these known start/end bytes and try to synchronize.

You could also make the receiving PSoC send a stop/start command to receive data at startup.

Regards,

View solution in original post

0 Likes
5 Replies