Cortex M0+ controller interfacing with external RTC module

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Cortex M0+ controller interfacing with external RTC module

1,081 Views
priyagarg
Contributor II

Hello to all,

I start working with Freescale cortex M0+ controller (MKL16Z256VLH4) with IDE: Keil uvision V5 & programmer: ulink2. And I am using I2C enabled DS3231 RTC module. I need to interface this RTC with the mentioned controller and get (and set) the current time and data & display them on the touchscreen. I really do not know how to start with this. If anyone has worked over this and if they have any resources to share, would be really great for me to start with this. If anyone can point me in the right direction to start with this, it will be very helpful for me. 

I tried to search on this forum regarding my concern but not able to get started with this. and if any more things are needed from my side to convey my thoughts, please let me know. 

Please help!

With Regards,

Priya

6 Replies

838 Views
mjbcswitzerland
Specialist V

Hi Prija

See the following documents - there is complete time management (including I2C connected Dallas chips) in the open source uTasker project for all Kinetis parts.
It also allows you to do complete chips simulation (also of I2C and external Dallas parts) using Visual Studio.

RTC and time keeping: http://www.utasker.com/docs/uTasker/uTasker_Time.pdf
I2C: http://www.utasker.com/docs/uTasker/uTasker_I2C.pdf

Regards

Mark


Kinetis: http://www.utasker.com/kinetis.html
Kinetis KL25, KL26, KL27, KL28 (some examples of Cortex m0+ processor parts):
- http://http://www.utasker.com/kinetis/FRDM-KL25Z.html
- http://www.utasker.com/kinetis/TWR-KL25Z48M.html
- http://www.utasker.com/kinetis/FRDM-KL26Z.html
- http://www.utasker.com/kinetis/TEENSY_LC.html
- http://www.utasker.com/kinetis/FRDM-KL27Z.html
- http://www.utasker.com/kinetis/Capuccino-KL27.html
- http://www.utasker.com/kinetis/FRDM-KL28Z.html

Free Open Source solution: https://github.com/uTasker/uTasker-Kinetis
Working project in 15 minutes video: https://youtu.be/K8ScSgpgQ6M

For better, faster, cheaper product developments consider the uTasker developer's version, professional Kinetis support, one-on-one training and complete fast-track project solutions to set you apart from the herd : http://www.utasker.com/support.html

838 Views
priyagarg
Contributor II

Hi Mark,

Apologies for responding you late. I have gone through the document and found that it can be possible to implement RTC with utasker framework. I am still going through the document and I am in dilemma for the controller used. A very basic and maybe silly question: From what I have read, in the config.h file, there is a definition for FRDM and tower boards. How can I use it for my controller (MKL16Z256VLH4). Should I uncomment FRDM-46Z board to use this controller? 

I might be asking a silly question. I am still learning. Please help :smileyhappy:

0 Kudos

838 Views
mjbcswitzerland
Specialist V

Hi Priya

Your KL16 is effectively a KL26 without USB interface so you could base your configuration on the FRDM-KL26Z board (which is what NXP advises for KL16 developments). Since your chip has 256k Flash and 32k SRAM you will need to adjust this in the memory setup (see app_hw_kinetis.h)

#elif defined FRDM_KL26Z                                                 // {24}
  //#define PIN_COUNT           PIN_COUNT_32_PIN
  //#define PIN_COUNT           PIN_COUNT_48_PIN
    #define PIN_COUNT           PIN_COUNT_64_PIN                         // 64 pin package
  //#define PIN_COUNT           PIN_COUNT_100_PIN
  //#define PIN_COUNT           PIN_COUNT_121_PIN
    #define PACKAGE_TYPE        PACKAGE_LQFP                             // LQFP
  //#define PACKAGE_TYPE        PACKAGE_QFN
  //#define PACKAGE_TYPE        PACKAGE_BGA
  //#define SIZE_OF_FLASH       (32 * 1024)                              // 32k program Flash
  //#define SIZE_OF_FLASH       (64 * 1024)                              // 64k program Flash
    #define SIZE_OF_FLASH       (128 * 1024)                             // 128k program Flash
  //#define SIZE_OF_FLASH       (256 * 1024)                             // 256k program Flash
  //#define SIZE_OF_RAM         (4 * 1024)                               // 4k SRAM
  //#define SIZE_OF_RAM         (8 * 1024)                               // 8k SRAM
    #define SIZE_OF_RAM         (16 * 1024)                              // 16k SRAM
  //#define SIZE_OF_RAM         (32 * 1024)                              // 32k SRAM

where you can modify these to match your exact chip.

There is also a target called the "rcARM_KL26" which uses a 256k KL26 and thus already matches with respect to memory.

Just be sure to disable USB_INTERFACE in config.h to avoid the code trying to use USB.

Finally check the clock circuitry that you board has and whether the configuration is correct (again in the target section of app_hw_kinetis.h). The FRDM-KL26Z has an 8MHz crystal and the rcARM_KL26 has an external 10MHz oscillator so you may need to adjust if your HW has a different source.

Good luck

Regards

Mark

838 Views
priyagarg
Contributor II

Hi Mark,

I followed your instructions and did everything according to visual studio simulator project files. When I run the simulator, I can see the LED blinking on PortE_bit31 of FRDM-KL26Z with 256K flash and 32K RAM with USB-interface disable. 

So, I tried to implement same on my hardware, I opened the Keil project source code and I changed everything accordingly but when downloading the project file, not able to see the led blinking. I tried to change the LED pin but still clueless. Everything is working on simulator but not on hardware. 

Really thank you for all your help. 

With Regards,

Priya

0 Kudos

838 Views
mjbcswitzerland
Specialist V

Priya

Make sure that you have chosen the correct processor in the Keil setup (at least a Cortex-m0+ and not an M4, for example). Then ensure that you use the correct linker script file KL_256_32.sct. [Any mismatch here will generally cause immediate failure].{I have attached this file in case it is missing in your version}

In case you still have problems, set the define BLINKY in config.h which will cause a minimum configuration to be built that just checks that the OS and TICK interrupt operate to flash an LED. This will remove possible additional code that may be enabled that is not compatible with the device.

Finally, if this still doesn't help or there is a problem when additional features are enabled do the following:

- disable the watchdog with

#define WATCHDOG_DISABLE()      (1)

- build and load the code and let it run

- pause the debugger and view in disassemble mode

- step the code in disassemble mode to see what it is doing. In case of a problem due to accessing illegal resources (98% of problem cases) you will find it stepping in and out of the hard fault handler. Look at the register value that it is accessing to cause the fault (it is usually in peripheral space 0x40000000...) and see which peripheral block this is (search kinetis.h). Then disable any code that is accessing this peripheral.

Good luck

Regards

Mark

0 Kudos

838 Views
priyagarg
Contributor II

Hi Mark,

Thank you so much for your positive response. I'll go through these documents and will get back to you soon with my collective inputs. 

0 Kudos