katesfb
Posts: 20
Joined: Tue Aug 14, 2012 4:17 am

can the pi do "software serial"?

Fri Mar 01, 2013 10:51 am

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.

cnt
Posts: 60
Joined: Wed Sep 26, 2012 4:42 am

Re: can the pi do "software serial"?

Sat Mar 02, 2013 6:29 pm

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.

User avatar
aTao
Posts: 1095
Joined: Wed Dec 12, 2012 10:41 am
Location: Howlin Eigg

Re: can the pi do "software serial"?

Sat Mar 02, 2013 6:43 pm

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.
>)))'><'(((<

vallidor
Posts: 8
Joined: Mon Apr 02, 2012 3:43 am

Re: can the pi do "software serial"?

Fri Jun 28, 2013 5:56 pm

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?

michaell
Posts: 16
Joined: Mon Sep 17, 2012 8:08 am

Re: can the pi do "software serial"?

Thu Oct 31, 2013 6:38 am

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?
I'm interested in the code. Can you make it available ?

User avatar
joan
Posts: 15970
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: can the pi do "software serial"?

Thu Oct 31, 2013 8:39 am

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.

pelowitz
Posts: 1
Joined: Fri Jul 11, 2014 2:11 am

Re: can the pi do "software serial"?

Fri Jul 11, 2014 2:14 am

Simple solution is an I2C UART such as is used in the https://www.sparkfun.com/products/9981

stevech
Posts: 144
Joined: Sun Jul 15, 2012 11:53 pm

Re: can the pi do "software serial"?

Fri Jul 11, 2014 5:52 am

just use a USB/serial with FTDI chipset inside.
And don't mess with software serial.

User avatar
Gert van Loo
Posts: 2487
Joined: Tue Aug 02, 2011 7:27 am

Re: can the pi do "software serial"?

Fri Jul 11, 2014 6:35 am

Why do you want software serial? Do you need a second UART port or do you need more then two ports?

PiGraham
Posts: 5063
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: can the pi do "software serial"?

Fri Jul 11, 2014 7:04 am

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.
Good job Joan!

User avatar
joan
Posts: 15970
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: can the pi do "software serial"?

Fri Jul 11, 2014 7:22 am

PiGraham wrote:
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.
Good job Joan!
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.

Return to “General discussion”