AnsweredAssumed Answered

UART0 interrupt problem

Question asked by Mridul Pandey on Apr 30, 2015
Latest reply on May 4, 2015 by Mridul Pandey

Hi all,
I was trying to program on KL02 microcontroller in keil-mdk using baremetal examples. I am finding trouble in using UART0 interrupt routines. I have written the following code for the initialization of UART interrupt as my UART buffer receives a character. Where am i going wrong?

 

 

 

 

void uart0_init (UART0_MemMapPtr uartch, int uart0clk, int baud)

{

    register uint16 sbr;

    uint8 temp;

   

    SIM_SCGC4 |= SIM_SCGC4_UART0_MASK;

   

    /* Make sure that the transmitter and receiver are disabled while we

     * change settings.

     */

    UART0_C2_REG(uartch) &= ~(UART0_C2_TE_MASK

  | UART0_C2_RE_MASK );

 

  UART0_C2_REG(uartch)  |= 0x20; // enabled Receiver Interrupt Enable for RDRF

 

      /* Configure the uart for 8-bit mode, no parity */

    UART0_C1_REG(uartch) = 0; /* We need all default settings, so entire register is cleared */

   

 

 

      /* Calculate baud settings */

    temp = UART0_C4;

    temp = (temp & UART0_C4_OSR_MASK) + 1;

    sbr = (uint16)((uart0clk)/(baud * (temp)));

   

       

    /* Save off the current value of the uartx_BDH except for the SBR field */

    temp = UART0_BDH_REG(uartch) & ~(UART0_BDH_SBR(0x1F));

  

    UART0_BDH_REG(uartch) = temp |  UART0_BDH_SBR(((sbr & 0x1F00) >> 8));

    UART0_BDL_REG(uartch) = (uint8)(sbr & UART0_BDL_SBR_MASK);

 

 

    /* Enable receiver and transmitter */

    UART0_C2_REG(uartch) |= (UART0_C2_TE_MASK

               | UART0_C2_RE_MASK );

   

}

 

 

Please Help...

Outcomes