Hello,
I would like to use the KL25 Freedom board and running the RTC.
But the clock sources for the RTC are RTC_CLKIN, or 32KHz crystal which need external component, or the LPO 1KHz signal.
Is there a way to get 1 second time base with the LPO? I don't know how to configure the RTC to manage this not 32KHz frequency.
Thank you for your help.
Antoine
Hi Antoine,
I met the same issue.
The clock source should be selected by OSC32KSEL(19-18 bits) of SIM_SOPT1 (page 194 of KL25 Sub-Family Reference Manual). But it doesn't work. For each set of multiplekser the RTC_CLKIN source is selected.
Let me know if someone has better observation.
Regards,
Marcin
my code compiled by mbed.org:
printf("\rSOPT1:0x%.8x:0x%.8x\r",SIM,SIM->SOPT1);
SIM->SOPT1 &= ~SIM_SOPT1_OSC32KSEL_MASK;
SIM->SOPT1 |= SIM_SOPT1_OSC32KSEL(3); //LPO 1kHz
printf("\rSOPT1:0x%.8x:0x%.8x\r",&(SIM->SOPT1),SIM->SOPT1);
printf("SIM_SOPT1_OSC32KSEL_MASK:0x%.8x\r",SIM_SOPT1_OSC32KSEL_MASK);
printf("SIM_SOPT1_OSC32KSEL(3):0x%.8x\r",SIM_SOPT1_OSC32KSEL(3));
printf("SIM_SOPT1_OSC32KSEL(2):0x%.8x\r",SIM_SOPT1_OSC32KSEL(2));
as work around I drived the RTC_CLKIN by external source or PWM.
I know this thread is a couple of months old, but I have found a way to get the RTC working properly without needing to swap crystals, etc. By default, there is no link between the internal 32K reference and the RTC clock input HOWEVER it is possible to route the internal 32K out to PTC3 and bring it back in on the RTC clock input on PTC1.
You can configure the required settings in Codewarrior/Processor Expert on the CPU component (in expert mode) as follows:
On the RTC, set the "Clock Source" to "ERCLK32K".
And don't forget to put a wire link between PTC1 and PTC3 :smileyhappy:
Low and behold, you have an internally-sourced 32K signal to run the RTC on the Freedom board without needing any external devices or needing to change any crystals.
Perfect. It works.
Thanks,
Marcin
On the RTC, set the "Clock Source" to "ERCLK32K".
And don't forget to put a wire link between PTC1 and PTC3
I've done everything that heliosfa said and still doesn't work. If I write RTC1_Init(UserDataPtrr, FALSE) the date restarts every time is reconnected to the USB, and if I write RTC1_Init(UserDataPtrr, TRUE) the date doesn't change.
Here is my workaround:
It required connection PTD1->PTC1
Example:
/*
* Clock Generator generates wave on PTD1,
* the frequency is set up by CLOCK_PERIOD constant,
* the wave is symmetric 50/50.
*/
void clockGenerator(void)
{
//0.000030517578125 = 1/32768
//#define CLOCK_PERIOD (1/(2^15))
#define CLOCK_PERIOD (0.000030517578125)
//#define CLOCK_PERIOD (0.01) <- 100Hz :smileyhappy:
PwmOut out(PTD1); /* PTD1 is the same address as LED1 */
out.period(CLOCK_PERIOD); // out requires a 2ms period
out.pulsewidth((CLOCK_PERIOD/2)); // out position determined by a pulsewidth between 1ms
}
So, I need the RTC component and a PWM_LDD, not?
When I add the PWM_LDD component, how should I configure it? I've some errors.
http://i.imgur.com/l0iJN47.png
And, once included the PWM_LDD I have to add a TimerUnit_LDD:
http://i.imgur.com/AjDql17.png
I assume that all of this is whether the steps taken by Graeme Bragg.
Marcin Marecki escribió:
Here is my workaround:
It required connection PTD1->PTC1
Example:
/*
* Clock Generator generates wave on PTD1,
* the frequency is set up by CLOCK_PERIOD constant,
* the wave is symmetric 50/50.
*/
void clockGenerator(void)
{
//0.000030517578125 = 1/32768
//#define CLOCK_PERIOD (1/(2^15))
#define CLOCK_PERIOD (0.000030517578125)
//#define CLOCK_PERIOD (0.01) <- 100Hz :smileyhappy:
PwmOut out(PTD1); /* PTD1 is the same address as LED1 */
out.period(CLOCK_PERIOD); // out requires a 2ms period
out.pulsewidth((CLOCK_PERIOD/2)); // out position determined by a pulsewidth between 1ms
}
But, How can I use that with Codewarrior?
I'm using MQXLite.
From CodeWarrior window: Component Library, add PWM_LDD component (logic driver).
It is named PWM1 (in my project).
I "Component Inspector" select "Expert" page.
Output pin: select from list PTC1,
Period: 10ms (for 100Hz generator)
Starting pulse width: 5ms,
Auto initialisation: yes.
It starts in my project. I checked it by frequency meter.
Let me know if you have some another questions and if it works in your project,
Marcin
Hi Graeme B.
I did as you said, but it doesn't run. The time shown doesn't change. I think that the reason could be inside the code:
...
...
...
LDD_TDeviceData *MyRTCPtr;;
LDD_RTC_TTime TimePtr;
LDD_TUserData *UserDataPtrr;
//bool SoftInit;
...
...
...
int main(void)
{
...
...
...
/* Write your code here */
//SoftInit=FALSE;
MyRTCPtr=RTC1_Init((LDD_TUserData *)NULL, FALSE); // MyRTCPtr=RTC1_Init(UserDataPtrr, FALSE);
byte secc;
byte minn;
byte horr;
for(;;) {
RTC1_GetTime(MyRTCPtr,&TimePtr);
secc=TimePtr.Second;
minn=TimePtr.Minute;
horr=TimePtr.Hour;
//Code for showing the Time (Printf, UART, LCD, etc)
...
...
...
//WAIT1_Waitms(100);
}
...
...
...
}
Is there something wrong?
Hi,
You can check the example driver for RTC configuration: FRDM-KL25Z Product Summary Page
Download the FRDM-KL25Z_QSP: FRDM-KL25Z Quick start package and check drivers folder.
Hope this helps.