-
1. Re: UART RX bytes in wrong order
bob.marlowe Jan 17, 2016 12:00 PM (in response to richard_1498031)You can be quite sure that the UART does not save the received bytes in a wrong order, no way.
What I presume is that you miss the first byte which gets appended in the next round as the last one.
Your code looks quite ok, but you do not check for errors which would be done when you use the API provided.
I would suggest to check for overruns.
Bob
-
2. Re: UART RX bytes in wrong order
user_49271930 Jan 17, 2016 12:49 PM (in response to richard_1498031)
Unfortunately, I can not evaluate the project, but I can offer my variant solutions for MODBUS
PSoC4: PSoC 4ModbusSlave.cywrk.zip
PSoC5LP: PSoC5LP_ModbusSlave.zip
Read more here(russian): http://mylab.wmsite.ru/moi-razrab/cypress-psoc/modbus/
I used the achievements Sam Walsh:
https://github.com/EmbeddedSam/Modbus-Slave-for-PSoC4 -
3. Re: UART RX bytes in wrong order
richard_1498031 Jan 17, 2016 2:45 PM (in response to bob.marlowe)You can be quite sure that the UART does not save the received bytes in a wrong order, no way.
I know...
I'll attach two scope pictures. RS485 pin is just used for testing.
IdleTimerFlg.jpg is where RS485 pin is set to same value as IdleFlg which is used to catch first byte after bus was idle. Which also lead me to ask, is there no UART interrupt to detect that bus was idle for at least one frame?
Second scope picture (HiOnFirstByte.jpg) RS485 pin is set high when detecting byte 0x02 and set low for the other three bytes.
As you can see signal is set high ~6µS after last stop bit in packet arrived. This is where I loose it, why is first byte in packet detected as last one??
Pavloven: Thanks for your files. We already have several products successfully running MODBUS, I've just copied needed functions from our existing code.
-
HiOnFirstByte.jpg 82.2 K
-
IdleTimerFlg.jpg 82.0 K
-
-
4. Re: UART RX bytes in wrong order
user_49271930 Jan 17, 2016 8:34 PM (in response to richard_1498031)This is very similar to the presence of the capacitor at the output tx_en (Baudrate is 921600).
you can check for Baudrate 9600? -
5. Re: UART RX bytes in wrong order
user_78878863 Jan 18, 2016 2:54 PM (in response to richard_1498031)Since this baud rate is quite high to handle in software - you really need to check for buffer overruns. When you use the scope for checking, you need to look at the first transmission and see whether it gets handled correctly or not (otherwise Bobs scenario happens).
-
6. Re: UART RX bytes in wrong order
richard_1498031 Jan 19, 2016 5:50 AM (in response to richard_1498031)After some rethinking PSoC device reply to the request from Master.
Code execution is too slow to evaluate one byte at a time.
Had to save complete request packet to ComBuf and enter SW_ISR after last byte was detected.
Unfortunately this lead to a delay of ~100µS before sending reply which forced me to increase Master timeout waiting for reply.
Need to decrease that delay if we want to use PSoC in production. Still very early stages of testing...
This topic can be closed. I've attached the project as it is now in case its useful for someone.
/Richard