R-Pi 4 serial port truncates messages

I can't be sure if this is a node-red or R-PI issue. It's a low runner so I can work around it but thought someone may want to investigate who knows how to get under the hood.

I've seen this issue on two separate R-PI 4 modules mounted on the R-PI IO boards. The flow below can be used to quickly find the issue. You need to add a wire to loop back the serial port on the IO board.
In my application, I used a o-scope to verify the message size on the wire was correct, this seems to be a receive side issue.

What you'll see is an expected msg length of 32 bytes. The flow will stop when a msg of less than 16 bytes is received.
'''
flows(1).json (2.1 KB)
'''

What happens if you increase the port timeout significantly?

For the future, please see this post for how to post flows - How to share code or flow json

[Edit] Also does it truncate or miss characters?

The message is truncated. Oddly, in my application I expect 23 bytes and it seems to always truncate to 16 bytes.

I've tried changing baud rate, timeout, response timeout, modem control signals, message pacing and nothing has an effect. I've also verified the signal quality which is very good.

[{"id":"62a0e5a5.fc59bc","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"a5e97b88.29fc1","type":"inject","z":"62a0e5a5.fc59bc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":270,"y":480,"wires":[["c96883ab.928c68"]]},{"id":"e5a01549.1808c","type":"function","z":"62a0e5a5.fc59bc","name":"","func":"\nif (msg.payload.length > 16)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":600,"wires":[["14a3a644.d5496a"]]},{"id":"360db49b.d92ca4","type":"debug","z":"62a0e5a5.fc59bc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":420,"wires":[]},{"id":"24f2195f.278fde","type":"debug","z":"62a0e5a5.fc59bc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":430,"y":660,"wires":[]},{"id":"c96883ab.928c68","type":"function","z":"62a0e5a5.fc59bc","name":"","func":"\nmsg.payload = [0.1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6]\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":480,"wires":[["360db49b.d92ca4","97e1f8f6.418b5"]]},{"id":"97e1f8f6.418b5","type":"serial out","z":"62a0e5a5.fc59bc","name":"","serial":"bc2ed729.523838","x":910,"y":480,"wires":[]},{"id":"c4505f2a.356db","type":"serial in","z":"62a0e5a5.fc59bc","name":"","serial":"bc2ed729.523838","x":270,"y":600,"wires":[["e5a01549.1808c","24f2195f.278fde"]]},{"id":"14a3a644.d5496a","type":"delay","z":"62a0e5a5.fc59bc","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":670,"y":540,"wires":[["97e1f8f6.418b5"]]},{"id":"bc2ed729.523838","type":"serial-port","serialport":"/dev/ttyAMA1","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"5","bin":"bin","out":"interbyte","addchar":"","responsetimeout":"0"}]

Thanks,
Dave

What's the IO board, do you have specs of it?
Where do you put the loopback wire on? Uart2 (AMA1) is on pins 27 & 28 of the Pi header.
Did you edit the /boot/config.txt to enable the uart2?

Sure, here's the link for the IO board:

Yes, for the test flow I use a jumper between pins 27/28 of J8 and yes I did enable the uart in the config file.
I running from the on-board memory not a USB stick.

Obviously in my application I'm not doing a loopback. I am polling a separate processor that's just running some embedded code and see the same issue.

Clutching at straws maybe, but could you stop node-red and start it again in a terminal and post the log from startup here please. Including some comms action.

Tested it here on a "normal" Pi4 with a jumper on pin 27 & 28, added dtoverlay=uart2 in /boot/config.txt.
And it works fine here with your flow (removed the delay node).
Array with 26 elements is send and every time there 55 bytes received. This because you send an array and set the receiver as binary buffer output.

To send binary data try this in your function node:

msg.payload = Buffer.from("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x20\x21\x22\x23\x24");
return msg;

30 bytes are send and 30 bytes are received.

Example:

[{"id":"44e345f9fecfeb6f","type":"inject","z":"581aefe8afaa4f7f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":480,"y":260,"wires":[["7a21b882602e5055"]]},{"id":"82f92f3c7094b58d","type":"function","z":"581aefe8afaa4f7f","name":"","func":"\nif (msg.payload.length > 16)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":650,"y":380,"wires":[[]]},{"id":"615714af560fb444","type":"debug","z":"581aefe8afaa4f7f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":840,"y":200,"wires":[]},{"id":"e74fb363437e23bd","type":"debug","z":"581aefe8afaa4f7f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":640,"y":440,"wires":[]},{"id":"7a21b882602e5055","type":"function","z":"581aefe8afaa4f7f","name":"","func":"msg.payload = Buffer.from(\"\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\x09\\x0A\\x0B\\x0C\\x0D\\x0E\\x0F\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x20\\x21\\x22\\x23\\x24\");\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":650,"y":260,"wires":[["615714af560fb444","53e8bbe77866d8bd"]]},{"id":"53e8bbe77866d8bd","type":"serial out","z":"581aefe8afaa4f7f","name":"","serial":"bc2ed729.523838","x":1120,"y":260,"wires":[]},{"id":"1ddd9268c097ba56","type":"serial in","z":"581aefe8afaa4f7f","name":"","serial":"bc2ed729.523838","x":480,"y":380,"wires":[["82f92f3c7094b58d","e74fb363437e23bd"]]},{"id":"bc2ed729.523838","type":"serial-port","serialport":"/dev/ttyAMA1","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"5","bin":"bin","out":"interbyte","addchar":"","responsetimeout":"0"}]

I'm running a test over the weekend so yes I will do your test on Monday.
The error is random and may take as much as 30 minutes or more to happen.

I'm sorry, what do you mean by " Including some comms action."

I meant up to the point the error occurs. I got the impression that it was a solid failure, but apparently not. In that case are you certain that the full message is sent for the message that fails?
Another question. Does the rest of the message appear as the next message, or possibly on the front of the next message?
You said you had tried various timeout settings, have you tried a very long timeout? One second for example?

Keep in mind that pin 27&28 is also used by i2c.
Because your Module 4 IO board has an real-time clock it's likely that the i2c bus is used and can interfere with the UART.

Is this the image you wanted?
Since I use a start byte, any left over bytes would be discarded. I'll see if i can modify the test to catch any left over bytes. I will also try a string instead of just bytes.
I did try a very long timeout to see if the erro was due to the timeout expiring.

It looks to me like the RTC is on SPI-0 which is not on this pin set.

This is interesting.
If I set the serial port to deliver ASCII stings but keep the Split after timeout I see the same issue with some truncated strings.
If I set the split to be on the \n char then it seem to work 100%.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.