3

I am looking to implement a Microchip MCP7940 real time clock into my sensor data logging circuit that I have based on the Uno. Would the most logical solution be to attempt at changing an existing library to work with this clock (ie RTClib), or to begin from scratch and do the configuration directly in my program?

  • Have you compared the MCP7940 to another RTC chip for which a working library exists? You'll need the datasheets. The more alike they are, the easier it will be to modify one's library for the other. At the higher levels - the interface functions - there shouldn't be too much difference; you'll need methods to set the clock, read the clock, and maybe 'hack' the clock (start it running in sync with some reference signal after you've pre-set the time). But the devil, as they say, is in the details. If the chips differ much, one library won't help much with the the low-level details of the other. – JRobert Jul 3 '14 at 21:12
  • Looking at the datasheet, it is very very similar to the DS1307. I wouldn't be surprised if the DS1307 library would work for the MCP7940 without modifications. So definitely use an existing library as a starting point. – Gerben Jul 4 '14 at 13:24
  • @JRobert The pinouts of the DS1307 and MCP7940 are identical. The major difference between the two is that the MCP7940 has an alarm output (which is the reason I'm using it over the DS1307). I'd assumed it would be fairly simple to modify a library to work with it. Now it just becomes a question of how long that will take with my limited programming knowledge/experience. – craigkoiter Jul 4 '14 at 16:29
  • Then you're far better off starting with a working library. You'd always have a known-good state to revert to when you need to. That beats the heck out of every line of code being experimental! You don't say much about your programming experience, but if the library is moderately well documented, you should at least be able to identify what part of the library needs modifying and what needs to happen there. Then, if you need it, it would be relatively easy for someone to guide you from there to working code. – JRobert Jul 4 '14 at 17:35
  • @JRobert My programming experience is assembly on PIC controllers, and directly with the Arduino. I know enough about programming to know that the libraries are constructed using something more in depth than what is being used in the IDE. – craigkoiter Jul 4 '14 at 19:59
1

In case anyone comes looking for an answer to this question, here is my solution:

I started with the excellent library by jeelabs (link: https://github.com/jcw/rtclib)

To create my new library, I changed a few of the register addresses, and added the few functions that I wanted it to do (set alarm, create an ordinal date, manually adjust the time with user input)

I posted my code to a Git project: https://github.com/crako1t/MCP7940-library-for-logger.git

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.