
Originally Posted by
HenrikOlsson
Yes, you can have different baudrate(s) on different UARTs and yes you can change it at any time you want. But, as the posts in the other thread says, to change it you can't use PBPs DEFINE HSER_BAUD because that's a compile time directive and not a runtime command.
If you want to set or change the baudrate at runtime you need to set or change the registers manually. BAUDCON, SPBRG, SPBRGH most of the time. And remember that the register names are different for the second UART - BAUDCON2, SPBRG2 etc.
Without seeing your code we can't say why what you did didn't work.
Hi Henrik,
i did have the DEFINEs on the code like this.
Code:
'*-----------------------------------------------------------------------------|
'* | --------------------- | |
'*----------------------- | EUART 1 Configuration | --------------------------|
'* | --------------------- | |
'*-----------------------------------------------------------------------------|
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_SPBRG 160 ' 38400 Baud @ 64MHz, -0,08%
SPBRGH = 1
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
'*-----------------------------------------------------------------------------|
'* | --------------------- | |
'*----------------------- | EUART 2 Configuration | --------------------------|
'* | --------------------- | |
'*-----------------------------------------------------------------------------|
'DEFINE HSER2_RCSTA 90h ' Enable serial port & continuous receive
'DEFINE HSER2_TXSTA 24h ' Enable transmit, BRGH = 1
'DEFINE HSER2_CLROERR 1 ' Clear overflow automatically
'DEFINE HSER2_SPBRG 160 ' 38400 Baud @ 64MHz, -0,08%
'SPBRGH2 = 1
'BAUDCON2.3 = 1 ' Enable 16 bit baudrate generator
DEFINE HSER2_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER2_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER2_CLROERR 1 ' Clear overflow automatically
DEFINE HSER2_SPBRG 130 ' 9600 Baud @ 64MHz, -0,02%
SPBRGH2 = 6
BAUDCON2.3 = 1 ' Enable 16 bit baudrate generator
'------------------------------------------------------------------------------|
'-----------sent a sentence to gps, this is not working at the moment----------|
'------------------------------------------------------------------------------|
' When the GPS Module is POWERED ON, then the following sentenses are received.
' $PMTK011,MTKGPS*08
' $PMTK010,001*2E
' $PMTK010,002*2D
pause 800
HSEROUT2 ["$PMTK251,38400*27",13,10] ' 38400 boundrate, check MTK manual configuration
pause 500
RCSTA2 = $90 ' Enable serial port & continuous receive
TXSTA2 = $24 ' Enable transmit, BRGH = 1
SPBRG2 = 160 ' 38400 Baud @ 64MHz, -0,08%
HSEROUT2 ["$PMTK220,100*2F",13,10] ' 100(millisecond)=0.1(sec)-->1/0.1= 10Hz
On the first stage that i send the following command, to change the baudrate for the GPS, it works because both PIC and GPS are at the same rate.
Code:
B]HSEROUT2[/B] ["$PMTK251,38400*27",13,10] ' 38400 boundrate, check MTK manual configuration
then i guess with the following code that i change the rate on the PIC's port.
Code:
RCSTA2 = $90 ' Enable serial port & continuous receive
TXSTA2 = $24 ' Enable transmit, BRGH = 1
SPBRG2 = 160 ' 38400 Baud @ 64MHz, -0,08%
then send the command which seems that it doesnt work.
Code:
HSEROUT2 ["$PMTK220,100*2F",13,10] ' 100(millisecond)=0.1(sec)-->1/0.1= 10Hz
Bookmarks