AnsweredAssumed Answered

Output to UART1 KL25Z

Question asked by gbd on Jun 27, 2013
Latest reply on Jan 23, 2014 by Gordon Jess

Hello everyone,

 

I'm trying to figure out how to get output from UART1 on my KL25Z. I'm using a bare metal platform and not CW. I've got a uart1_init() to configure the registers and everything looks to be correct but I'm not getting any output. This exact same init script will allow me to move uart0 around to the different uart0 pin locations. Any help you'd be willing to provide would be greatly appreciated

 

void uart1_init(int baud_rate)

{

    SIM_SCGC5 |= SIM_SCGC5_PORTC_MASK;

 

    // Turn on clock to UART1 module and select 48Mhz clock (FLL/PLL source)

    SIM_SCGC4 |= SIM_SCGC4_UART1_MASK;

    SIM_SOPT5 &= ~SIM_SOPT5_UART1TXSRC_MASK;

    SIM_SOPT5 |= SIM_SOPT5_UART1TXSRC(0);                 // FLL/PLL source

 

    // Select "Alt 3" usage to enable UART1 on pins

    PORTC_PCR3 = PORT_PCR_MUX(3);

    PORTC_PCR4 = PORT_PCR_MUX(3);

 

    UART1_C2 = 0;

    UART1_C1 = 0;

    UART1_C3 = 0;

    UART1_C4 = 0;

    UART1_S2 = 0;

 

    // Set the baud rate divisor

    #define OVER_SAMPLE 16

    uint16_t divisor = (CORE_CLOCK / OVER_SAMPLE) / baud_rate;

    UART1_C4 = UARTLP_C4_OSR(OVER_SAMPLE - 1);

    UART1_BDH = (divisor >> 8) & UARTLP_BDH_SBR_MASK;

    UART1_BDL = (divisor & UARTLP_BDL_SBR_MASK);

 

    // Initialize transmit and receive circular buffers

    buf_reset(tx_buffer1, BUFLEN);

    buf_reset(rx_buffer1, BUFLEN);

 

    // Enable the transmitter, receiver, and receive interrupts

    UART1_C2 = UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK;

    printf("UART1_C4 = %x \r\n", UART1_C4);

    printf("UART1_C2 = %x \r\n", UART1_C2);

    enable_irq(INT_UART1);

}

 

int uart1_write_err(char *p, int len)

{

    int i;

 

 

    __disable_irq();

    for(i=0; i<len; i++) {

        while((UART1_S1 & UART_S1_TDRE_MASK) == 0)  // Wait until transmit buffer empty

            ;

 

 

        UART1_D = *p++;                     // Send char

    }

    __enable_irq();

    return len;

}

 

 

Outcomes