2017-02-23 02:32 AM
Hello everyone,
I work on a clock project and have a problem with the LSE crystal. I first
made my program on a STM32F0Discovery and it worked properly. Then I made a PCB with a STM32F030R8T6 and tried to program it but the LSE didn't startoscillating. I looked on the forum to see if anyone had the same issues than me and I found some people that said that it's the capacitors that cause the problem. They say that you need a crystal whit two 6pF capacitors and not a crystal with two 12pF like I had. So I tried that and it didn�t work either. Can someone help me further?The crystal I'm using can be found
.The 12pF capacitor can be found
.The 6pF capacitor can be found
.For Init fonction is:
void init_RTC (void)
{
RTC_InitTypeDef RTC_InitStructure;
RTC_TimeTypeDef RTC_TimeStructure;
// Enable the PWR clock
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);
// Allow access to RTC
PWR_BackupAccessCmd(ENABLE);
// Reset RTC Domain
RCC_BackupResetCmd(ENABLE);
RCC_BackupResetCmd(DISABLE);
// Enable the LSE OSC
RCC_LSEConfig(RCC_LSE_ON);
// Wait until LSE is ready
while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{
//The program is hold in this loop
}
// Select the RTC Clock Source
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
// Enable the RTC Clock
RCC_RTCCLKCmd(ENABLE);
RTC_DeInit();
//Disable write protection
RTC_WriteProtectionCmd(DISABLE);
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_12;
RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
RTC_InitStructure.RTC_SynchPrediv = 0xFF;
RTC_Init(&RTC_InitStructure);
RTC_TimeStructure.RTC_H12 = RTC_H12_AM;
RTC_TimeStructure.RTC_Hours = 0;
RTC_TimeStructure.RTC_Minutes = 0;
RTC_TimeStructure.RTC_Seconds = 0x00;
if(RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure)== ERROR)
while (1)
{
};
// Wait for RTC APB registers synchronisation
RTC_WaitForSynchro();
}
Thank you for helping and have a nice day
Blanc Quentin
#stm32 #stm32f030 #rtc_waitforsynchro #lserdy #lse-rtc #lse #crystal #rtc #stm32f02017-03-07 04:25 PM
Some crystals in some designs simply take too long to start up. I don't know how long the 'library' code you posted waits for it, but you can simply put a breakpoint into the loop which waits for LSE to come up, and wait there 'manually' for a few seconds, observing the ready flag in the debugger.
As a last resort, you could also try to use the crystal from the 'known good' Disco board, or use a known-good crystal e.g. from a discarded clock.
Aren't the SMD crystals sometimes too sensitive on overheating during soldering? I have experience only with crystals in leaded packages.
JW
2017-03-07 07:56 PM
That looks to be a 12pF crystal, I'm pretty sure the BOM calls out the 6-7pF one, not the more common 9pF or 12pF ones, which historically have not functioned well with STM32 parts. ie not started at all, take a long time, or are simply off frequency.
This is the one you want
2017-03-08 12:38 AM
Now I don't know if this was a sheer luck but all crystals I tried with 12pF load worked at me. I was even able to observe them oscillating with the most common 1:10 scope probe (i.e. an extra 15pF or so); on the OUT pin only of course, the slightest extra load on IN pin killed the oscillations reliably, but they restored themselves after removing that load. I tried all this on a F4, which is said in AN2867 to have the smallest (fixed) gain of all STM32s. I used only leaded crystals, but of very varying source and quality (including salvaged from scrap clock as I mentioned above), and all worked.
This all said does not mean one should go for the 12pF crystals once the design calls for the 6pF ones - those from experiments above I measured run tens of ppm off their nominal frequency plus tolerance, btw. I am just encouraging experimentation.
I stress that I am waiting up to 10 seconds in my code for the crystal to come up (as the RTC is under battery, this happens only at battery change, so it's a bearable procedure), and have seen some crystals to take literally seconds to come up oscillating properly.
JW
2017-05-11 03:39 AM
[SOLVED]
Hello
Blanc Quentin,
As I mentioned in my earlier comment, I also had the same issue as you described. Everything worked correctly on discovery kit, but not on PCB. I tried changing the capacitor values, changling the drive level but nothing worked for me. Finally, I went through this
and it had all the answers I needed.So, here is a list of all the changes that I made in my design to solve the problem.
Insted of a cylindrical DIP package of 32.768 kHz crystal, I used
https://www.digikey.com/product-detail/en/EPSON/MC-306-32.768K-E3-ROHS/SER2417CT-ND/1532560
along with two 10pF capacitors in 1206 SMD package as load capacitors CL1 and CL2Made sure that Crystal is mounted very very close (less than 3mm) to the microcontroller as shown below
Ocillator circuit has to be surrounded by a Guard Ring on the top layer of PCB, and by an isolated Ground Plane on the bottom layer of PCB as shown in below figure. The Guard Ring should be connected to underlying Ground Plane by multiple VIAs from top layer to the bottom layer.
The Guard Ring and Ground Plane are to be connected only to the microcontroller ground and not to the rest of the circuit ground.
Keep rest of the high frequency GPIO tracks away (more than 10mm) from the Oscillator circuit
Keep the OSC32_IN and OSC32_OUT track of the same length and balanced
Do not insert any test points on the tracks of oscillator circuit
Have a Look at my final PCB layout of Oscillator Circuit
TOP SIDE LAYOUT
BOTTOM SIDE LAYOUT
After applying above mentioned changes to a newly designed PCB, the LSE crystal started oscillating without any difficulties at all.
So my suggestion to you is to redesign the PCB keeping above points in mind.
I hope this helps you.
2017-06-12 05:00 AM
Hi
Patel.Meet.002
,Do you know how long does it take to have the LSE ready on your new design ?
On my side I have to wait 2 sec on :RCC_GetFlagStatus(RCC_FLAG_LSERDY)...
2017-06-12 11:48 PM
Hi Ben Moulin,
After the new design, it takes less than 1 second. Slightly more time is taken when selecting LSE as a clock source for the first time, but after that, hardly 1 second for LSE to be ready in the subsequent runs.
Earlier it used to take as long as 1 minute for the LSE ready flag, and even after that, the clock timing was not accurate.
As far as I remember, the controller waits for 4000 perfect pulses from the crystal before making LSE = 1.
So, if the crystal frequency is 32.768 kHz, then it will require atleast 0.122 seconds provided that the oscillator was already working.
It also depends on factors like load capacitance, drive level etc.
However, I think the 2 second time taken by the LSE to be ready in your case is alright if you are not facing any issues during the operation.