Changing Baud Rate Using picserialdrv

Is there anyone that has tried using the serial ports at different baud rates before? I’m trying to connect a gps to the TTL port and I’ve set the baud rate to 9600 but the setting is either ignored or overridden. Does anyone know what is going on? The code implies that you are able to change the baud rate yet every time I try it doesn’t change at all.



  Open2USART(USART_TX_INT_ON & USART_RX_INT_ON & USART_ASYNCH_MODE &
    USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, baud_96); 
  
  IPR3bits.RC2IP = PRIORITY;     
  IPR3bits.TX2IP = PRIORITY;     
  TRISGbits.TRISG1 = 0;         /*TX2 output*/
  TRISGbits.TRISG2 = 1;         /*RX2 input */

  flush = RCREG2;               /* flush data */
  flush = RCREG2;               /* flush data */
  RXINTF2 = 0;

  dataOut.TX_SYNC1 = 0xAA;
  dataOut.TX_SYNC2 = 0x55;

  PC_Status = (PcBitsPtr) &PC_Control_Byte;
  PC_Status->PCInControl = TRUE;

I’m using mplab to write this code.
:mad: :confused: :mad:
many thanks in advance

Can you establish communications with your PC at 9600 bps ???

You did look at \mcc18\h\usart.h header file and found USART_BRGH_LOW, but did you check the PIC 18F8520 manual to determine what the proper BAUD RATE for 9600 is?? I see it coded in …\VexCode_StartUp\PicSerialDrv.h as “baud_96 = 64, // Low speed”, but a little checking might be a good idea…

I see UART #1 being opened two places in the VexCode_StartUp, but UART #2 is only opened in PicSerialDrv.c on line 152.

I do see one anomaly… The BAUD RATE is set through an Enumeration, SERIAL_SPEED. There are Two Enumerations for SERIAL_SPEED… One in ifi_utilities.h, and one in PicSerialDrv.h, the one in PicSerialDrv.h has “baud_96”, the one in ifi_utilities.h does not.

I wonder if there is an issue with the value of “baud_96”. You might add “baud_96” to the Enumeration, SERIAL_SPEED in the Header File “ifi_utilities.h” to see if that might be the issue…

Get These:
PIC18F6520/8520/6620/8620/6720/8720 Datasheet
PIC18F6520/8520 Rev. A1 Silicon/Data Sheet Errata
Timer1Module Data Sheet Errata

(add)
All my Vex Controllers are “loaned out” to the local High School team for the First Tech Challenge, so I can not try it myself right now…

I am using hyperterminal to establish a connection at 9600 baud. 

The baud rate did come out to the correct value according to the datasheet.

The discrepancy between the two enumerations did not make a difference, as long as it was defined somewhere.

 You can add your own baud rates as long as you stick with the proper divisors to generate your numbers, for example I was able to establish a connection with the bot at 4800 baud which is not previously defined. The code for that was

Open1USART(USART_TX_INT_ON & USART_RX_INT_ON & USART_ASYNCH_MODE &
    USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, baud_96*2); 

I didn’t actually feel like adding to the enumeration (because i’m lazy like that) so i doubled the divisor to bring the baud down to 4800
I’ll post the divisors later, the numbers aren’t off the top of my head.

UART 1 is opened under the function Initialize_Serial_Comms. However, this function is only called from user routines.c which means that the two openings don't conflict. for the picserialdrv is meant to opperate with the ddt version of the project. 

In conclusion, I was able to change the baud rates on both serial ports however, I don't have a reason why it didn't work before because i've tried the thing several times. 

the initialization code looked like this:


Open1USART(USART_TX_INT_ON & USART_RX_INT_ON & USART_ASYNCH_MODE &
    USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, baud_96);