5 Replies Latest reply on Mar 6, 2018 8:10 AM by gunoc_288966

    UART communication between two PSoC


      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.


      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.


          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 )


      The Rx buffer of second PSoC is 5.


      I dont know how can i synchronise the two PSoCs.


      Thanks in advance

        • 1. Re: UART communication between two PSoC



          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.



          • 2. Re: UART communication between two PSoC

            Thanks for the reply.

            I have the start byte 0x08.
            But how can I synchronize it with the receiving PSoC.


            Since I thought the same, I kept a switch at 1st PSoC, so when I press it the uart trasmission begins from 1st PSoC. This should solve the boot up time.

            • 3. Re: UART communication between two PSoC

              I see two problems:


              1. You are detecting that you are out of sync, by checking for the start byte. But your code waits for the next 5 bytes which will stay out of sync. Possible solution: Read until you find your start byte, then read the following 4 bytes.


              2. Only having a start byte is unreliable. You say you have a float number. It very likely that your start byte will also be in the float number. Try at least expanding the start of protocol to 16 bits, reducing considerably the possibility of finding this combination in the float number.



              1 of 1 people found this helpful
              • 4. Re: UART communication between two PSoC

                This is a matter of protocol. You could resove that problem by

                Second PSoC sends a byte

                First PSoc answers with a float number (fixed number of bytes)



                1 of 1 people found this helpful
                • 5. Re: UART communication between two PSoC

                  I always use a state machine in the receiving devide.


                  State 0: read byte. If it is the start byte, go to state 1, else stay in state 0.


                  state 1: receive 4 bytes, then go to state 2.


                  state 2: receive a checksum (CRC16 recommended). If checksum is correct, evaluate the bytes received in state 1, otherwise ignore them. In any case go back to state 0.


                  Checking for the start byte in case 0 makes it very likely to be in sync, but it is not guaranteed. After a few cycles the state machine will be in sync.

                  1 of 1 people found this helpful