I try to connect PC with FRDM-KL25Z board via USB-UART adapter. Unfortunately when I configured UART1 using “Kinetis L Peripheral Quick Reference” and “Reference Manual” it didn’t work correctly… I can receives and transfers data but during the sending, all messages are badly received by FRDM-KL25Z and PC.
I tried to program whole configuration by myself but with no effect. Probably I have some easy mistake but I have no idea where… (maybe it's problem with baud?)
On PC I use PUTTY to connect with KL25Z and I’ m sure that it isn’t problem with USB-UART adapter because he worked great when I communicated with my beaglebone black.
Maybe anybody have had the same problem and know what should I improve?
Below UART1 settings and program code.
- baud: 2400
- 8-bit character length
- One stop bit
- Parity disabled
#include "derivative.h" /* include peripheral declarations */
#define CLOCK_UART1 (SIM_SCGC4 |= SIM_SCGC4_UART1_MASK)
#define CLOCKC (SIM_SCGC5 |= SIM_SCGC5_PORTC_MASK)
#define UART_TX (PORTC_PCR4 |= PORT_PCR_MUX(3))
#define UART_RX (PORTC_PCR3 |= PORT_PCR_MUX(3))
//transfer and receive disable
UART1_C2 &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK);
//BAUD: 2400 48 000 000/(16*2400) = 0b10011100010
UART1_BDH = UART_BDH_SBR(0x4);
UART1_BDL = UART_BDL_SBR(0xE2);
//transfer and receive enable
UART1_C2 |= (UART_C2_TE_MASK | UART_C2_RE_MASK);
if(UART1_S1 & UART_S1_RDRF_MASK)
data = UART1_D;
while(!(UART1_S1 & UART_S1_TDRE_MASK) && !(UART1_S1 & UART_S1_TC_MASK))
UART1_D = data;