News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Setting Baud USART2 in run time

Started by Gamboa, Mar 24, 2022, 12:23 PM

Previous topic - Next topic

Gamboa

Hi,

I am using the USART2 of a PIC24F64GA306 and I have to change the baud rate at runtime.
I've used a procedure with multiple declares, but the compiler doesn't like this method very much.

  Proc UART2_Inicializar()

   DireccionMemoria = 32764 'Leo la velocidad USART2
   Velocidad_U2 = LeerByteEEPROM(DireccionMemoria)
   Select Case Velocidad_U2 'Compruebo que la velocidad leida es una velocidad permitida
     Case VELOCIDAD9600
       Declare Hserial2_Baud = 9600
     Case VELOCIDAD19200
       Declare Hserial2_Baud = 19200
     Case VELOCIDAD38400
       Declare Hserial2_Baud = 38400
     Case VELOCIDAD57600
       Declare Hserial2_Baud = 57600
     Case VELOCIDAD115200
       Declare Hserial2_Baud = 115200
     Case Else             'Si no es permitida pongo 9600
       Declare Hserial2_Baud = 9600
   EndSelect

    Declare HRSOut2_Pin = PORTB.6 ' Selecciona pin para TX en USART2
    Declare HRSIn2_Pin = PORTB.7  ' Selecciona pin para RX en USART2

    IFS1bits_U2RXIF = 0  'Flag de interrupcion de recepcion RX2
    IEC1bits_U2RXIE = 1 'Habilitar interrupcion de recepcion RX2

  EndProc

The compiler warns with several warnings about the problem.

Warning! Line [1173] In file [e:\Empresa\....\Ritanium24_4_0_3.bas] *** Declare 'HSERIAL2_BAUD' Has already been used in the program. This declaration will be ignored! ***

Is there a way to do this with compiler directives, or do I need to manipulate the USART2 control registers directly?

regards,
Gamboa

Long live for you

Yasin

HSerial2_ChangeBaudYou should use this.

Gamboa

Long live for you