Clocking from RTC oscillator on K20

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Clocking from RTC oscillator on K20

1,546 次查看
daveytaylor
Contributor II

Hey,

I am looking to clock a K20(DX32VFM5) from an external 32.768kHz crystal connected to the EXTAL32/XTAL32 pins.

As I've not done this before it's been some trial and error and trying others code - but I've hit a wall.

My problems at this point boils down to crashing/stopping when attempting to access the RTC_CR register.

After enabling the RTC clock gate (SIM_SCGC6 |= (uint32_t)0x20000000UL;) I try to set RTC_CR OSCE but the processor seems never to move beyond this line.

Even reading the RTC_CR register (temp = RTC_CR;) results in the same behaviour.

I have these processors running off internal and external crystals in various configurations without any problems - but this has me stumped.

Does anyone have any suggestions or a working example on how to clock the cpu from the RTC crystal (via FLL, 48MHz)?

Best,

Davey

5 回复数

855 次查看
perlam_i_au
Senior Contributor I

Just after enable RTC on the SIM_SCGC6 register, then you should ensure that SRTC is clear, please clear it your self in order to start configuration of this field with known state. Enable interrupts, then enable oscillator on the OSCE field of RTC_CR register.

After this you will have to wait the startup time of your crystal (check this on your crystal datasheet).

Then, when your crystal is runing on a stable frequency set the time compesnation, configure Timer seconds and alarm and finally enable the counter with TCE field on the RTC_SR register.


Have a nic day :P,
Perla

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

855 次查看
daveytaylor
Contributor II

Thank you very much for answering!

I will try this later today and get back to you - but essentially you are saying that there may be pending interrupts that need be cleared before enabling the peripheral, right? Hmm both TIIE and TIF are 1 on reset... which I had missed. Thanks!

*But* the problem I am having is that I cannot even *read* the CR register - which does not really make sense to me even under this condition - even doing { uint32_t volatile temp = *(uint32_t*)0x4003D010 } to completely bypass the HAL layer causes the issue.

Would there be an explanation for this?

0 项奖励

855 次查看
perlam_i_au
Senior Contributor I

Just as you mention is important to consider possible conditions that could generate unexpected behavior (like interrupts), also in order to make this easy, have you considered download the Kinetis 50MHz bare metal sample code? In this package you will find the RTC driver with initialization function that could make this easy or you could use it as example to follow as well.

Check on the path: C:\(your download path)\kinetis_50MHz_sc\k20d50m_sc_baremetal\src\drivers\rtc, specifically on the rtc_init funtion.

I suggest you to take a look on this, you will notice there are some masks defined on the (your microcontroller).h  file for set specific values on register fields instead of calculate or reassign values every time you need to change something, this can help you to make some changes easy and avoid typo errors when you set value for a register (this happens to me all the time :S)


Have a nic day :P,
Perla

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

855 次查看
daveytaylor
Contributor II

Perla,

I really appreciate you taking the time.

My problem was a hardware issue, namely VBAT not being connected to a power source.

I incorrectly believed the RTC peripheral would be powered by VDD if VBAT was not present.

For reference to future readers:

* VBAT is essential, it is the only way to power up the RTC peripheral to enable system clocking via the RTC oscillator.

* This code (minus the second last line) worked fine for me: Problem configuring K20 to use an external crystal...

Sadly there is no response in that post detailing the reason the code from PE as described by the original author does not work.

I get the exact same issue and simply removed the /* Check that the source of the FLL reference clock is the external reference clock. */ while loop.

Perhaps a knowledgeable answer to that post would be in place, as this was the only reference I could find that discusses RTC system clocking (even though the tread later discusses clocking via the OSC module external crystal).

Thanks again

Best,

Davey

855 次查看
perlam_i_au
Senior Contributor I

I'll keep looking for more information about this, at least I am happy to see that you have found this interesting information regard VBAT connection.

0 项奖励