RS232 serial communication problems with 18F458

Started by Gavin Dingley November 29, 2007
I am fairly new to pics, so you will have to forgive me. I am playing with a 18F458, no particular reason for using this device, it's just I had one available, and for this question I think the scope is general to other devices in the range.

I have prototyped a circuit on breadbaord using this PIC and a MAX232 chip so that I can communicate from a PC to the device through RS232. Basically I have a terminal program on the PC so that when I type a letter it appears as binary on a set of eight LEDs connected to one of the PICs ports; nothing too special, but I wanted to give this ago for interest/educational purposes.

The problem is that the binary patterns that appear on the LEDs do not correspond with the standard ASCII codes for the letter that is sent. Every ASCII character generates a different binary pattern, but not the right one, although the MSB seems to be always lit. In case you are wondering, I have set the terminal to 8 bit communication.

Another curious thing is that from the datasheet the baud rate is set by the instruction cycle clock (i.e. the crystal frequency / 4), but after calculating this I had to up-the baud rate to 4 times so that the binary patterns would change after sending an ASCII character, otherwise the LEDs would only adjust their pattern slightly, it at all. So it appears the baud rate is calculated from the clock frequency:

For correct operation:

Crystal frequency 3680kHz

Baud rate: 4800

I used initially:

x = (clk/4)/(baud_rate * 64) = 0X0D

for baud rate 1200, but found 4800 worked better, so:

x = (clk)/(baud_rate * 64) = 0X0D

(clk is crystal frequency)

Thanks in advance,


Never miss a thing. Make Yahoo your homepage.
I usually start by sending out 55H on the transmit pin and scope it to see what the actual bit timing is.
Once the transmit is correct the receive just follows on.