Menu

Redefining HW Serial interface BaudRate,is it possible?

Help
ikonsgr74
2018-04-21
2018-04-27
  • ikonsgr74

    ikonsgr74 - 2018-04-21

    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.

     
  • Anobium

    Anobium - 2018-04-21

    Yes, but, you will have to calculate the settings and load the registers with the correct value.

     
  • ikonsgr74

    ikonsgr74 - 2018-04-27

    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
  • ikonsgr74

    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! :-)

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.