AnsweredAssumed Answered

UART interrupt

Question asked by Mridul Pandey on May 18, 2015
Latest reply on Sep 16, 2015 by Alberto Lubeiro

I am working on kl26z frdm board anf want to receive UART data on interrupt. I have written the following initialization code and ISR code but its not running succesfully. Please help me with a solution.

 

void uart_init (UART_MemMapPtr uartch, int sysclk, int baud)

{

    register uint16 sbr;

    uint8 temp;

 

      if (uartch == UART1_BASE_PTR)

        SIM_SCGC4 |= SIM_SCGC4_UART1_MASK;

      else

    SIM_SCGC4 |= SIM_SCGC4_UART2_MASK;

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

       * change settings.

       */

      UART_C2_REG(uartch) &= ~(UART_C2_TE_MASK

  | UART_C2_RE_MASK );

 

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

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

  

      /* Calculate baud settings */

      sbr = (uint16)((sysclk*1000)/(baud * 16));

      

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

      temp = UART_BDH_REG(uartch) & ~(UART_BDH_SBR(0x1F));

  

      UART_BDH_REG(uartch) = temp |  UART_BDH_SBR(((sbr & 0x1F00) >> 8));

      UART_BDL_REG(uartch) = (uint8)(sbr & UART_BDL_SBR_MASK);

 

UART_C2_REG(uartch) |= UART_C2_RIE_MASK; //newly added

enable_irq(12);

EnableInterrupts;

  

      /* Enable receiver and transmitter */

      UART_C2_REG(uartch) |= (UART_C2_TE_MASK

       | UART_C2_RE_MASK );

 

 

 

}

 

 

void UART1_IRQHandler(void)

{

k=0;

  do{

  if( uart_getchar_present (UART1_BASE_PTR))

  {string_c[k]=UART_D_REG(UART1_BASE_PTR);k++;}

  else{  }

  }while(!((strstr(string_c, "OK\r\n"))

  ||(strstr(string_c, "ERROR\r\n"))

          ||(strstr(string_c, "ERROR:"))

  ));

printf("string_c -> %s",string_c) ;

}

 

 

 

Please help to get this issue resolve soon.

My UART1 is working but its not working on interrupt subroutine when it receive a character.

Outcomes