AnsweredAssumed Answered

LPUART0 FRDM K82F

Question asked by Grzegorz Mikitiuk on May 6, 2018
Latest reply on Jul 18, 2018 by Grzegorz Mikitiuk

Hello i've been trying to send some informations throught UART for some time but i can't get it to work, i'm probably missing something. The problem is that if i check with logic analyzer my TX line i can  clearly see that data is correct but in realterm or any other software connected through USB-TTL only what i get is null(00). 

 

Here is my simple code:

 

 

#include <stdio.h>
#include "board.h"
#include "peripherals.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "MK82F25615.h"


uint16_t sbr;

int main(void) {

/* Init board hardware. */
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
/* Init FSL debug console. */
BOARD_InitDebugConsole();
SIM -> CLKDIV1 &= ~SIM_CLKDIV1_OUTDIV1_MASK;
SIM -> CLKDIV1 &= ~SIM_CLKDIV1_OUTDIV2_MASK;

SIM -> SCGC5 |= SIM_SCGC5_PORTB_MASK;
SIM -> SCGC2 |= SIM_SCGC2_LPUART0_MASK;
SIM -> SOPT2 |= SIM_SOPT2_LPUARTSRC(0x01);

 

MCG -> C6 &= ~ MCG_C6_PLLS_MASK;
MCG -> C4 |= MCG_C4_DMX32_MASK;
MCG -> C4 |= MCG_C4_DRST_DRS(0);

PORTB-> PCR[16] = PORT_PCR_MUX(0x03);
PORTB-> PCR[17] = PORT_PCR_MUX(0x03);

 

LPUART0 -> CTRL &= ~LPUART_CTRL_TE_MASK;
LPUART0 -> CTRL &= ~LPUART_CTRL_RE_MASK;
LPUART0 -> BAUD |=LPUART_BAUD_OSR(15);

sbr = (23986176/(16*9600));
LPUART0 -> BAUD |= LPUART_BAUD_SBR(sbr);

LPUART0 -> CTRL &= ~LPUART_CTRL_M_MASK;
LPUART0 -> CTRL &= ~LPUART_CTRL_PE_MASK;
LPUART0 -> BAUD &= ~LPUART_BAUD_SBNS_MASK;

LPUART0 -> CTRL |= LPUART_CTRL_TE_MASK;
LPUART0 -> CTRL |= LPUART_CTRL_RE_MASK;

 

while(1)
{

LPUART0 -> CTRL |= LPUART_CTRL_TE_MASK;

LPUART0 -> DATA = 0x53;
while(!(LPUART0 -> STAT & LPUART_STAT_TC_MASK) );

LPUART0 -> CTRL &= ~LPUART_CTRL_TE_MASK;

}
return 0 ;
}

 

Any ideas? i'm suspecting baudrate but i have no idea what could be wrong in calculations.

Outcomes