Page 1 of 1
RS-485-like 9-bit mode for UART?
Posted: Sun Sep 27, 2015 8:18 pm
by dbc
After a quick look at the UART documentation, I'm trying to figure out how rs-485-like communication is supported. That is, where data is 9 bits, and the most significant bit is the address marker flag. A UART listening in 9-bit mode should test an address character to see if it is being addressed. It should only accept following data bytes if the address matches, otherwise data is ignored. Does the MicroPython UART API support that somehow?
Re: RS-485-like 9-bit mode for UART?
Posted: Mon Sep 28, 2015 5:20 am
by dhylands
The uart does support 9 bit mode, but I don't think it does any filtering. It presents each 9-bits in 2 bytes. So the python code would need to do the filtering. I imagine that it would be possible to add support to the UART driver to return an 8-bit stream and do address matching.
See:
http://docs.micropython.org/en/latest/l ... #uart.init and
http://docs.micropython.org/en/latest/l ... #uart.read
Re: RS-485-like 9-bit mode for UART?
Posted: Mon Sep 28, 2015 6:31 pm
by dbc
OK. I'll take a look at the data sheet. Some ST parts only match on 4 of the 8 address bits -- somebody at ST needs to be slapped over that, but I digress...
In any case, the point of 9 bit mode (usually) is not to send 9 bit data, but to send 8 bit data to a specific address on a multi-drop bus, without all the other nodes having to take an interrupt just to throw away the received character. The hardware should suppress all the uninteresting traffic. An API that reflected that usage model for 9-Bit mode would be a good addition, I think.
Re: RS-485-like 9-bit mode for UART?
Posted: Mon Sep 28, 2015 10:35 pm
by dhylands
I took a look at the datasheet. The 405 appears to only support a 4-bit address.
However, I think that you can probably make it work by first setting the UART up as if it were in 8-bit mode and then directly modifying the registers to put it into 9-bit mode and set the address and wake modes (using the stm module). I'll have to give this a go and see if I can make it work (I'm on the road for a couple days, so I'm not sure I'll have time or not).
Re: RS-485-like 9-bit mode for UART?
Posted: Tue Sep 29, 2015 1:16 am
by dbc
It's been a while since I looked at that part of an ST data sheet, but IIRC, there is a way to hook an interrupt to the address byte so that you can do an 8 bit compare in software in time to set a bit in a control register. It's pretty silly that ST makes you do that, but that's the way it is.
When I get a chance I am going to look over the current code, I have an idea for a simple upward compatible API extension that would enable addressed communication and driver output-enable control. It will require that I set aside a little time to read the data sheet and look at the current API, and also think through requirements. To totally solve the problem for some (not all) protocols, it also needs to allow for a GPIO to be used as a transmit-enable on a driver chip. One of my friends uses addressed 9-bit mode extensively (with other processors), I'll quiz him, too.
You will likely get to your experiment first, I have a couple other commitments in the queue.
Re: RS-485-like 9-bit mode for UART?
Posted: Wed Sep 05, 2018 9:50 pm
by craigzyc
Did anything ever come of this?
An interupt and software address compare would be far more efficient than how I currently see to do this