Hi,
Is is possible for the pi to do "software serial", i know it can do hardware serial via the dedicated Uart but can it also do software serial in the same way that a microprocessor such as a PIC or AVR can do both hardware and software serial, the software serial being able to use any general purpose I/O pins. For example on the PIC, serin and serout are the software serial commands and hserin/hserout are the hardware serial commands that make use of the on-board uart/usart.
If it is possible are there any routines to achieve this.
Cheers.
Re: can the pi do "software serial"?
with raspbian or another "standard" linux? no.
The problem is that linux is not a real-time operating system. What that means is that you get no guarantees about timing. So, if your program was preempted during serial communication it may miss incoming bits or corrupt outgoing bytes.
it is possible in theory if you program it without an operating system or using a real-time OS, but really its not worth using a strange OS or no OS just to get soft serial, which would hurt performance anyway.
The problem is that linux is not a real-time operating system. What that means is that you get no guarantees about timing. So, if your program was preempted during serial communication it may miss incoming bits or corrupt outgoing bytes.
it is possible in theory if you program it without an operating system or using a real-time OS, but really its not worth using a strange OS or no OS just to get soft serial, which would hurt performance anyway.
Re: can the pi do "software serial"?
As cnt says, no, not directly, the timing will be so bad it will be nigh on impossible to get anything to receive the signal.
However, there is more than one way to skin a cat.
It is possible with a mix of PWM and DMA to create your own UART signal with any number of start, stop, parity and data bits.
However, there is more than one way to skin a cat.
It is possible with a mix of PWM and DMA to create your own UART signal with any number of start, stop, parity and data bits.
>)))'><'(((<
Re: can the pi do "software serial"?
I actually did this.
Yeah, it's pretty rough, but I can transmit at 9600baud 8N1 with about ~10% error rate.
Receiving is the tricky part. At 300baud 8N1 I have ~20% error rate sometimes, <5% other times.
Want the code?
Yeah, it's pretty rough, but I can transmit at 9600baud 8N1 with about ~10% error rate.
Receiving is the tricky part. At 300baud 8N1 I have ~20% error rate sometimes, <5% other times.
Want the code?
Re: can the pi do "software serial"?
I'm interested in the code. Can you make it available ?vallidor wrote:I actually did this.
Yeah, it's pretty rough, but I can transmit at 9600baud 8N1 with about ~10% error rate.
Receiving is the tricky part. At 300baud 8N1 I have ~20% error rate sometimes, <5% other times.
Want the code?
Re: can the pi do "software serial"?
I've added software serial read/write code to pigpio.
The code was written more out of interest than necessity so I make no claims for reliability. When I was testing I was transmitting 3 serial streams simultaneously at different baud rates. I did notice that it was more reliable if one end of the serial link was hardware based.
The code as written only supports 8N1. It should be relatively easy to change to a different protocol.
http://abyz.co.uk/rpi/pigpio/cif.html#gpioWaveAddSerial to send from Pi
http://abyz.co.uk/rpi/pigpio/cif.html#g ... lReadStart to receive to Pi
edited to add: I may have given an incorrect feeling about reliability. Between my laptop and Pi at 115200 I was getting error free transmission of a 220KB binary file.
The code was written more out of interest than necessity so I make no claims for reliability. When I was testing I was transmitting 3 serial streams simultaneously at different baud rates. I did notice that it was more reliable if one end of the serial link was hardware based.
The code as written only supports 8N1. It should be relatively easy to change to a different protocol.
http://abyz.co.uk/rpi/pigpio/cif.html#gpioWaveAddSerial to send from Pi
http://abyz.co.uk/rpi/pigpio/cif.html#g ... lReadStart to receive to Pi
edited to add: I may have given an incorrect feeling about reliability. Between my laptop and Pi at 115200 I was getting error free transmission of a 220KB binary file.
Re: can the pi do "software serial"?
Simple solution is an I2C UART such as is used in the https://www.sparkfun.com/products/9981
Re: can the pi do "software serial"?
just use a USB/serial with FTDI chipset inside.
And don't mess with software serial.
And don't mess with software serial.
- Gert van Loo
- Posts: 2487
- Joined: Tue Aug 02, 2011 7:27 am
Re: can the pi do "software serial"?
Why do you want software serial? Do you need a second UART port or do you need more then two ports?
Re: can the pi do "software serial"?
Good job Joan!joan wrote:I've added software serial read/write code to pigpio.
...
edited to add: I may have given an incorrect feeling about reliability. Between my laptop and Pi at 115200 I was getting error free transmission of a 220KB binary file.
Re: can the pi do "software serial"?
One chap was using pigpio to generate DMX512 which is a pretty tough test. He had to add disable_pvt=1 to /boot/config,txt though and format a byte at a time to allow for the two stop bits.PiGraham wrote:Good job Joan!joan wrote:I've added software serial read/write code to pigpio.
...
edited to add: I may have given an incorrect feeling about reliability. Between my laptop and Pi at 115200 I was getting error free transmission of a 220KB binary file.