Forums

Software UART driver

Started by Daniel Doron November 10, 2014
Hi all,

I have tried to look an answer for this on the web, but I mainly got "no can do" (timing issue).

Kernel: 2.6.3x
MCU: atmel at91 (9263)

I wish to get/write a driver to bitbang a couple of gpios to emulate a uart. the communication is with a remote PIC (PIC12F683) to which I have already wrote the software and checked with linux terminal. 
the communication does not have to be fast at all (1200 would be fine). only a few bytes are exchanged. 

can someone point me in the right direction? did someone already develop such a driver? is there an example/guide I can follow to do it? 

Daniel.
Hi all,

I have tried to look an answer for this on the web, but I mainly got "no can do" (timing issue).

Kernel: 2.6.3x
MCU: atmel at91 (9263)

I wish to get/write a driver to bitbang a couple of gpios to emulate a uart. the communication is with a remote PIC (PIC12F683) to which I have already wrote the software and checked with linux terminal. 
the communication does not have to be fast at all (1200 would be fine). only a few bytes are exchanged. 

can someone point me in the right direction? did someone already develop such a driver? is there an example/guide I can follow to do it? 

Daniel.
On Monday, November 10, 2014 4:00:58 PM UTC+2, rbehm wrote:
> On 10.11.2014 21:44, Daniel Doron wrote: > > Hi all, > > > > I have tried to look an answer for this on the web, but I mainly got "no can do" (timing issue). > > > > Kernel: 2.6.3x > > MCU: atmel at91 (9263) > > > > I wish to get/write a driver to bitbang a couple of gpios to emulate a uart. the communication is with a remote PIC (PIC12F683) to which I have already wrote the software and checked with linux terminal. > > the communication does not have to be fast at all (1200 would be fine). only a few bytes are exchanged. > > > > can someone point me in the right direction? did someone already develop such a driver? is there an example/guide I can follow to do it? > > > > Daniel. > > > You will probably fail with this, because you need hard real time > operation. > Even if it is not really fast, you need to sample at least 4 times/bit > time to find the start bit and its center and from there on sample the > bits at each center point. Anything else will be to sensitive on minor > variations from the sender. This timing must be met with at least half a > bit time. The sender is a bit easier bit you also have to meet the timing. > At 1200 bit/sec this means about 200�sec. Sounds long, but a lot of > things can come in the way even if running inside the kernel. It might > work if your kernel is doing not much more. > > -- > Reinhardt
got it. thanks. D.
On 11/9/2014 10:00 PM, rbehm wrote:
> On 10.11.2014 21:44, Daniel Doron wrote: >> Hi all, >> >> I have tried to look an answer for this on the web, but I mainly got >> "no can do" (timing issue). >> >> Kernel: 2.6.3x >> MCU: atmel at91 (9263) >> >> I wish to get/write a driver to bitbang a couple of gpios to emulate a >> uart. the communication is with a remote PIC (PIC12F683) to which I >> have already wrote the software and checked with linux terminal. >> the communication does not have to be fast at all (1200 would be >> fine). only a few bytes are exchanged. >> >> can someone point me in the right direction? did someone already >> develop such a driver? is there an example/guide I can follow to do it? >> >> Daniel. >> > You will probably fail with this, because you need hard real time > operation. > Even if it is not really fast, you need to sample at least 4 times/bit > time to find the start bit and its center and from there on sample the > bits at each center point. Anything else will be to sensitive on minor > variations from the sender. This timing must be met with at least half a > bit time. The sender is a bit easier bit you also have to meet the timing. > At 1200 bit/sec this means about 200�sec. Sounds long, but a lot of > things can come in the way even if running inside the kernel. It might > work if your kernel is doing not much more.
I disagree with the failure prediction. I did a bit banged MIDI interface with a PIC16F84 at more than a decade ago with great success. The real predictor of success or failure will be your requirements. It's true that hard real time response is needed however there are many ways to skin this cat. If there's no RTOS, your odds of success improve. If there are no other interrupts active, you will likely succeed. How many times you need to sample a bit cell will be determined by your operating environment, baud rate, reliability requirements, etc. JJS
John Speth <johnspeth@yahoo.com> writes:

> On 11/9/2014 10:00 PM, rbehm wrote: >> On 10.11.2014 21:44, Daniel Doron wrote: >>> Hi all, >>> >>> I have tried to look an answer for this on the web, but I mainly got >>> "no can do" (timing issue). >>> >>> Kernel: 2.6.3x >>> MCU: atmel at91 (9263) >>> >>> I wish to get/write a driver to bitbang a couple of gpios to emulate a >>> uart. the communication is with a remote PIC (PIC12F683) to which I >>> have already wrote the software and checked with linux terminal. >>> the communication does not have to be fast at all (1200 would be >>> fine). only a few bytes are exchanged. >>> >>> can someone point me in the right direction? did someone already >>> develop such a driver? is there an example/guide I can follow to do it? >>> >>> Daniel. >>> >> You will probably fail with this, because you need hard real time >> operation. >> Even if it is not really fast, you need to sample at least 4 times/bit >> time to find the start bit and its center and from there on sample the >> bits at each center point. Anything else will be to sensitive on minor >> variations from the sender. This timing must be met with at least half a >> bit time. The sender is a bit easier bit you also have to meet the timing. >> At 1200 bit/sec this means about 200&micro;sec. Sounds long, but a lot of >> things can come in the way even if running inside the kernel. It might >> work if your kernel is doing not much more. > > I disagree with the failure prediction. I did a bit banged MIDI > interface with a PIC16F84 at more than a decade ago with great > success. The real predictor of success or failure will be your > requirements. It's true that hard real time response is needed however > there are many ways to skin this cat. If there's no RTOS, your odds > of success improve. If there are no other interrupts active, you will > likely succeed. How many times you need to sample a bit cell will be > determined by your operating environment, baud rate, reliability > requirements, etc.
But did you do it *from linux* (that is what the OP seems to want to do AIUI). -- John Devereux
>Hi all, > >I have tried to look an answer for this on the web, but I mainly got "no
can do" (timing issue).
> >Kernel: 2.6.3x >MCU: atmel at91 (9263) > >I wish to get/write a driver to bitbang a couple of gpios to emulate a
uart. the communication is with a remote PIC (PIC12F683) to which I have already wrote the software and checked with linux terminal.
>the communication does not have to be fast at all (1200 would be fine).
only a few bytes are exchanged.
> >can someone point me in the right direction? did someone already develop
such a driver? is there an example/guide I can follow to do it?
> >Daniel. >
I don't see why you can't do this on an Atmel. See "Bit Banging" by Jack Ganssle (http://www.ganssle.com/articles/auart.htm ) AP-24 "Application Techniques for the MCS-48 Family" from Intel. Google it, and if you can't find it online get back to me. How about this for the AVR "AVR304: Half Duplex Interrupt Driven Software UART" (http://www.atmel.com/images/doc0941.pdf) Unless I misunderstand your question I am stunned you can't find the stuff on the web. Just entering bit bang in Google brings up tons of references. --------------------------------------- Posted through http://www.EmbeddedRelated.com
On Mon, 10 Nov 2014 05:44:38 -0800, Daniel Doron wrote:

> Hi all, > > I have tried to look an answer for this on the web, but I mainly got "no > can do" (timing issue). > > Kernel: 2.6.3x MCU: atmel at91 (9263)
I assume you mean _linux_ kernel. If so, and if you don't have real time extensions, then probably not. Amazingly enough, a few (around 99% of the market) embedded processors don't use Linux. So it's good to specify what OS (if any) you're using.
> I wish to get/write a driver to bitbang a couple of gpios to emulate a > uart. the communication is with a remote PIC (PIC12F683) to which I have > already wrote the software and checked with linux terminal. > the communication does not have to be fast at all (1200 would be fine). > only a few bytes are exchanged. > > can someone point me in the right direction? did someone already develop > such a driver? is there an example/guide I can follow to do it?
Without real-time extensions to your Linux kernal, or perhaps hijacking a timer interrupt in a way that it can be serviced independently of Linux, you're probably out of luck. Bit-banging serial is easy-peasy if you have good timer resources and an OS that doesn't get in the way, but Linux gets in the way. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
>>Kernel: 2.6.3x >>MCU: atmel at91 (9263) > >I don't see why you can't do this on an Atmel. >See "Bit Banging" by Jack Ganssle >(http://www.ganssle.com/articles/auart.htm ) > >AP-24 "Application Techniques for the MCS-48 Family" from Intel. Google
it,
>and if you can't find it online get back to me. > >How about this for the AVR "AVR304: Half Duplex Interrupt Driven Software >UART" >(http://www.atmel.com/images/doc0941.pdf) > >Unless I misunderstand your question I am stunned you can't find the
stuff
>on the web. Just entering bit bang in Google brings up tons of
references. I'm sorry- I missed the bit that you were using Linux. My bad. --------------------------------------- Posted through http://www.EmbeddedRelated.com
On 11/10/2014 10:17 AM, John Devereux wrote:
> John Speth <johnspeth@yahoo.com> writes: > >> On 11/9/2014 10:00 PM, rbehm wrote: >>> On 10.11.2014 21:44, Daniel Doron wrote: >>>> Hi all, >>>> >>>> I have tried to look an answer for this on the web, but I mainly got >>>> "no can do" (timing issue). >>>> >>>> Kernel: 2.6.3x >>>> MCU: atmel at91 (9263) >>>> >>>> I wish to get/write a driver to bitbang a couple of gpios to emulate a >>>> uart. the communication is with a remote PIC (PIC12F683) to which I >>>> have already wrote the software and checked with linux terminal. >>>> the communication does not have to be fast at all (1200 would be >>>> fine). only a few bytes are exchanged. >>>> >>>> can someone point me in the right direction? did someone already >>>> develop such a driver? is there an example/guide I can follow to do it? >>>> >>>> Daniel. >>>> >>> You will probably fail with this, because you need hard real time >>> operation. >>> Even if it is not really fast, you need to sample at least 4 times/bit >>> time to find the start bit and its center and from there on sample the >>> bits at each center point. Anything else will be to sensitive on minor >>> variations from the sender. This timing must be met with at least half a >>> bit time. The sender is a bit easier bit you also have to meet the timing. >>> At 1200 bit/sec this means about 200&micro;sec. Sounds long, but a lot of >>> things can come in the way even if running inside the kernel. It might >>> work if your kernel is doing not much more. >> >> I disagree with the failure prediction. I did a bit banged MIDI >> interface with a PIC16F84 at more than a decade ago with great >> success. The real predictor of success or failure will be your >> requirements. It's true that hard real time response is needed however >> there are many ways to skin this cat. If there's no RTOS, your odds >> of success improve. If there are no other interrupts active, you will >> likely succeed. How many times you need to sample a bit cell will be >> determined by your operating environment, baud rate, reliability >> requirements, etc. > > But did you do it *from linux* (that is what the OP seems to want to do > AIUI).
No I didn't do it from Linux. But I've been in the business long enough to know that a solution frequently can be found if you're clever enough. For example, I propose this idea might work on Linux: Interrupt on a GPIO pin to capture the start bit. Disable all interrupts and poll each bit for all bits that you expect at the operational baud rate. Then enable interrupts after the last bit is captured. At 1200 baud that takes about 10 msec. If the system requirements will tolerate that length of apparent dead time, you've solved the problem of UART receive. JJS
On 11/10/2014 07:44 AM, Daniel Doron wrote:
> Hi all, > > I have tried to look an answer for this on the web, but I mainly got "no can do" (timing issue). > > Kernel: 2.6.3x > MCU: atmel at91 (9263) > > I wish to get/write a driver to bitbang a couple of gpios to emulate a uart. the communication is with a remote PIC (PIC12F683) to which I have already wrote the software and checked with linux terminal. > the communication does not have to be fast at all (1200 would be fine). only a few bytes are exchanged. > > can someone point me in the right direction? did someone already develop such a driver? is there an example/guide I can follow to do it? > > Daniel. >
Are you already using the 3 on chip USARTs on the 9263? If not how about just using one of them as a serial device from Linux.