AnsweredAssumed Answered

problem in getting UART loop back output for KL25Z128

Question asked by manvitha on May 15, 2013
Latest reply on May 16, 2013 by manvitha

Hi,

     I am beginner working on KL25Z128 freedom MCU. I have a problem in getting output for UART loop back code(with baud 115200,FLLCLk 48MHz, sampling 16), once I debug and run the code in code warrior it enters default interrupt handler function(in kinetics_sysint.c) _asm("bkpt"); and suspends.

can anyone help me on this please?

 

#define UART_MODE        INTERRUPT_MODE

int main (void)

{

  char ch;

  printf("\nRunning the UART project.\n");

 

  SIM_Init();

  PORT_Init();

  UART0_Init();

 

 

  while(1)

  {

#if UART_MODE == POLLING_MODE

    while(!(UART0_S1&UART_S1_RDRF_MASK));

    c = UART0_D;

    while(!(UART0_S1&UART_S1_TDRE_MASK) && !(UART0_S1&UART_S1_TC_MASK));

    UART0_D  = c;

#endif

  }

}

 

 

void SIM_Init(void)

{

  SIM_SOPT2 = SIM_SOPT2_UART0SRC(1);

  SIM_SOPT2 &= ~SIM_SOPT2_PLLFLLSEL_MASK;

  SIM_SCGC4 = SIM_SCGC4_UART0_MASK;

  SIM_SCGC5 = SIM_SCGC5_PORTA_MASK;

 

}

void PORT_Init(void)

{

   PORTA_PCR2 = PORT_PCR_ISF_MASK | PORT_PCR_MUX(0x2);

  PORTA_PCR1 = PORT_PCR_ISF_MASK | PORT_PCR_MUX(0x2);

}

void UART0_Init(void)

{

  UART0_C2 &= ~ (UART0_C2_TE_MASK | UART0_C2_RE_MASK);

#if UART_MODE == INTERRUPT_MODE

  enable_irq(12); 

  set_irq_priority(12, 3);

#endif

  UART0_BDH = 0x00;

  UART0_BDL = 0x1A;

  UART0_C4 = 0x0F;

  UART0_C1 = 0x00;

  UART0_C3 = 0x00;

  UART0_MA1 = 0x00;

  UART0_MA1 = 0x00;

  UART0_S1 |= 0x1F;

  UART0_S2 |= 0xC0;

#if UART_MODE == INTERRUPT_MODE

  UART0_C2 = UART0_C2_RIE_MASK;

#endif

  UART0_C2 |= UART0_C2_TE_MASK| UART0_C2_RE_MASK;

}

 

 

void uart0_isr(void)

{

#if UART_MODE == INTERRUPT_MODE

  if (UART0_S1&UART_S1_RDRF_MASK)

  {

    c = UART0_D;

    if ((UART0_S1&UART_S1_TDRE_MASK) || (UART0_S1&UART_S1_TC_MASK))

    {

    UART0_D  = c;

    }

  }

#endif

}

 

Outcomes