LPC55s69 32kHz Clock Mode USART

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC55s69 32kHz Clock Mode USART

907 Views
francisy
Contributor II

I am using 32kHz mode for usart. 

My procedure is 

POWER_EnablePD(kPDRUNCFG_PD_XTAL32K); /*!< Powered down the XTAL 32 kHz RTC oscillator */
POWER_DisablePD(kPDRUNCFG_PD_FRO32K); /*!< Powered the FRO 32 kHz RTC oscillator */
CLOCK_AttachClk(kFRO32K_to_OSC32K); /*!< Switch OSC32K to FRO32K */

/*!< Set up dividers */
CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */
/*!< Set up clock selectors - Attach clocks to the peripheries */
CLOCK_AttachClk(kOSC32K_to_MAIN_CLK); /*!< Switch MAIN_CLK to OSC32K */
/*< Set SystemCoreClock variable. */
SystemCoreClock = 32768U;

POWER_SetVoltageForFreq( 32768U ); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
CLOCK_SetFLASHAccessCyclesForFreq(32768U); /*!< Set FLASH wait states for core */

CLOCK_SetClkDiv( kCLOCK_DivFlexFrg0, 256U, false ); /*!< Set FRGCTRL0_DIV divider to value 256 */
CLOCK_AttachClk( kOSC32K_to_FLEXCOMM0 );

USART_Init( BOARD_COMMS_UART, &config, CLOCK_GetFlexCommClkFreq( 0U ) );

if(CLOCK_GetFlexCommClkFreq( 0U ) == 32768U){
BOARD_COMMS_UART->CFG |= USART_CFG_MODE32K(1);
BOARD_COMMS_UART->BRG = 0;
}

I send a 16 byte of 0x55 in order to measure the baudrate, it gives me 0.49ms per bit, so the baud rate is 2000, not 9600. 

I have also tested the CLKOUT which route to OSC32 clock, it gives me 32kHz correctly.

How can I set it to 9600 baud rate? Do I miss any steps to enable 32kHz clock mode for usart?

Do you have any example code?

Labels (2)
Tags (2)
0 Kudos
2 Replies

794 Views
francisy
Contributor II

Thanks xiangjun.rong
But what I need is 9600 baud rate when using 32kHz clock.

It should be achieved by setting

USART->CFG |= USART_CFG_MODE32K(1);

I have found my mistake. 

I should disable USART before I change the MODE32K bit in CFG.

Like the below.

void Uart32kClkModeConfig( USART_Type * base)
{
   base->CFG &= ~USART_CFG_ENABLE_MASK;
   base->CFG |= USART_CFG_MODE32K( 1 );
   base->BRG = 0;
   base->OSR = 0;
   base->CFG |= USART_CFG_ENABLE_MASK;
}

794 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Francis,

This is the fig of the uart clock:

pastedImage_1.png

I think it is correct that you get 2K baudrate.

You use OSC32K as the uart clock source.

Flexcomm Interface clock = (FRG input clock) / (1+(MULT / DIV))

For your case, the DIV=255, the MULT is zero, so the FlexComm0 clock is the 32K OSC.

This is baudrate formula:

baud rate = [FCLK / oversample rate] / BRG divide

For your case, the oversample rate is a fixed value 16, the BRG is 1(which you set up BRG as zero), so the uart baudrate is

32K/16/1=2K.

Hope it can help you

BR

XiangJun Rong

0 Kudos