Raspberry pi serial port
Pages: 1 2
Terry Swanborough (455) 53 posts |
Hi If I use the simple code below on a beagle board I get serial output characters OK. When using the same code on the raspberry pi I get nothing out of pin 8 UART TX. I have tried different port numbers but with no success?. Any Ideas 10 HAL_UARTTransmitByte=70 60 SYS "OS_Hardware",1,65,,,,,,,0,HAL_UARTTransmitByte 80 Q=INKEY(10) 81 PRINT "A" 90 GOTO 60 100 END |
Chris Evans (457) 1614 posts |
I’m not sure that drivers have been written for the Raspberry Pi’s serial port. |
Rick Murray (539) 13840 posts |
Please, people, don’t make this mistake. Pay attention now: Serial running inside a microcontroller board is 0v (low) and +v (high) where high can be 1.8V, 3.3V, 5V etc as depending on the MCU. You will likely encounter this if your MCU’s I/O comes to a header with IIC, GPIO, Serial, etc etc on it. TTL serial may be encountered. This is the same as above, but the high is more restricted (usually 4.7V-5.1V) so that it may interface with TTL logic. You may encounter this with certain typewriters, label printers and such that had peripherals designed to work specifically with that hardware. Otherwise, it isn’t so different to BBC Micro or ACIA serial in that it needs to be fed to a line driver (or MAX232) to make it work with “the real world”. Here, we come to the RS-xxx protocols. These are the real world serial. RS-423 is real world serial for the microcomputer generation. Logical low is represented by -5V and high by +5V. That’s a 10V swing. Many line driver chips could manage this from a 5V input so this was typically how it went. As a note on compatibility, RS-423 specifies an upper signalling level of +/-6V so will work with RS-232 equipment of similar characteristics, but would fail with some of the fruitier RS-232 setups. A mistake made by a fair few companies in the home micro days that said their serial ports were RS-232 but provided hardware that coped only with RS-423 level signalling. RS-232 is worse. It is an older protocol, for connecting disparate terminals and such and some freaky ’60s era hardware. Typically RS-232 is between +/-5V and +/-15V (a swing of 30V); however the standard specifies that the smallest valid signal is +/-3V while the biggest valid signal is +/-25V (a swing of 50V). I’m sure you can see why +/- 15V into a 3.3V signal is… a no-go. You don’t want level shifters either for RS-432/232; you need a line driver (converts to/from the +/- swing). |
Terry Swanborough (455) 53 posts |
Hi Voltage is not a problem at the moment I am just looking at the output just out of interest the output on the raspberry pi swings 0 to 3.3v I have a beagle board running into a max232 using resistor dividers on the receive Anyway it might mean I have to directly access the serial port but normally the serial |
Chris Evans (457) 1614 posts |
Actually thinking about it, as Adrian development and early demonstrations (before USB was implemented) were done using a keyboard connected via a PCs Serial Port, there must have been some support very early on! n.b. The BeagleBoard and PandaBoard use 1.8v levels on their GPIO! |
Nat Fowler (1676) 6 posts |
Terry, |
Terry Swanborough (455) 53 posts |
I have been working mainly with the beagle board at the moment I will download the |
Rick Murray (539) 13840 posts |
Can’t [Beagle]; needs fiddling [RPi]. The MIDI specification says the serial link runs at 31.25kbps. The Beagle offers 28.8kbps and 38.4kbps (as it is divided down from a master timebase). So, you’ll either need very tolerant MIDI hardware that works outside of the defined MIDI spec, or looking to talk to a PIC or similar via GPIO that then generates the 31.25kbps data stream. I had a brief look at the OMAP3 TRM. It looks as if McBSP #5 can do MIDI, though I don’t know if its pins are accessible anywhere or otherwise used for alternative purposes. p3064 – p3223 describes it in brain-aching detail. Things appear to be better on a RaspberryPi as you appear to be able to specify a custom timebase; so you slow the main UART clock down and then open serial comms at 38400bps (which is actually running at the slower MIDI speed by now). Details here: http://www.siliconstuff.com/2012/08/serial-port-midi-on-raspberry-pi.html It is for Linux, but a person with know-how might be able to offer some code to do the same under RISC OS. It is a better solution than a microcontroller, or (god help you) trying to bit-bang MIDI out of two GPIO pins! |
Nat Fowler (1676) 6 posts |
It’s rPi I’m talking, sorry I didn’t clarify since the forum topic was rPi.. Yeah I’ve read this slowing (via config file) of the baud-rate but of course on Linux, and don’t know what is possible in RISC. I’ll start a new forum topic I guess, I corresponded with Tank and he said something about a pain-in-the-@ bit-bang (even though I dont know that term) as well. |
Terry Swanborough (455) 53 posts |
Just A quick update I now have bytes transmitting out of the serial port It seems I cannot change the serial BAUD rate? HAL_UARTRate=73 and SYS"OS_SerialOp",6,0 None of the above seem to work Just out of interest the SYS"OS_Hardware type call works on a beagle board The raspberry seems to default to a fast baud rate I have not worked out the speed |
Colin (478) 2433 posts |
Unless something’s changed SYS only uses registers 0-7 in BASIC. I use an assembler routine in BASIC to call OS_Hardware as you need access to registers 8 and 9. |
Terry Swanborough (455) 53 posts |
I cant see that being the problem as the SYS commands |
Steve Drain (222) 1620 posts |
SYS has passed registers R0 to R9 for a very long time, probably since RO3. The information in the PRM and Manual has been outdated for as long. My BASIC StrongHelp manual has the correct information. |
Colin (478) 2433 posts |
Hmmm something has changed then. Anyway I looked at mixed/RiscOS/Sources/HAL/BCM2835/s/UART in cvs and it seems that HAL_UARTRate doesn’t do anything. |
Stephen Unwin (1516) 154 posts |
Just tried using the program from the first post and monitoring pin 8 with an oscilloscope I get one transmission speed. Then, from the link Rick provided above, I add the following three lines to CONFIG/TXT:- “# For MIDI Ignore the first quotes, I couldn’t get just a hash! Reboot and run the same program. There is a definite reduction in bit rate and it looks of the right order, but I haven’t conducted an accurate measurement yet. Will have to dig out the DB50XG card! :) Using Raspberry Pi with todays new release and nothing else changed yet. |
Rick Murray (539) 13840 posts |
|
Terry Swanborough (455) 53 posts |
I have written a little assembly / BASIC program to allow access to the Raspberry PI Just out of interest when setting the baud rate to 115200 the calculation I have not got access set up to the sources to RISCOS so cannot add the changes |
neil.r (1738) 66 posts |
Just for the record, I tried the Pi_uart program this afternoon, writing to a Textstar LCD display 1 at 9600 with Tx and Rx connected to GPIO pins 14 and 15. Worked first time without any problems at all. I’ll have a go at reading from it as well at some point. 1 http://www.coolcomponents.co.uk/catalog/textstar-serial-display-p-428.html |
howard (1751) 2 posts |
I downloaded Terry’s program and it works ok but there’s seems to be an awful lot of assembly code in there. I know it’s necessary to set up speed and format once but isn’t there an easier / quicker way to just send output data to the serial port ? I see this command: Thanks for any help. Howard |
Terry Swanborough (455) 53 posts |
Hi I’m afraid the assembly language is needed to allow SYS “OS_Hardware”,1,65,,,,,,,0,HAL_UARTTransmitByte The above sys command sends bytes to the serial port in this |
Tank (53) 375 posts |
old thread resurrection !! Running Terry’s program does work with the hardware I have connected, but does drop characters sometimes. If anyone wants to see the source to find my mistake just look here P.S the module is NOT registered yet, so I am using the same SWI numbers as my PCISerial module whilst testing. |
Ronald May (387) 407 posts |
Your figure for UARTCLK sounds more like what is used for init_emmc-clock. |
Tank (53) 375 posts |
Ronald, sum=UARTCLK/(16*baud%) and this gives you I%=4 F%=57 By the way, I can now get the first 16 characters of data but then it drops a bunch before getting more…… |
Tank (53) 375 posts |
Well, one moment of clarity and BOOM…. I now get all my data as expected !! I now have a Current Cost Envi CC128 connected to the Pi and an app that presents the data. here is the source and a !SerialDev so if anyone could test it and pass any problems back to me. Not yet working are DRIVER_CONTROLLINES, DRIVER_MODEMCONTROL, DRIVER_WORDFORMAT, DRIVER_FLOWCONTROL. The format is set at 8 bit no parity. |
Tank (53) 375 posts |
When I have it fully working, should this be a module that I register myself, or should it be changed and added to the ROM build as the standard serial port ? |
Pages: 1 2