Altering an RTC library.

I’m working on altering the DS1307 RTC library for use with the MCP795XX.

The MCP795 has the first register set to hundredths of seconds and I won’t be using those so I adjusted the write and send pointers to the second register.

I’m a little confused about some of the other hex calls. I’m not sure if they need to be changed based on the different chip, or if they are machine code interrupts, as some of them seem to be. Just starting to work on the research the codes, my biggest one is…

#include <Wire.h>
#include "DS1307RTC.h"

#define DS1307_CTRL_ID 0x68

Just wanted to know if anyone knows what the 0x68 is in reference as neither the ds1307 or mcp795XX have anywhere close to that many registers.

Library: DS1307RTC Library, For Accessing Real Time Clock (RTC) Chips

MCP datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/22300A.pdf

0x68 is the I2C slave address of the device.

You need to carefully study the functions of both devices and all the respective register locations, in order to make the appropriate changes in the software.

Microchip published a document explaining how to "migrate" code for the DS1307 to the MCP7940x series of RTC, which may be helpful. It is available here: http://ww1.microchip.com/downloads/en/DeviceDoc/20002337B.pdf

Wow, thanks for the quick replies.

AWOL:
0x68 is the I2C slave address of the device.

Okay, I’ve not looked into any I2C stuff, yet. I’ll have to look into that, I just got done with figuring out the modbus aspects of the project and was hoping to avoid having another machine interface to code around.

jremington:
You need to carefully study the functions of both devices and all the respective register locations, in order to make the appropriate changes in the software.

Microchip published a document explaining how to “migrate” code for the DS1307 to the MCP7940x series of RTC, which may be helpful. It is available here: http://ww1.microchip.com/downloads/en/DeviceDoc/20002337B.pdf

GREAT! Yeah, I spent about two hours pouring over the datasheets to make sure which functions I was dealing with, for now I just want to get the time functions to work and they are the same but the MCP has the 0 register for hundredths of second instead of seconds, but the rest are in the right order. So I just needed to move the pointer one higher.

Thanks looks like I’ve got more reading to do!

The MCP795X is an SPI device whereas the DS1307 is I2C. If I were tackling this, I think I'd start by looking for a library for the DS3234 RTC which is also SPI. I expect it would be easier to change only the registers rather than also have to rewrite the entire protocol as well.

Pete

el_supremo: The MCP795X is an SPI device whereas the DS1307 is I2C. If I were tackling this, I think I'd start by looking for a library for the DS3234 RTC which is also SPI. I expect it would be easier to change only the registers rather than also have to rewrite the entire protocol as well.

Pete

That's not a bad idea, I didn't even notice the SPI and I2C difference. Same plan(alter working code) but a different starting code, yeah, I'll have to see about that finding an SPI RTC library. Thanks for pointing that out, I probably would have spent way to long trying to figure that out.

If you are willing to stick to 794xx series which is I2C, you can use an existing library: https://github.com/JChristensen/MCP79412RTC

I have used it and it works very well - alarms, sram access and whatnot.

aeternus

Good find aeternus!

Unfortunately, the reason we're using the MCP79511 is for the unique ID address MAC address.

Luckily, I found someone who made a library for the DS1394 which has the same pin and register setup. I'm waiting for a response from them to get the actual library.

CraigF: Good find aeternus!

Unfortunately, the reason we're using the MCP79511 is for the unique ID address MAC address.

MCP79411 has a 48-bit MAC address; MCP79412 has a 64-bit MAC address. The library mentioned above works with both and has a function to read the MAC address. I've also used 24AA02E48 for MAC addresses, very inexpensive.

(Thanks, @aeternus :))