Log in

View Full Version : RS232 & PIC18F



Christos_K
- 14th June 2005, 21:03
Sorry for all those continuous questions but its really frustrating! I used a PIC16f to communicate via rs232 to my pc! Everything worked ok!

I now replaced the pic with a PIC18f2680 and I get nothing on the screen of my PC when sending a "Hello". Something is received but I think it is a problem with the communication protocols. Does anyone know how I need to set the HSER_BAUDCON register for 2400pbs communication?

I though I could only set the brg16 to zero but nothing... Here is my code which worked (without the define hser_baudcon) with a pic16f.

DEFINE HSER_RCSTA 90h 'Enable Serial PORT
'8 bit reception
'Disable Single receive
'Enable continuous receive
'All bytes received, diable address detection
'No framming Error
'No overrun error

DEFINE HSER_TXSTA 20h '8 bit transmission
'Enable transmit
'Asyncronous mode
'Low baud rate (BRGH=0)
'TSR full

define HSER_BAUDCON 0h
DEFINE HSER_SPBRG 64 'set USART to 2400 baud (when BRGH=0)
define hser_cloeer 1


'Oscillation Settings
'---------------------

DEFINE OSC 10


loop:

hserout ["Hello",13]
pause 100
goto loop


=====================
Same code doesn't work with 18f2680.

According to PIC18f2680 datasheet when Sync=0, BRGH=0 and BRG16=0 for 2400bps you set SPBRG = 64 at 10MHz...Could it be that some of the BAUDCON bits other than BRG16 shouldn't be 0??

Christos_K
- 15th June 2005, 00:03
Well something weired is happening now..Apparently I should have set the oscillator configuration bit to HS..(can anyone explain to me what are the differences of say xt, hs, lp tec?)..When i connect it starts showing dummy characters but when i press the reset button it sends the hello word as it should be...If i disconnect and connect again the same thing happens...I need to press reset ...Can anyone figure out or suggest why this is happening?

angelika
- 15th June 2005, 14:13
I think:

TXSTA=%00100100 ' Enable transmit and asynchronous mode , 24h and not 20h
DECLARE HSERIAL_CLEAR=ON ' Optionally clear the buffer before receiving
Clear the overflow error bit before commencing a read.

if I will find other wrong then I post it.(sorry for my bad english).