-
-
Notifications
You must be signed in to change notification settings - Fork 348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UART TX_FIFO_EMPTY interrupt on start of transmission #1645
Comments
@egr8086 Thanks for this, I'm working on some serial driver changes ATM so will look at this also. I have a generic modbus RTU driver for Sming here: https://github.com/mikee47/Sming/tree/feature/modbus/Sming/Services/Modbus It uses a serial driver interrupt callback (see It would be great to have a generic driver for Sming, so perhaps we could work on this together? Example:
|
Hello. I observe unexpected behavior when trying to use BTW I just landed on this issue (hinted by github). I have exactly the same problem as @egr8086. The proper set/reset of the RE pin of my RS485 interface could happen only with interrupts/callbacks. Manually setting it after Serial.write() breaks the timing. I'm reading the non-os api reference and here is what makes me curious:
|
Oh, hey guys, you may find the code in this class useful in achieving this. I made a driver for RS485 that controls the read/write enable pins in a very specific way for another half-duplex protocol. It could be useful for reference to implementing MODBUS. https://github.com/kpishere/Net485/blob/master/src/Net485Physical_HardwareSerial.hpp In the protocol I'm using this for, there was specific requirements for pre-drive and post-drive timings. |
@kpishere Unfortunately I don't understand how your program verifies completion of TX (TX transmit empty). I'm attaching some scope shots of the problem. I tried both with
(with setUartCallback)
|
@kmihaylov Be aware that the FIFO empty interrupt occurs when the last character has been moved from the FIFO into the hardware sending register. Specifically, that means the last character will be lost if the RS485 direction is changed. This is why my implementation adds a NUL character at the end. Behaviour is confirmed by your 'scope traces. Also bear in mind that |
@kmihaylov Oh, it is simpler than you might be looking for. Essentially, I don't verify completion, I simply calculate the time needed to send the known number of bytes at a fixed bit rate. The macro here does the calc. This wouldn't work if there were any sort of flow control etc. but there isn't in this case. Packets in my usage case don't exceed 252 bytes either. case DriveStateE::Sending: |
@kpishere ah I see, good to know! Thanks! This solution
will trigger it two times and the first time it will immediately close the TX line. What I did is to get rid of the first NUL character and to add a NUL character at the end of the data array that has to be send. This way it works. Meanwhile I'm struggling with the interrupts. On ModbusMaster I managed to do it, but on modbusino, for some reason, it didn't fire and leaves the TX line pulled by the slave. I'll clean the code and investigate it a little bit. |
I working on modbus RTU implementation using Sming and HardwsreSerial. Before uart transmission i need to pull up TX_ENABLE pin (GPIO 0 in my case) and pull it down after transmission complete. But txCompleteDelegate() calls on begin of transmission.
Here is initialization:
txCompleteDelegate:
setTxWait(true) doesn't help.
The text was updated successfully, but these errors were encountered: