Hello,
I am using the following code to initialize UART0.
#define UART_RE_SHIFT 2
#define UART_TE_SHIFT 3
#define UART0_DISABLE_RECEPTION (UART0_C2 &= ~(1<<UART_RE_SHIFT))
#define UART0_ENABLE_RECEPTION (UART0_C2 |= (1<<UART_RE_SHIFT))
#define UART0_DISABLE_TRANSMISSION (UART0_C2 &= ~(1<<UART_TE_SHIFT))
#define UART0_ENABLE_TRANSMISSION (UART0_C2 |= (1<<UART_TE_SHIFT))
void Init_UART0_General (void)
{
uint8_t dummy;
/* Setup Clock Source for UART 0
* Select clock source to be MCGFLLCLK
* (we are in FEE mode with MCGFLLCLK=20.9MHz)
*/
SIM_SOPT2 |= (SIM_SOPT2_UART0SRC(SOPT2_UART0_MCGFLLCLK));
/* Enable UART0 clock */
SIM_SCGC4 |= SIM_SCGC4_UART0_MASK;
/* Setup Port Control Register for RX pin */
gUART0_RX_PCR_REG_c = PORT_PCR_MUX(gUART0_PORT_MUX_c);//gUART0_PORT_MUX_c);
/* Setup Port Control Register for TX pin */
gUART0_TX_PCR_REG_c = PORT_PCR_MUX(gUART0_PORT_MUX_c);
//PORTA_PCR1_IRQC page 273(142)
PORTA_PCR1 |= (1 << 17); // Interruption on falling edge
/* Disable transceiver to do the configuration */
UART0_DISABLE_RECEPTION;
UART0_DISABLE_TRANSMISSION;
/* Configure BDH and BDL */
UART0_BDH = 0x00; // Keep default value for now
UART0_BDL = 0x04; // Keep default value for now
/* Configure C1 register */
UART0_C1 = 0x00; // 8-bit Mode ; No parity
/* Configure C2 register */
UART0_C2 = 0x00; // Disable all interrupts for now
/* Clear all flags */
// UART0_S1 = 0x1F; // w1c
UART0_S2 = 0x00;
/* Configure C3 register */
UART0_C3 = 0x00; // Keep default configuration
/* Configure C4 register */
UART0_C4 = 0x0F; // Disable Match Address ; OSR=16 (default)
/* Configure C5 register */
UART0_C5 = 0x00; // BOTHEDGE=0 as OSR=16 (BOTHEDGE must be set when 0SR is between 4 and 7
/* Enables the interrupts corresponding to UART_0 driver */
NVIC_EnableIRQ(UART0_IRQn);
NVIC_SetPriority(UART0_IRQn, UART0_INTERRUPT_PRIORITY);
NVIC_ClearPendingIRQ(UART0_IRQn);
// Init RX interrupts
// UART0_C3 |= UART0_C3_ORIE_MASK; // Implement later if useful
UART0_C2 |= UART0_C2_RIE_MASK;
/* Variable used in Rx ISR */
UART0_RxBufferFull = 0;
/* Read Rx buffer to clear the flags */
dummy = UART0_D;
}
Regards,
Bruno Silva