Software UART Code for MC9S08QD4

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Software UART Code for MC9S08QD4

Jump to solution
1,325 Views
venkateshgv
Contributor II

Hi..

 

I am using MC9S08QD4, in this the UART protocol is not present, So i am looking for building software uart.

 

Is it possible?

 

If possible any body having sample code for this and pls share it.

 

Regards

Venkatesh

Labels (1)
0 Kudos
Reply
1 Solution
933 Views
tonyp
Senior Contributor II

Yes, it's possible to implement a 100% software UART (even having different baud rates for TX and RX, if you like).  What do you think people did before hardware UARTs were invented?

The whole concept is based on relatively accurate bit timing (there a small allowance of baud rate mismatch).  I have code for several versions of this (all in ASM8 assembly language) and if you can follow assembly I could provide some but I will have to clean it up a bit from some proprietary code before posting it.  So, let me know if assembly code is good for you and I'll try to get it ready in a few days.  (UPDATE: Code is now attached -- you will need ASM8 to assemble.)

Regardless, the idea is pretty much this:

For RX:

* You need a half-bit time delay, and a full bit time delay for the baud rate you need.

* You poll and wait for a start bit edge (a zero, normally -- unless your line is inverted).

* Once you get the start bit, you wait half bit to go to the center of the bit for sampling.

* Then you enter a loop starting with a full bit delay (this will bring you to the center of the first data bit).

* You read the RX line's state (you can even make multiple reads -- say, 3) to eliminate possible noise on the line.  You accept what the majority of the reads give you.

* You shift the bit into the most significant bit of your data byte (a rotate right in assembly)

* You repeat the loop for 8 bits and you're done.

For TX:

* You only need a full bit time delay routine.

* You do the start  bit (normally, a zero).

* You delay for a bit time.

* You shift out the next bit (rotate right).

* Depending on the shifted out bit being 0 or 1 you set the TX line accordinly.

* You repeat the loop for 9 bits (start plus 8 data) and you're done.

* Don't forget to leave the TX line high (and wait a bit time) for stop bit.

Hope this helps.

View solution in original post

0 Kudos
Reply
3 Replies
933 Views
vicentegomez
NXP TechSupport
NXP TechSupport

Hi

Also you can use as reference the application note AN2637, this is for a HC08 device but it can help you.


Have a great day,
Vicente

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
934 Views
tonyp
Senior Contributor II

Yes, it's possible to implement a 100% software UART (even having different baud rates for TX and RX, if you like).  What do you think people did before hardware UARTs were invented?

The whole concept is based on relatively accurate bit timing (there a small allowance of baud rate mismatch).  I have code for several versions of this (all in ASM8 assembly language) and if you can follow assembly I could provide some but I will have to clean it up a bit from some proprietary code before posting it.  So, let me know if assembly code is good for you and I'll try to get it ready in a few days.  (UPDATE: Code is now attached -- you will need ASM8 to assemble.)

Regardless, the idea is pretty much this:

For RX:

* You need a half-bit time delay, and a full bit time delay for the baud rate you need.

* You poll and wait for a start bit edge (a zero, normally -- unless your line is inverted).

* Once you get the start bit, you wait half bit to go to the center of the bit for sampling.

* Then you enter a loop starting with a full bit delay (this will bring you to the center of the first data bit).

* You read the RX line's state (you can even make multiple reads -- say, 3) to eliminate possible noise on the line.  You accept what the majority of the reads give you.

* You shift the bit into the most significant bit of your data byte (a rotate right in assembly)

* You repeat the loop for 8 bits and you're done.

For TX:

* You only need a full bit time delay routine.

* You do the start  bit (normally, a zero).

* You delay for a bit time.

* You shift out the next bit (rotate right).

* Depending on the shifted out bit being 0 or 1 you set the TX line accordinly.

* You repeat the loop for 9 bits (start plus 8 data) and you're done.

* Don't forget to leave the TX line high (and wait a bit time) for stop bit.

Hope this helps.

0 Kudos
Reply
933 Views
venkateshgv
Contributor II

Hello..Tony..

Thanks for the idea.

Yes, i can able to understand the Assembly language

once u finish..pls share ..

0 Kudos
Reply