cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L152 LSE

costi
Associate III

Hi,

I want to use STME32L152 with LSE for RTC.

I set the bit LSEON in the register RCC_CSR but the bit remains always 0. I proceeded the same with LSION and it is working well.

I disable also the bit LSECSS and behavior is the same.

The LSE oscilator didn't start.

There is another condition to starting LSE?

Thank you

Constantin

1 ACCEPTED SOLUTION

Accepted Solutions
costi
Associate III

Problem solved.

I have followed the sequence below to start LSE:

.....

1.

GPIOA

For STM32L152 the MCO pin is on the PA8 and this pin has to be set as AF mode.

At this pin it can be shown the desired internal frequency.

An oscilloscope can be use to see the signal.

2.

RCC_CFGR.register

I am taking out the LSE waveform at the microcontroller pin MCO setting the register RCC_CFGR.

MCOPRE = 0 (000: MCO is divided by 1)

MCOSEL = 7 (111: LSE oscillator clock selected)

3.

RCC_APB1ENR register

Set bit PWREN

4.

PWR_CR register

Set bit DBP to have access at RTC

5.

RCC_CSR register

Set bits:

RTCSEL = 01 (01: LSE oscillator clock used as RTC/LCD clock)

LSEON = 1 (1: LSE oscillator ON)

LSECSSON = 0 (0: CSS on LSE (32 kHz oscillator) OFF)

Wait until   LSERDY == 1 (1: External 32 kHz oscillator ready)

View solution in original post

4 REPLIES 4
WPuch
Associate II

maybe it will help you how i do it.

#define FLUSH asm("dsb"); //not sure it's needed on L0

if((RCC_CSR&0x30000)!=0x10000) { //check if RTC is NOT running on external oscillator

 RCC_CSR|=0x80000; FLUSH; //resets RTC clock, allows to change oscillator settings

 initrtc=1; //flag to be used later that RTC clock has to be initialized

 }

RCC_CSR=0x00050900; FLUSH; //RTC enabled, LSE, medium low drive strength

...

may be other initializations here as clock doesn't start instantly, so it will wait less after

if(initrtc) {

//here put some default date and time, possibly set up other

//settings on RTC.

//of course make sure to check RTC_ISR status to make sure

//you won't write data before RTC accept it.

//i think you already know how to do

}

0690X00000AA0reQAD.png

Note that PWR needs to have enabled clock in RCC previously.

JW

costi
Associate III

thank you for the answers

I tried your advices

LSEON is still kept to 0. (also LSERDY)

I set the bit BDE from PWR_CR register, set LSEON.

The quartz doesn't work(physically) and for this reason LSERDY is kept to 0 logic.

costi
Associate III

Problem solved.

I have followed the sequence below to start LSE:

.....

1.

GPIOA

For STM32L152 the MCO pin is on the PA8 and this pin has to be set as AF mode.

At this pin it can be shown the desired internal frequency.

An oscilloscope can be use to see the signal.

2.

RCC_CFGR.register

I am taking out the LSE waveform at the microcontroller pin MCO setting the register RCC_CFGR.

MCOPRE = 0 (000: MCO is divided by 1)

MCOSEL = 7 (111: LSE oscillator clock selected)

3.

RCC_APB1ENR register

Set bit PWREN

4.

PWR_CR register

Set bit DBP to have access at RTC

5.

RCC_CSR register

Set bits:

RTCSEL = 01 (01: LSE oscillator clock used as RTC/LCD clock)

LSEON = 1 (1: LSE oscillator ON)

LSECSSON = 0 (0: CSS on LSE (32 kHz oscillator) OFF)

Wait until   LSERDY == 1 (1: External 32 kHz oscillator ready)