Hello,
I have a sensor that sends data to the microcontroller via UART with the following specifications:
Baud Rate: 9600
Data Bits: 8
Parity: None
Stop Bits: 1
Flow Control: None
Voltage: 3V
Below are some snippets of my code (I apologize for the lack of comments)
SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); // PLL (400MHz) / 2 / 2.5 (SYSDIV) = 80 MHz system clock speed
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); // enable GPIO Port C peripheral SysCtlPeripheralEnable(SYSCTL_PERIPH_UART4); // enable UART4 peripheral GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5); // assign pin types in Port C as UART GPIOPinConfigure(GPIO_PC4_U4RX); GPIOPinConfigure(GPIO_PC5_U4TX); UARTConfigSetExpClk(UART4_BASE,SysCtlClockGet(),9600, UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE); UARTFIFOEnable(UART4_BASE); UARTIntRegister(UART4_BASE,UART_Handler); UARTIntEnable(UART4_BASE,UART_INT_RX); UARTEnable(UART4_BASE);
void UART_Handler(void) {
UARTIntClear(UART4_BASE,UART_INT_RX);
int i = 0;
char uartrecv;
do
{
// Read a character using the blocking read function. This function
// will not return until a character is available.
uartrecv = UARTCharGet(UART4_BASE);
UART_buffer[i] = uartrecv;
i++;
//
// Stay in the loop until either a CR or LF or i<10 is received.
//
} while((uartrecv != '\n') && (uartrecv != '\r') && (i<32));
}
The problem is that the UART_buffer has a bunch of random characters. As well, when I look into the register, the frame error bit goes high once in a while...
I'm not really sure what I'm doing since I'm new to using UART.
Thanks in advance!