Left for archival purposes.

User avatar
By kartman
#6230 Methinks a handy feature would be RS485 support for the uart. This would most likely be an option that would nominate a gpio to act as the rx/tx select for the RS485 transceiver (like a max485 et al). Usually a logic '1' is tx.
Depending on the actual part implementation it could be simple or a little trickier. When there is data in the queue to send, the gpio bit is set high, then the data sent. When there is no more data to send and the uart has actually clocked out all the bits, then the gpio is set low. Hopefully the uart has a tx complete bit/interrupt rather than just a tx buffer empty bit/interrupt - otherwise the timer needs to be used to predict the end of the last byte of transmission based on the baud rate.
User avatar
By kartman
#8130 After fiddling for a day trying to get the uart to perform rs485 bus control, I conceded and used an os timer to time the transmit enable. This works well but has a granularity if 1ms, so you don't get tight control needed for high baud rates. Thus if your slave responds too fast, you'll have problems.
User avatar
By gwizz
#8155 Hey, it sounds like you've done something that could be really useful for a bunch of folks, well done :)

What sort of speeds can you run reliably with a 1ms resolution in terms of baud rate?

Can you share your schematic and/or code perhaps?

Keep on hacking :D
User avatar
By kartman
#8798 Hardware wise it is just a max3485 or similar chip. As for the timing, that becomes system dependant - how fast will an addressed device respond. At 9600 baud, 1ms is about one character time which is ok for many systems but at 115200, the 1ms granularity is 15 character times which is probably not ok.
You would want to chose a gpio that doesnt mind being pulled down during reset - reason being you add a pulldown resistor to keep the max3485 from enabling its transmitter during reset.
The code basically sets the gpio pin just before you transmit then load up a timer alarm based on the number of characters you want to send then the alarm resets the gpio. I did it in C but it would work equally in lua.