The RAK12002 WisBlock RTC module is a low cost extremely low power real time clock module based on the RV-3028-C7 from Micro Crystal. It only consumes 40 nA and also has 43 bytes of non-volatile user memory. Rather than a battery backup it has a small super capacitor that will operate the device for a week without power. The source code for the Arduino library that is used is here and was written for the Melopero RV-3028 breakout board. I have adapted that library to the Pico SDK and tested it with a RAK12002 installed on a RAK19001 base board and RAK11310 core module. My Git repository with the source code is here.
Other than changing the code from a C++ class to C functions the only real change is accessing the RV-3028-C7 via I2C. The Pico SDK has a very nice I2C library which is simpler than the Arduino code. Reading and writing I2C simply involve calls to i2c_write_blocking and i2c_read_blocking. In both cases the register address is first written then one or more sequential register values are read or written. In the case of writing to a register a single i2c_write_blocking call is used with a buffer containing the register address as the first byte followed by a set of one or more sequential register values. For setting the time an 8 byte buffer is written that contains the register address and the seven time and date values.
However when it comes to using the 43 bytes of EEPROM the Melopero library does not work as is. There are two problems. First, the RV-3028-C7 data sheet states that before any command is written to the EEPROM_COMMAND_ADDRESS, a value of 0 must first be written. This is missing. Secondly, it is important to wait until the EEPROM is not busy before issuing commands and again that is missing. The command to disable the automatic refresh to RAM is required before reading or writing a single byte to or from EEPROM. This is slightly different than the requirements for reading EEPROM configuration data, which is only refreshed at midnight. These problems are corrected in the code in my GitHub repository.
Note that the RV-3028 charges the supercapacitor on the RAK12002 RTC module with a trickle charge but by default this is not enabled. It is important to enable it by setting bit 5 of the EEPROM_BACKUP register (address 0x37). I do this in the rtc-board.c RtcInit() function
Leave a Reply
You must be logged in to post a comment.