EmbeddedRelated.com
Forums

8051 serial problems

Started by Edo Reshef April 21, 2004
Hi,

I have an 8051 controller that communicates over RS485 to other 8051
controller. The communication is half-duplex at baud of 57600, and it
works great. So far so good.
Lately, I'm trying to make the 8051 device talk with a PC, since it is
57600 and I have RS232<>RS485 converter this should be simple.

I'm encountering strange problems at the 8051 reception, I never
received what I send from the PC. For example:
             msb  lsb
PC Sends  -> 11011011
8051 Gets -> 10111011

PC Sends  -> 10110011
8051 Gets -> 01110011

PC Sends  -> 11000101
8051 Gets -> 10000101

PC Sends  -> 10101011
8051 Gets -> 01001011

Even more, when the msb is "0" the reception interrupt does not
trigger.
It looks like the 8051 ignores the PC start bit or something...

The protocol is 9-bit multi-drop, which i already implemented on PC
side using Space and Mark parities, it worked fine with some other
9-bit PIC devices.

I'm debugging the 8051 device with a DS-ICE but i don't think this is
the problem.
I'm totally out of ideas what could be wrong.

Regards,
  Edo Reshef
>PC Sends -> 11011011 >8051 Gets -> 10111011 > >PC Sends -> 10110011 >8051 Gets -> 01110011 > >PC Sends -> 11000101 >8051 Gets -> 10000101 > >PC Sends -> 10101011 >8051 Gets -> 01001011 > >Even more, when the msb is "0" the reception interrupt does not >trigger. >It looks like the 8051 ignores the PC start bit or something... > >The protocol is 9-bit multi-drop, which i already implemented on PC >side using Space and Mark parities, it worked fine with some other >9-bit PIC devices. >
Remember that serial data is sent lsb first. It seems something odd is happening at the end of reception, not at the start.
Edo Reshef schrieb:

> I have an 8051 controller that communicates over RS485 to other 8051 > controller. The communication is half-duplex at baud of 57600, and it > works great. So far so good. > Lately, I'm trying to make the 8051 device talk with a PC, since it is > 57600 and I have RS232<>RS485 converter this should be simple. > > I'm encountering strange problems at the 8051 reception, I never > received what I send from the PC. For example: > msb lsb > PC Sends -> 11011011 > 8051 Gets -> 10111011 > > PC Sends -> 10110011 > 8051 Gets -> 01110011 > > PC Sends -> 11000101 > 8051 Gets -> 10000101 > > PC Sends -> 10101011 > 8051 Gets -> 01001011 > > Even more, when the msb is "0" the reception interrupt does not > trigger. > It looks like the 8051 ignores the PC start bit or something...
It cannot. A start bis is a start bit, wherever it comes from.
> The protocol is 9-bit multi-drop, which i already implemented on PC > side using Space and Mark parities, it worked fine with some other > 9-bit PIC devices.
I think the problem is somewhere in this area. PCs are not likely to support 9-bit frames, and if it works, it's not really safe or reproducible. Maybe your positive experience was made with another PC or another software configuration.
> I'm debugging the 8051 device with a DS-ICE but i don't think this is > the problem. > I'm totally out of ideas what could be wrong.
I strongly recommend to look at the interface lines with a DSO and check if the PC really sends correctly. You might also consider testing the communication at lower speeds first (where the PC hack might eventually work). Did you also try the other direction already? -- Dipl.-Ing. Tilmann Reh Autometer GmbH Siegen - Elektronik nach Ma&#4294967295;. http://www.autometer.de
"Edo Reshef" <edoreshef@hotmail.com> wrote in message
news:7a494870.0404210733.58b36103@posting.google.com...
> Hi, > > I have an 8051 controller that communicates over RS485 to other 8051 > controller. The communication is half-duplex at baud of 57600, and it > works great. So far so good. > Lately, I'm trying to make the 8051 device talk with a PC, since it is > 57600 and I have RS232<>RS485 converter this should be simple. > > I'm encountering strange problems at the 8051 reception, I never > received what I send from the PC. For example: > msb lsb > PC Sends -> 11011011 > 8051 Gets -> 10111011 > > PC Sends -> 10110011 > 8051 Gets -> 01110011 > > PC Sends -> 11000101 > 8051 Gets -> 10000101 > > PC Sends -> 10101011 > 8051 Gets -> 01001011 >
Looking at the bit patterns, I'd say either your timing is off (not exactly 57600) or your signal edges are not steep enough due to, for instance, a long cable or low-pass filters on a serial port. Check the signal with an oscilloscope. Meindert
Edo Reshef wrote:
> Hi, > > I have an 8051 controller that communicates over RS485 to other 8051 > controller. The communication is half-duplex at baud of 57600, and it > works great. So far so good. > Lately, I'm trying to make the 8051 device talk with a PC, since it is > 57600 and I have RS232<>RS485 converter this should be simple. > > I'm encountering strange problems at the 8051 reception, I never > received what I send from the PC. For example: > msb lsb > PC Sends -> 11011011 > 8051 Gets -> 10111011 > > PC Sends -> 10110011 > 8051 Gets -> 01110011 > > PC Sends -> 11000101 > 8051 Gets -> 10000101 > > PC Sends -> 10101011 > 8051 Gets -> 01001011 > > Even more, when the msb is "0" the reception interrupt does not > trigger. > It looks like the 8051 ignores the PC start bit or something... > > The protocol is 9-bit multi-drop, which i already implemented on PC > side using Space and Mark parities, it worked fine with some other > 9-bit PIC devices.
This has a strong scent of a speed / distorsion error. It seems that after 6 bits, the 8051 is off by one bit time. Please remember that initially the RS-232 standard limited the transfer speed to 20000 bits/s. There may be edge slow-down capacitors at either or both ends of the RS-232 data lines. Which crystal and what divisor are you using on the 8051's? Tauno Voipio tauno voipio @ iki fi
edoreshef@hotmail.com (Edo Reshef) wrote:

>Hi, > >I have an 8051 controller that communicates over RS485 to other 8051 >controller. The communication is half-duplex at baud of 57600, and it >works great. So far so good. >Lately, I'm trying to make the 8051 device talk with a PC, since it is >57600 and I have RS232<>RS485 converter this should be simple. > >I'm encountering strange problems at the 8051 reception, I never >received what I send from the PC. For example: > msb lsb >PC Sends -> 11011011 >8051 Gets -> 10111011 > >PC Sends -> 10110011 >8051 Gets -> 01110011 > >PC Sends -> 11000101 >8051 Gets -> 10000101 > >PC Sends -> 10101011 >8051 Gets -> 01001011
Looks like the 8051 baud rate is about 10% faster than the PC.
Gary Kato wrote:

> PC Sends -> 11011011 >>8051 Gets -> 10111011 >> >>PC Sends -> 10110011 >>8051 Gets -> 01110011 >> >>PC Sends -> 11000101 >>8051 Gets -> 10000101 >> >>PC Sends -> 10101011 >>8051 Gets -> 01001011 >>Even more, when the msb is "0" the reception interrupt does not >>trigger. >>It looks like the 8051 ignores the PC start bit or something... >> >>The protocol is 9-bit multi-drop, which i already implemented on PC >>side using Space and Mark parities, it worked fine with some other >>9-bit PIC devices. >> > > Remember that serial data is sent lsb first. It seems something odd is > happening at the end of reception, not at the start.
and that suggests the MSB is perhaps sliding into the STOP bit, either drive slew as has been suggested, or simply the wrong BAUD rate. Your errors are all 'at one end' which does not suggest driver skew, but does fit baud rate miss-match. -jg
garykato@aol.com (Gary Kato) wrote in message news:<20040421115816.07978.00000055@mb-m27.aol.com>...
> >PC Sends -> 11011011 > >8051 Gets -> 10111011 > > > >PC Sends -> 10110011 > >8051 Gets -> 01110011 > > > >PC Sends -> 11000101 > >8051 Gets -> 10000101 > > > >PC Sends -> 10101011 > >8051 Gets -> 01001011 > > > >Even more, when the msb is "0" the reception interrupt does not > >trigger. > >It looks like the 8051 ignores the PC start bit or something... > > > >The protocol is 9-bit multi-drop, which i already implemented on PC > >side using Space and Mark parities, it worked fine with some other > >9-bit PIC devices. > > > > Remember that serial data is sent lsb first. It seems something odd is > happening at the end of reception, not at the start.
Good point! I didn't know that, that make sense! But how can you explain that if the MSB is "0" the byte is not received at all?
Tilmann Reh <tilmannreh@despammed.com> wrote in message news:<c665p1$qg2$1@online.de>...

> I think the problem is somewhere in this area. PCs are not likely > to support 9-bit frames, and if it works, it's not really safe > or reproducible. > Maybe your positive experience was made with another PC or another > software configuration.
I have done 9-bit framing with a PC at 57600 baud rate communicating to a PIC controller, it works perfect, sending the 9-bit is really easy, receiving it a bit is more tricky but I'm not interested in receiving so I'm OK.
> I strongly recommend to look at the interface lines with a DSO > and check if the PC really sends correctly. > You might also consider testing the communication at lower > speeds first (where the PC hack might eventually work). > > Did you also try the other direction already?
I'll check it with a DSO and see what comes up, I have a really old DSO so I will see if i can make it work....
Edo Reshef wrote:
> Good point! I didn't know that, that make sense! But how can you > explain that if the MSB is "0" the byte is not received at all?
Because then the stop bit is invalid (due to baud-timing-skew).... Post up your xtal, and timer reload values, and there are plenty here who will spot a ooops... -jg