Skip to content
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 write behavior #9

Open
mhanuel26 opened this issue May 16, 2018 · 9 comments
Open

uart write behavior #9

mhanuel26 opened this issue May 16, 2018 · 9 comments

Comments

@mhanuel26
Copy link

Hi,

I want to know if it's possible to know when the uart has transmitted the data out of the interface.

My experience is that uart write method buffers the data, but I need to know the exact moment that there are no more bytes to send so I can toggle a GPIO. One way is to make write method blocking, which I understand is not possible.

I was trying to see if the native API offer additional control over this so I can write my low level app in C++ but it seems there is no additional uart core support different than AT API.

Will appreciate your comments,

@Fleker
Copy link

Fleker commented May 22, 2018

I don't believe there is any direct knowledge of the UART buffer, although as far as I know it's fairly expedient. What level of latency are you expecting?

@mhanuel26
Copy link
Author

Hello @Fleker

Thanks for your response,

I am trying to work with RS-485 using two wires, I have to disable the driver as soon as the last bit is transferred, this was not working when I call UART.write followed by the GPIO toggle instruction.

Would you suggest me a workaround?

@Fleker
Copy link

Fleker commented May 22, 2018

Do you have to disable it at the exact time of the last bit? Can you get away with a 10ms timeout?

One workaround could be to add a UART line back to your device on the Rx pin so that you can see exactly when the data is sent out of the bus.

@mhanuel26
Copy link
Author

Well, the closer the better,. The problem is that 10ms might be too much for high baud rate. Actually a normal baud rate of 19200 means several bits in a 10ms, so at the end it will depend on how fast the other peer can react and send data. If I do not disable the driver before the other peer start sending the response, the channel will get corrupted and data loss.

I think the workaround can be really messy, because I have to somehow code an "UART idle detector", it might involve timers, etc ...

@Fleker
Copy link

Fleker commented May 22, 2018

Can the receiving peripheral send an ACK byte back to your device when it receives the last part of the response?

@mhanuel26
Copy link
Author

That would be part of the communication protocol.
The problem is rather at the physical layer, for RS-485 when having only two wires, the channel is half duplex, is suppose there is only one device transmitting at a given time, for the modbus case that device is called Master. It's the physical medium which impose the need to disable the driver since both driver and receiver are sharing the same two wires.
You simple cannot receive correctly if the driver is enable, which is really simple to do on an MCU or when you can control the transmitting timing, i.e. to know the exact time there are no more bytes to transmit.
I think the AT should be able to provide some way to allow this, as this is the way RS-485 works in two wires mode.

@mhanuel26
Copy link
Author

Hi @Fleker ,

Would it be possible to have an upcoming release of AT that makes a UART.write blocking?
Or what I am trying to do might just be not possible with AT and ban be considered a dead road then.

Please let me know your thoughts,

@Fleker
Copy link

Fleker commented May 24, 2018

You can file a feature request for the framework using the issue tracker.

Is it possible to use four wire RS-485?

I'm going to ask some folks and get their insight.

@mhanuel26
Copy link
Author

mhanuel26 commented May 24, 2018

Four wires would be good since it's like full duplex, the problem is that most industrial RS-485, specially modbus devices are wired in the field using two wire scheme. Basically if you have a 4 wire device and you want to connect to a 2 wire network you just join A-Y and B-Z terminals.
By the way, here is the hardware I used for testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants