Summary
In my article entitled “FreeRTOS FAT SL – Musing on my Implementation“, I lamented that I was supposed to implement a Real Time Clock so that the reads and writes of files could be timestamped, but didnt. I knew that the PSoC4200M Real Time Clock is actually really easy to use. But, I didn’t because I didn’t want to fix the command line interface that I was using. In this article I will show you how to implement a PSoC4200M Real Time Clock in FreeRTOS. Then in the next article Ill show you how to implement the FreeRTOS Command Line Interface to set the time and turn on the FreeRTOS FAT SL Clock Driver.
PSoC4200M Real Time Clock Schematic
The first thing to do is copy the FreeRTOS Template project. Then add the UART and RTC components to the project schematic from the PSoC Creator Component Catalog.
The PSoC4200M Real Time Clock will have the default settings for the component.
To make an accurate clock, I want to turn on the Watch Crystal Oscillator which drives the Watch Dog Timers. To do this, click on the “Clocks” tab of the Design Wide Resources. Then press edit clock.
Once you are on the clock editor page, turn on the WCO (by pressing the checkmark in the upper left hand corner). Then turn on the WDT Timer 0 in the Periodic Timer Mode. Set the divider to 32768 so that the RTC will get 1 interrupt per second. You also need to select the source of the RTC to be Timer 0.
Firmware
In the firmware I create a new task called “uartTask” which just starts the RTC, then prints out the time when the user presses ‘t’. Obviously I didnt set the clock, so it starts from 12:00:00. Ill fix that in the next post after I get the FreeRTOS Command Line Interpreter working.
void uartTask(void *arg) { (void)arg; UART_Start(); clearScreen(); UART_UartPutString("Start Real Time Clock Demo\n"); UART_SetCustomInterruptHandler(uartISR); uint32 timeBCD; char buff[32]; RTC_Start(); while(1) { ulTaskNotifyTake(pdTRUE,portMAX_DELAY); while(UART_SpiUartGetRxBufferSize()) // if there is data then read and process { char c; c= UART_UartGetChar(); switch(c) { case 't': timeBCD = RTC_GetTime(); sprintf(buff,"%d:%d:%d\n",(int)RTC_GetHours(timeBCD),(int)RTC_GetMinutes(timeBCD),(int)RTC_GetSecond(timeBCD)); UART_UartPutString(buff); break;
You can find this project called RTC-Example in the workspace PSoC-Filesystem on the IoT Expert GitHub site or git@github.com:iotexpert/PSoC-FileSystem.git
No comment yet, add your voice below!