Hello,
I've having difficulty getting my UART driver to work on the KL25Z
I followed this document from freescale: http://cache.freescale.com/files/32bit/doc/quick_ref_guide/KLQRUG.pdf
This doesn't seem to work.
My main method handles what would normally be in a "getchar" and "putchar" method.
I just want it to repeat what I send it.
My code is as follows:
This is the main.c file
#include "UART.h"
int main(void){
uart0_Init();
while(1){
while(!(UART0->D1 & UART_S1_RDRF_MASK));
c = UART0->D;
while(!(UART0->S1 & UART_S1_TDRE_MASK) && !(UART0->S1_TC_MASK));
UART0->D = c;
}
}
And this is the UART.h file:
#include <MKL25Z4.h>
#include <stdio.h>
#include "delay.h"
#define POLLING_MODE 1
#define UART_MODE POLLING_MODE
void uart0_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;
PORTA->PCR[2] = PORT_PCR_ISF_MASK | PORT_PCR_MUX(0x2);
PORTA->PCR[1] = PORT_PCR_ISF_MASK | PORT_PCR_MUX(0x2);
UART0->C2 &= ~(UART0_C2_TE_MASK | UART0_C2_RE_MASK);
UART0->BDH = 0x00;
UART0->PDL = 0x1A;
UART0->c4 = 0x0F;
UART0->C1 = 0x00;
UART0->C3 = 0x00;
UART0->MA1 = 0x00;
UART0->MA2 = 0x00;
UART0->S1 = 0x1F;
UART0->S2 = 0xC0;
UART0->C2 |= UART0_C2_TE_MASK | UART0_C2_RE_MASK;
}