David Ryan
Posts: 9
Joined: Wed May 16, 2018 3:53 pm

[RESOLVED] Verifying transmission complete on Tx/Rx

Thu Jul 19, 2018 2:21 pm

Hello all,

I have a project that uses the Tx/Rx pins to transmit through an RS-485 chip. I'm using GPIO18 as a flow control. As it stands when I go to transmit the following sequence occurs.

1 - Calculate transmission time(ms) based on baudrate and buffer size x = f(y)
2 - Set to GPIO 18 to transmit
3 - Send the buffer data to be written
4 - Set GPIO 18 to receive after x time has passed.

This process works, but I would feel better about the resilience of the application if I could somehow check Tx/Rx to confirm that the buffer has been written rather than hoping my timeout processes in the correct amount of time.

Application is written in node using GPIO and serialport libraries.

Any advice would be greatly appreciated. As always, thanks guys.

[UPDATE]

For the project I was working on I ended up moving to an RS485 with flow control hardware, but I was able to find a solution to my problem in a Node library SerialPort

They have a function drain that polls the OS to see if the serial port has transmitted all of it's data

It works...however there is a ≈20ms delay in the response coming from the OS on a Raspberry pi 3 running Raspbian Stretch with a few other tasks running. That was too much for my needs, but for some (most probably) that is sufficient.

Note: With a 20ms delay you do run the risk of collision on a line. I was running a Modbus scheme with the Pi device as the master. I was getting a response from the slave device about 5ms after I sent out the request, but was continuing to drive the line high waiting for the OS to tell me it had written everything on the port.

Thanks everyone for the help.
Last edited by David Ryan on Tue Sep 11, 2018 1:05 pm, edited 3 times in total.

KnarfB
Posts: 194
Joined: Wed Dec 14, 2016 10:47 am
Location: Germany

Re: Verifying transmission complete on Tx/Rx

Thu Jul 19, 2018 4:44 pm

Hi David,

you cannot be sure for a user mode application because of OS activities which may introduce unwanted delays between your function calls, e.g. under heavy load conditions. If you switch the GPIO back too late, the UART may miss an early reply on the RS485 bus.

The overall risk depends on the baud rate, the protocol details (timing, number of bytes to send/recieve) etc..

The following might help:
  • increase the process priority to real-time (use sudo chrt -r 99 ... form the command line to start your prog) reducing the risk of being interrupted by the OS
  • use additional hardware supporting RS485 hardware flow control. I used a STM32 NUCLEO-F042K6 board for a similar purpose with a high baud rate of 2MBaud
hth KnarfB

David Ryan
Posts: 9
Joined: Wed May 16, 2018 3:53 pm

Re: Verifying transmission complete on Tx/Rx

Fri Jul 20, 2018 3:52 pm

Thanks KnarfB!

That was the answer I was afraid of. I haven't tried (really I wasn't aware of) increasing the process priority. I'll give that a shot.

Thanks for the device suggestion. If process priority doesn't check out I'll give that a shot.

mosespi
Posts: 508
Joined: Mon May 12, 2014 3:35 pm
Location: 34,-118
Contact: Website

Re: Verifying transmission complete on Tx/Rx

Fri Jul 20, 2018 6:47 pm

If you control both sides, add some sort of checksum and verify the data received is intact before acting upon it.

Regards,
-Moses
Power problems? MoPower UPS for the Pi
http://www.allspectrum.com/mopower/

David Ryan
Posts: 9
Joined: Wed May 16, 2018 3:53 pm

Re: Verifying transmission complete on Tx/Rx

Thu Sep 06, 2018 8:31 pm

[UPDATE]

For the project I was working on I ended up moving to an RS485 with flow control hardware, but I was able to find a solution to my problem in a Node library SerialPort

They have a function drain that polls the OS to see if the serial port has transmitted all of it's data

It works...however there is a ≈20ms delay in the response coming from the OS on a Raspberry pi 3 running Raspbian Stretch with a few other tasks running. That was too much for my needs, but for some (most probably) that is sufficient.

Thanks everyone for the help.

Return to “Advanced users”

Who is online

Users browsing this forum: No registered users and 9 guests