Serial port on Pi
Chris Hall (132) 3554 posts |
I have more than one piece of hardware connected: one is a GPS module which continually spams the Pi’s RXDATA pin with serial data at 9600baud and one is a PaPiRus display which uses the RXDATA and TXDATA pins as GPIO outputs to control the border pixels and to discharge the diode pumps. [initial condition is serial port receiving data at 9600baud with no problem] Step 1 is to disable the GPS module and set BCM 14 (TXD) and BCM15 (RXD) to GPIO outputs. Step 2 is to update the PaPiRus display. Step 3 resets BCM 14 and 15 to their UART function and reenables the GPS module. Sometimes though the serial data don’t get received correctly after steps 1 to 3 – I suspect that my step 3 (shown below) is not quite right. Any ideas please?
|
Ronald May (387) 407 posts |
Any ideas please? From someone on the outside looking in, the obvious thing would be to try setting up the serial before gps is sending data. I’m guessing the example way is working for you in your normal gps startup though. |
Chris Hall (132) 3554 posts |
The serial port is all set up and working at start up, the caveat here is that the GPS module starts spamming the RXDATA pin with 9600 baud serial data about 1s after power is applied and it is not until much later (about 11s after power on) that my application checks SerialDeviceSupport is present and does lines 6960 to 7000 as part of its initialisation. Nearly always that works but sometimes it doesn’t (I receive zero and top-bit-set characters over the serial port) and after noticing that I do lines 6950 to 7000 (i.e. change serial port speed down and back again) which flushes the serial port and it then works. Hence it is not possible to set up the serial port before the gps sends data. In the case of updating the PaPiRus, once I have finished updating it, I restore the TXDATA and RXDATA pins to UART function. I agree that I should put lines 6850 and 6860 after line 7000, so at least the serial port tinkering is all done before telling the GPS to start again. What I am really asking is would that be sufficient? What is the correct way to resume? |
Ronald May (387) 407 posts |
Hence it is not possible to set up the serial port before the gps sends data. I have a copy of the original Pi direct serial driver by Terry, if you wish to try bypassing the system serial port software to see if there is a bug with the SerialOp method. Being direct, it doesn’t need any support modules. I dont know what it is referring to but using it before receiving doesn’t do any harm, maybe of no help also.
|
Chris Hall (132) 3554 posts |
Many thanks. That does have an interesting effect. After the sequence described above (steps 1 to 3) the serial port falls silent, nothing received (despite the GPS module sending data). Trying my original method to stir it into life is ineffective. *RMReinit Serial just gives an error ‘serial stream(s) in use’. Adding SYS “OS_SerialOp”,2,20 at line 7001 causes a complete hang of the machine. ALT-Break does nothing but ALT-Break followed by CTRL-Break says ‘press the return key to stop the program or Press SPACE or click mouse to continue’ but then it is stiffed completely. Puzzled. I think I can focus this down a bit. With the PaPiRus display removed but with the GPS module continually spamming the RXDATA pin with 9600 buad the following will duplicate the problem: Set RXDATA and TXDATA to GPIO outputs. |
Ronald May (387) 407 posts |
OS_SerialOp,2,20 Just reading Stronghelp and OS_SerialOP 2 sets the ACIA to transmit a break. (sounds hardware-ish) |
Rick Murray (539) 13840 posts |
Indeed. Why are you sending a break? What I don’t notice in your list of instructions is the part where you flush the buffers… |
Rick Murray (539) 13840 posts |
Also – the important thing with serial comms is not to make any assumptions about prior state. Flush buffers, set data format, set flow control (probably “none”), etc etc. Ronald – some GPS devices accept data to configure parameters such as reporting frequency and/or uploading assistance data to help get a quicker fix on location. |
Chris Hall (132) 3554 posts |
the important thing with serial comms is not to make any assumptions about prior state I have not. Why are you sending a break? No idea, but I’ll try any suggestion. I think *FX 21,1 and a change of serial speed both flush the buffers? Anyway my work around is not to update the PaPiRus display on start up so the serial port works from start up as before. That is only update it when just about to turn the computer off. |