Software Uart Sample code

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Software Uart Sample code

1,405 次查看
Moduletimer
Contributor I
Hi I am new to RS08 freescale controller and for one of our applicaton, I have to develope software UART. Can any help me by sharing the software UART code. Its urgent. I am using the MC9RS08KA2 controller. Please help....
标签 (1)
0 项奖励
2 回复数

441 次查看
rocco
Senior Contributor II

Hi Module Timer,

 

I have been lucky in that I have avoided the RS08 parts, so I'm not sure if my suggestion below will apply. Mac is right in suggesting a more capable part. It is often worth the extra pennies for a more suitable part over the extra development time it takes to fill a five-pound bag with ten pounds.

 

I have implemented a software uart using one timer. You set the timer to tick at some multiple "N" of the desired baud rate, sample the incoming stream at every tick, and output the next bit on every Nth tick.

 

Set a state-counter to start counting sample-times (mod N) once you detect the start bit, and then sample the data on states within the bit.

 

As an example:

  • For N=4, set the counter to tick at 4 times the baud rate.
  • Every fourth tick, you can update the output.
  • On every tick, sample the input. If still idle (un-asserted), do nothing.
  • When you detect the "start" bit, set the state-counter to bit 0. It will count from 0 to 3 and back to 0 on each tick.
  • On each state-count of 1, 2 and 3, sample the input. If they are not all the same, then "Majority Rules" determines the bit, and you should set a Noise-Flag.
  • Repeat for each bit, with the state counting 0 through 3, sampling at states1, 2 and 3.
  • After each whole byte, you can test for parity errors, if you need to implement parity.

On my implementation, the timer was also my real-time clock for my scheduler. I used N=8, and sampled on 3, 4 and 5. So it counted continuously, and I masked the low three bits. When the low three bits were zero, I updated the transmitter. I kept a separate counter for the receiver, which I zeroed on the start-bit. I then had it count continuously, with the low three bits being the state-count, and the next higher four bits being the byte counter. I had to implement 11 bits (Start-bit, 8 data-bits, parity-bit, stop-bit).

 

Basically, I copied the algorithm that many hardware uarts use. I wish I could post the code, but it is proprietary to my client. Besides, it's all in assembler, and I assume you would prefer C.

0 项奖励

441 次查看
bigmac
Specialist III

Hello, and welcome to the forum.

 

The RS08KA2 may be a poor choice to implement a firmware SCI function, especially if you require full duplex operation (transmit while receiving data).  With only a sigle 8-bit modulo timer available, I doubt that there will be sufficient timing resources.

 

The RS08KA8 would appear a better choice, with a 2-channel,16-bit TPM module present, in addition to the modulo timer.

 

Regards,

Mac

 

0 项奖励