A discussion group for the PICMicro microcontroller. Also called the Microchip PIC, this list is dedicated to the use and abuse of this fine, simple, microcontroller. Close to topic posts are welcome, ie. general electronics.
|
Hello, I've just spent a *very* long time fooling around with a rs232 asyncronous reciever on an RB interrupt. The interrupt looks something like this: #int_RB void RxChar() // input through RB7 { INTCON.RBIE=0; RCREG_X=fgetc(MCP_rs232); restart_wdt(); INTCON.RBIF=0; INTCON.RBIE=1; INTCON.GIE=1; } The fastest I can get the baud rate without getting errors is 19200 on an 11059200 Hz clock. An example is recieving A2 when in fact it is a 44. And a 8A when in fact it is a 15 (all in hex). Heres what i suspect: In rs232, LSB is sent first. 0x44 = 0b01000100 0xA2 = 0b10100010 When in rs232 the order is then flipped so 0b01000100 -> 00100010... comparing this to 0xA2 as it would appear over a rs232 line is 01000101. 01000101 ... the A2 in reverse order (what i got) 00100010 ... the 44 in reverse order (what i expected) It looks rather simple to fix (just shift it right and throw on a zero), but is there a better way to fix this problem without creating my own getc()? Im not sure what would happen if the rs232 value had a leading 1, ie 10110101... probably blow up. BTW: the 15 and 8A works the exact same way. I'm also thinking that if i were to increase my clock speed (while keeping it a nice multiple of 9600) then that might also remedy the problem. Chris |