Hi Pedro,
How many hardware USARTs does your 18F4520 have?
What does your PBP manual state HSERIN2 is for?
Hi Pedro,
How many hardware USARTs does your 18F4520 have?
What does your PBP manual state HSERIN2 is for?
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
SPBRG = 25 is 2400 baud @4MHZ, not 16MHz.
If you need 2400 baud @16Mhz you should try those settings
@9600 baudsCode: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
etc etc etc.Code: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
Try my PICMultiCalc for that.
Download it from there
http://www.picbasic.co.uk/forum/atta...7&d=1225550328
Last edited by mister_e; - 6th May 2009 at 23:07.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
using Mr E's Multi-calc's recommended settings
9600 baud
2400 baudCode: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
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).Code: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
Thanks to Mr ECode:RCSTA = $90 ' Enable serial port & continuous receive TXSTA = $20 ' Enable transmit, BRGH = 0 SPBRG = 103 ' 2400 Baud @ 0.17%
David
I didn't realize I was using an old version. I was still on 1.1.0
Thanks for the update
David
Bookmarks