PDA

View Full Version : Usart compile errors 18F4520



Pedro Pinto
- 6th May 2009, 17:40
Hello All

I try to comunicate via Usart on PORTC.6 and PORTC.7 with Pic 18F4520
and initiate with this:
' Initialize USART
TRISC = %10111111 ' Set TX (PortC.6) to out, rest in
SPBRG = 25 ' Set baud rate to 2400
RCSTA = %10010000 ' Enable serial port and continuous receive
TXSTA = %00100000 ' Enable transmit and asynchronous mode

or with this:
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
DEFINE HSER_BAUD 2400
DEFINE HSER_SPBRG 25
DEFINE HSER_CLROERR 1

but, everytime i want compile the programm it show error messages like:
Symbol not previously defined (RC2IF)
Symbol not previously defined (PIR3)
Symbol not previously defined (RCREG2)
Symbol not previously defined (TX2IF)
Symbol not previously defined (SPBRG2)
Symbol not previously defined (TXREG2)
Symbol not previously defined (TXSTA2)
Symbol not previously defined (RCSTA2)

I use PBP Pro 2.50 and Pic 18F4520
with instruction like this:
HSERIN2 800,final,[wait ("P"),dec2 function,dec3 pcb,dec3 dumy]

Anyone idea what i make wrong?

Thanks for help
Regards
Pedro

Bruce
- 6th May 2009, 17:48
Try HSERIN instead of HSERIN2.

Pedro Pinto
- 6th May 2009, 17:59
Hello Bruce

Thank You for help

I have change all Hserin2 and Hserout2 instructions to Hserin and Hserout and the compiler donīt show more error messages
Do you know why it don't accept the Hersxx2 option?

Regards
Pedro

Bruce
- 6th May 2009, 18:10
Hi Pedro,

How many hardware USARTs does your 18F4520 have?

What does your PBP manual state HSERIN2 is for?

Pedro Pinto
- 6th May 2009, 22:52
Hello again

With this initialisation i can receive well on the terminal program if i change on that the baudrate to 9600. What can be wrong, it must be 2400, or not?

DEFINE OSC 16
'
' Initialize USART
TRISC = %10111111 ' Set TX (PortC.6) to out, rest in
SPBRG = 25 ' Set baud rate to 2400
RCSTA = %10010000 ' Enable serial port and continuous receive
TXSTA = %00100000 ' Enable transmit and asynchronous mode
'
hserout ["SCCP",13,10]


Regards
Pedro

mister_e
- 6th May 2009, 23:03
SPBRG = 25 is 2400 baud @4MHZ, not 16MHz.

If you need 2400 baud @16Mhz you should try those settings


DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_SPBRG 103 ' 2400 Baud @ 16MHz, 0.17%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically


@9600 bauds

DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_SPBRG 25 ' 9600 Baud @ 16MHz, 0.16%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically


etc etc etc.

Try my PICMultiCalc for that.

Download it from there
http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2957&d=1225550328

Luckyborg
- 6th May 2009, 23:09
using Mr E's Multi-calc's recommended settings

9600 baud


RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $24 ' Enable transmit, BRGH = 1
SPBRG = 160 ' 9600 Baud @ -0.08%
SPBRGH = 1
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator


2400 baud

RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $24 ' Enable transmit, BRGH = 1
SPBRG = 130 ' 2400 Baud @ 0.0%
SPBRGH = 6
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator

The code you posted should have been sending data out at 9600 baud with SPBRG set to 25. Set SPBRG to 103 for 2400 baud. The error rate would be a little higher than the above code snippet (not that it would probably matter in the real world).


RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $20 ' Enable transmit, BRGH = 0
SPBRG = 103 ' 2400 Baud @ 0.17%

Thanks to Mr E :)
David

Luckyborg
- 6th May 2009, 23:09
I knew I left that post reply open too long...

Luckyborg
- 6th May 2009, 23:13
I didn't realize I was using an old version. I was still on 1.1.0

Thanks for the update :)

David