Hello everyone. I'm having a strange problem with the baud rate generator on this chip. For some reason, even when I enter in values straight from the datasheet I am off by a factor of ten. For example, if I set up everything for 19200 baud I'll end up with 1920 baud. Set for 9600 baud? I end up with 960 baud. Also, when I use realterm I get nothing but 00s as my data. No matter what I transmit. I've played around with this most of the day and I can't seem to find my error. Any ideas?
oscillator config
UART config (Please ignore the parameter in enable_comm(). I've "hardcoded" the function for now to help troubleshoot)
I/O section
oscillator config
Code:
// Oscillator Config
OSCCONbits.SPLLEN = 0; // no PLL
OSCCONbits.IRCF = 0b1110; // running at 8Mhz.
Code:
// UART Config
TX1STAbits.BRGH = 1; // low speed baud. Baudrate = fosc/16(SPBRGH:SPBRGL + 1)
BAUD1CONbits.BRG16 = 0; // 8 bit baudrate generator
TX1STAbits.SYNC =0; // Asynchronous comm
enable_comm(9600); // start comm port 19200 baud
void enable_comm(unsigned int baudrate)
{
SP1BRGL = 25;
TX1STAbits.TXEN = 1; // enable data out
RC1STAbits.CREN = 1; // enable continuous receive
RC1STAbits.SPEN = 1; // enable serial port
RC1STAbits.RX9 = 0; // disable 9bit reception
TX1STAbits.TX9 = 0; // disable 9bit transmission
}
Code:
// I/O Config
TRISAbits.TRISA5 = 0; // heartbeat I/O
TRISCbits.TRISC5 = 1; // RS232 Rx
RXPPS = 0b10101; // Setting up rs232 input on RC5
TRISCbits.TRISC0 = 0; // RS232 Tx
RC0PPS = 0b10010; // set as peripheral output
TRISAbits.TRISA2 = 0; // used for debug out
TRISCbits.TRISC7 = 1; // PWM out. Set to input for now. Switching to output later
RC7PPS = 0b01110; // Using PWM module 3
Code:
void transmit_data(unsigned char data)
{
TX1REG = data;
}