Serial port on Pi
Chris Hall (132) 3554 posts |
Using a self-built low vector ROM from the 12-Feb tarball, with GPIO added to the ROM, I am encountering occasional but persistent serial errors. The programme (a development of SatNav) is controlling a Witty Pi 2 via the IIC bus (asserting GPIO 4 to power off the computer and using the RTC alarm to power it back on at a scheduled time) as well as reading and writing the RTC it provides, again via the IIC bus, using the OLED module to write to an OLED display, again using the IIC bus, whilst reading from the serial port from a GPS hat. Sometimes it starts up but only receives zero characters or top bit set characters from the serial input. In this case I just force an immediate shutdown and next time it powers on it all works again (nearly always). The log shows that about one in six power ons results in a malfunctioning serial port and only a few times do they occur in two successive start ups.
Interpreting the log: entries that say ‘serial’ mean it found zero and top bit set characters coming in the serial input so just forced a shutdown. An entry that says ‘close’ means that the GPS fix was within 50m of where the last known position was. Basically if it detects movement it satys on to log the distance. Loss of fix for 15 mins or no movement for 15 min goes back to switching off and waking up. The ‘flag’ means it was turned on with alarm 1 flagged, ‘force’ means it was turned on by push button. Otherwise the log entries are gridX,gridY,odometer,starttime,endtime,comments. Horrible work around but it means that even with a start up after only one minute (the design idea is for a 30 min power off period) it cuts power consumption down from about 500mA (with HDMI) to 52mAh per hour. (Probably about 35mAh/h if not using HDMI.) Is there any way (short of power off/on) to bring the serial port back to life? |
Rick Murray (539) 13840 posts |
Are you absolutely sure it is starting up with the right baud rate and word format? Usually if the results are gibberish, that’s the cause.
From the days of modems (so a very distant memory), if the input was unexpected nonsense, then read until there’s nothing more (discard it), set the baud rate and word format again, and then briefly toggle flow control to kick the hardware. This might have been something to do with a bug in the 6551 or maybe just cargo cult programming. ;-) Something I have noticed is that my Pi (older ROM) spews debugging info to the serial port at boot, but if there’s nothing to catch that data, the serial port is then effectively dead and won’t work if connected to a PC and more data sent (ie DADebug). Maybe not related, but it seems…unusual. The expected behaviour would be the data evaporating (as there’s no flow control). Not the entire serial functionality evaporating! |
Chris Hall (132) 3554 posts |
Are you absolutely sure it is starting up with the right baud rate and word format? Usually if the results are gibberish, that’s the cause. Well, sort of Yes. I have read the baud rate stop bits etc and it says they are the values that I had written to them when the programme started. There’s no handshaking. Taking the computer (model a+/Witty Pi 2/GPS Hat) to an impromptu meeting of BARUG tonight is likely to be a useful exercise in debugging once I read the log to see what it did! It certainly turned itself on and off with no user intervention. |
Jeffrey Lee (213) 6048 posts |
When testing for this issue I found that sometimes the first hundred or so received characters were corrupt, after which it corrected itself. I didn’t try looking any deeper to see where the problem was (but it was almost certainly a receiver-side problem, since the transmitter was already up and running for a few seconds before I started the receive app on the Pi)
Changing the baud rate or data format will cause the UART to be stopped and started again. I think this will also flush the FIFOs. |
Chris Hall (132) 3554 posts |
I’ll try this. The corrupted characters were being received far less often than the normal traffic would be, taking ages to accumulate up to over a hundred so it didn’t seem to correct itself (at least not after an hour or so). I’ll try changing the baud rate (it thinks it is running at the correct rate so I’ll change it to something that is definitely wrong, then back to the right figure and see what happens). I can flush the buffer with *FX 21,1. At present I start up the serial port with:
and on a start up where the serial doesn’t work, asking again what baud rate it thinks it is using gives the expected answer (9600baud). |