I was wondering, is it possible to change the baudrate of a HW serial interface after initial configuration?
For example, i set a #define USART_BAUD_RATE 2400 statement at start of code, then, if i want to change the speed, could i reset somehow the USART module and redefine a new baudrate inside code loop?
The pic i'm currently using is 16F1618 and PIC 16F1579.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I took a look to the assembly cowbasic produced and found the INITUSART routine. After some tests, i found out that there is only one command that changes value by changing baud rate. The ASM code is: INITUSART
;comport = 1
movlw 1
movwf COMPORT
;SPBRG = SPBRGLTEMP
** movlw 207
banksel SPBRG
movwf SPBRG
;SPBRGH = SPBRGHTEMP
clrf SP1BRGH
;BRG16 = BRG16TEMP
bsf BAUD1CON,BRG16
;BRGH = BRGHTEMP
bsf TX1STA,BRGH
;Set SYNC Off
bcf TX1STA,SYNC
;SPEN=1
bsf RC1STA,SPEN
;CREN=1
bsf RC1STA,CREN
;Set TXEN On
bsf TX1STA,TXEN
banksel STATUS
return
The line in bold, is the value that is changed when baud is changed, everything else is exactly the same.
So now, how exactly can i load this value inside basic code? Is there some special command to set the register SPBRG to the desired value? And will this be enough for "on the fly" correct changing of the baud rate?
Last edit: ikonsgr74 2018-04-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well,in the end, it was easier than expected, just a SPBRGL=x command, where X is the value needed for the desired baud, was enough to change speed "on the fly".
I love cow basic! :-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Everyone,
I was wondering, is it possible to change the baudrate of a HW serial interface after initial configuration?
For example, i set a #define USART_BAUD_RATE 2400 statement at start of code, then, if i want to change the speed, could i reset somehow the USART module and redefine a new baudrate inside code loop?
The pic i'm currently using is 16F1618 and PIC 16F1579.
Yes, but, you will have to calculate the settings and load the registers with the correct value.
I took a look to the assembly cowbasic produced and found the INITUSART routine. After some tests, i found out that there is only one command that changes value by changing baud rate. The ASM code is:
INITUSART
;comport = 1
movlw 1
movwf COMPORT
;SPBRG = SPBRGLTEMP
** movlw 207
banksel SPBRG
movwf SPBRG
;SPBRGH = SPBRGHTEMP
clrf SP1BRGH
;BRG16 = BRG16TEMP
bsf BAUD1CON,BRG16
;BRGH = BRGHTEMP
bsf TX1STA,BRGH
;Set SYNC Off
bcf TX1STA,SYNC
;SPEN=1
bsf RC1STA,SPEN
;CREN=1
bsf RC1STA,CREN
;Set TXEN On
bsf TX1STA,TXEN
banksel STATUS
return
The line in bold, is the value that is changed when baud is changed, everything else is exactly the same.
So now, how exactly can i load this value inside basic code? Is there some special command to set the register SPBRG to the desired value? And will this be enough for "on the fly" correct changing of the baud rate?
Last edit: ikonsgr74 2018-04-27
Well,in the end, it was easier than expected, just a SPBRGL=x command, where X is the value needed for the desired baud, was enough to change speed "on the fly".
I love cow basic! :-)