-
1. Re: UART communication between two PSoC
carlosf_91 Feb 27, 2018 4:20 AM (in response to spgermany7_1996721)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,
-
2. Re: UART communication between two PSoC
spgermany7_1996721 Feb 27, 2018 4:32 AM (in response to carlosf_91)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
carlosf_91 Feb 27, 2018 6:14 AM (in response to spgermany7_1996721)1 of 1 people found this helpfulI 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.
Regards,
-
4. Re: UART communication between two PSoC
user_1377889 Feb 27, 2018 7:33 AM (in response to carlosf_91)1 of 1 people found this helpfulThis 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)
Bob
-
5. Re: UART communication between two PSoC
user_1269049 Mar 6, 2018 8:10 AM (in response to user_1377889)1 of 1 people found this helpfulI 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.