cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L152

costi
Associate III

Hi,

Is there somebody who really used the RTC using external crystal (HSE) of 32.768KHz ?

I tried to use it but with no success.

Using the RTC with internal oscillator of 40KHz (HSI) the all it's OK.

I think that there is a problem with external crystal for this micro. It's possible?

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

10 REPLIES 10
pj_stm
Associate III

Use the scope and see if the oscillator is actually oscillating 🙂

Custom board? Or DISCO or EVAL board with 32.768 KHz LSE placed?

You mention HSE?​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
costi
Associate III

STM32L152_DISCO

I used the oscilloscope of course.

The oscillator doesn't work.

And I used 2 same boards.

pj_stm
Associate III

I think you mention LSE. HLE has to be 4MHz+.

Did you enable LSE in your code? By setting BDCR register or using the HAL function like this:

 RCC_OscInitStruct.LSEState = RCC_LSE_ON; 
 RCC_OscInitStruct.HSIState = RCC_HSI_ON;
 RCC_OscInitStruct.HSICalibrationValue = 16;
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
 RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12;
 RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 {
   _Error_Handler(__FILE__, __LINE__);
 }
 
iphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC; 
 PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
 {
   _Error_Handler(__FILE__, __LINE__);
 
 }

costi
Associate III

Sorry, I wanted to say LSE (32.768KHz) for RTC (external crystal)

Not HSE

pj_stm
Associate III

did you enable it in the software?

costi
Associate III

yes, of course, I enabled it

My interest is just for LSE and how can I start it.

I followed the reference manual. By the way, isn't there the register BDCR for this microcontroller (STM32L152).

LSEON = 1 (RCC_CSR)

LSECSSON = 0 (RCC_CSR)

DBP = 1 (PWR_CR)

pj_stm
Associate III

so check the capacitors.

costi
Associate III

I have 2 same boards. So I think that the capacitors are OK.

Moreover I replaced the capacitors on the one board.

I suspect the LSE microcontroller behavior. I found some examples on the net about RTC but all of them are using internal 40KHz oscillator(LSI). This is OK. I tried it and it's work fine. But with LSE no chance.