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
}
Solved! Go to Solution.
Hi, Mansi
I think your code is from KL25 demo code for LQRUG_uart_ex1. I tested it in our freedom board. It can work well. You can find in freedom.h, the baud rate is 19200. If you want to use in 115200 condition, you can change as below.
#define TERMINAL_BAUD 115200
If you want to change into loop mode, you need to set bit LOOPS in register UART0_C1. This is means UART0_C1 = 0x80;
I also tested on freedom board. It can work well. You can test again with our sample code.
The path is ....\Kinetis L Sample Code\kl25_sc_rev6\klxx-sc-baremetal\build\iar\LQRUG_uart_ex1.
Hope my reply can help you.
Best Regards
Paul
Hi, Mansi
I think your code is from KL25 demo code for LQRUG_uart_ex1. I tested it in our freedom board. It can work well. You can find in freedom.h, the baud rate is 19200. If you want to use in 115200 condition, you can change as below.
#define TERMINAL_BAUD 115200
If you want to change into loop mode, you need to set bit LOOPS in register UART0_C1. This is means UART0_C1 = 0x80;
I also tested on freedom board. It can work well. You can test again with our sample code.
The path is ....\Kinetis L Sample Code\kl25_sc_rev6\klxx-sc-baremetal\build\iar\LQRUG_uart_ex1.
Hope my reply can help you.
Best Regards
Paul
Hi Paul,
Thank you for your help. I missed to go through the baud in freedom.h. hope now it will work fine.
regards
Mansi