0
\$\begingroup\$

Here's the situation.

I have a project which utilizes multiple sensors and connects to another unit through standard UART (8N1).

Because no data needs to be missed from any device, I made the multiple sensors function as wireless UART channels which I managed to do successfully, but the standard UART isn't quite working correctly (as some characters are missed on the receiving end of the other unit). I believe it is a math issue.

I cannot use the serial interrupt because if I do then the data will be missed from the sensors, so I am limited to one timer interrupt.

Currently I set the standard UART speed to 38400bps and the individual sensor rates are about 680bps.

Am I configuring the timer correctly?

So my question is this. Is the following math correct when I want to reliably detect when a byte of serial data is processed at 38400bps?

TMOD = 22h ;Timers to mode 2 auto-reload
TH0 = 10h  ;Timer executes every 240 clocks. If I'm not mistaken, 
TL0 = 10h  ;   this means Timer executes 2x before serial character
           ;   is processed? or do I need to subtract a number too?
set timer 0 run
set timer 0 overflow  ;to start timer immediately

Also the crystal speed to my micro is 22.1184Mhz with 33pF ceramic caps between each crystal pin and ground.

The reason why I'm asking is because I'm adapting my ideas from Ricky's software uart tutorial at https://www.8051projects.net/wiki/8051_Software_UART_Tutorial but he has added some extra math to detect when bits come in but his program stalls while waiting for a bit. These stalls are what I don't want which is why I'm going with a timer, but I'm looking for that perfect equation.

Can anyone tell me if I'm in the right direction?

\$\endgroup\$
  • 2
    \$\begingroup\$ I cannot use the serial interrupt because if I do then the data will be missed from the sensors - then you're doing something wrong in your interrupt handling. UART interrupts are almost certainly the correct way to do this. \$\endgroup\$ – brhans Jun 18 '18 at 18:23
  • \$\begingroup\$ I'll clarify something. I'm running 5 UARTs. Because the 8051 only has one hardware UART, I have to make 4 software UARTs. If I use an interrupt for the hardware UART then when it runs then the software UARTs will be out of sync \$\endgroup\$ – Mike Jun 18 '18 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.