Hello everyone,
I have a Kinetis MK10DX128 VLH7 and Im trying to configure the UART0 module for a baud rate of 115200. I tryed several clock rates but my host receive only garbage. Every other baud rates until 115200 works fine. I tested it with two of my MCUs and they have the same problems. Here is my source code:
#include "derivative.h" /* include peripheral declarations */
#include "driver.h"
int main(void)
{
int n=0;
main_clock_init();
UART_init(115200,72000);
for(;;)
{
for(n=0;n<=100000;n++);
while(!(UART0_S1 & UART_S1_TDRE_MASK)){};
UART0_D = 'X';
}
return 0;
}
and the funktions in driver.c:
void main_clock_init() // Set clockrate to 72MHz
{
MCG_C4 |= MCG_C4_DMX32_MASK
| MCG_C4_DRST_DRS(2);
}
void UART_init(unsigned short baud,unsigned int uartclk_khz) // Initialise UART0
{
unsigned short sbr,brfa;
//Initialisation
SIM_SCGC4 |= SIM_SCGC4_UART0_MASK; // Activate clock for UART
SIM_SCGC5 |= SIM_SCGC5_PORTB_MASK; // Activate clock for PortC
PORTB_PCR16 = PORT_PCR_MUX(3); // Set PortB 16 for UARC
PORTB_PCR17 = PORT_PCR_MUX(3); // Set PortB 17 for UARC
sbr = (unsigned short)((uartclk_khz*1000)/(baud*16));
UART0_BDH = (unsigned char)((sbr & 0x1F00)>>8); // Write high word of baud rate into register
UART0_BDL = (unsigned char)(sbr & 0x00FF); // Write low word of baud rate into register
brfa = (((uartclk_khz*32000)/(baud*16))-(sbr*32));
UART0_C4 = (unsigned char)(brfa & 0x001F); // Write divider into register
UART0_C1 = 0; // 8-Bit-Mode,No parity
//UART0_BDH |= UART_BDH_RXEDGIE_MASK; // Enable interrupts from an edge on RxD
//enable_irq(45); // Enable interrupts from UART module
//NVICIP45 = 0x10; // Set Priority 1 to the UART module
UART0_C2 |= (UART_C2_TE_MASK | UART_C2_RE_MASK ); // Enable receiver and transmitter
while(!(UART0_S1 & UART_S1_TDRE_MASK)){};
UART0_D = 'a';
}
It would be nice when you can help me.
regards,
Eric