Hello everyone!
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.
UART1 Settings:
- baud: 2400
- 8-bit character length
- One stop bit
- Parity disabled
Program Code:
#include "derivative.h" /* include peripheral declarations */
#include "stdio.h"
#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))
int main(void)
{
uint8_t data;
CLOCKC;
UART_RX;
UART_TX;
//clock init
CLOCKB;
CLOCK_UART1;
//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);
for(;;){
if(UART1_S1 & UART_S1_RDRF_MASK)
{
//receive data
data = UART1_D;
while(!(UART1_S1 & UART_S1_TDRE_MASK) && !(UART1_S1 & UART_S1_TC_MASK))
{}
//transfer data
UART1_D = data;
puts("sent!");
}
}
return 0;
}