We are working on external RTC MCP7940(i2c) interfaced with nrf52840. Please check if drivers of the same for nrf52/51 are available or any implementation of CLOCK using MCP7940 with NRF?
Regards
Vishal Aditya
Embedded Software Engineer
We are working on external RTC MCP7940(i2c) interfaced with nrf52840. Please check if drivers of the same for nrf52/51 are available or any implementation of CLOCK using MCP7940 with NRF?
Regards
Vishal Aditya
Embedded Software Engineer
HI Vishal,
I am afraid that we do not have any dedicated drivers from the MCP7940. I am also not aware of any customers that have used the MCP7940 as the 32kHz clock source for the nRF5x series, but Ithink it should be possible.
We have TWI hardware drivers in our nRF5 SDK for the nRF51 and 52 series, see Driver support matrix.
Best regards
Bjørn
bjorn-spockeli
I am writing drivers by myself & stuck in the first step of I2C DETECT not happening.
SDK: nRF5_SDK_15.2.0_9412b96\examples\peripheral\twi_scanner
MCP7940 Break-out: https://rheingoldheavy.com/product/breakout-board-mcp7940/ which works perfectly with Arduino at I2C Address: 0x6F
But I2C DETECT not working with nrf52840 DK. Please suggest how to debug this issue? We have an Oscilloscope!
Sampling for 5secs:
Please check the traces of MCP_Breakout with Arduino:
With Arduino, MCP Works properly able to do i2c, SET & GET DATETIME
Arduino Code:
#include <Wire.h> void setup() { Wire.begin(); Serial.begin(115200); while (!Serial); // Leonardo: wait for serial monitor Serial.println("\nI2C Scanner"); } void loop() { byte error, address; int nDevices; Serial.println("Scanning..."); nDevices = 0; //for(address = 1; address < 127; address++ ) while(1) { //SENDING 0x6F in decimal as per arduino Wire library Wire.beginTransmission(111); error = Wire.endTransmission(); if (error == 0) { Serial.print("I2C device found at address 0x"); if (address<16) Serial.print("0"); Serial.print(address,HEX); Serial.println(" !"); nDevices++; } else if (error==4) { Serial.print("Unknown error at address 0x"); if (address<16) Serial.print("0"); Serial.println(address,HEX); } } if (nDevices == 0) Serial.println("No I2C devices found\n"); else Serial.println("done\n"); //delay(5000); // wait 5 seconds for next scan }
Please reply for a possible way of the solution!
With the Arduino you are writting to a device with address 0x6F, not reading from it. So if you want to do exactly the same with the nRF52840, then you need to replace nrf_drv_twi_rx with nrf_drv_twi_tx.
Please check the traces after code updates:
twi_init(); // for (address = 1; address <= TWI_ADDRESSES; address++) // { while(1) { // nrf_gpio_pin_write(RED_LED,1); err_code = nrf_drv_twi_tx(&m_twi, 0x6F, &sample_data, sizeof(sample_data),1); if (err_code == NRF_SUCCESS) { detected_device = true; NRF_LOG_INFO("TWI device detected at address 0x%x.\r\n", address); //nrf_gpio_pin_write(RED_LED,0); } NRF_LOG_FLUSH(); } if (!detected_device) { NRF_LOG_INFO("No device was found.\r\n"); NRF_LOG_FLUSH(); }
All write transactions are now followed by an ACK, which means that the MCP7940 is responding correctly. You could now try to send the I2C transaction that returns the time from the MCP7940.
Hi,
I am trying to do init sequence but not able to START Clock Oscillator of MCP7940
void init_MCP7940() {
char registerValue = 0x00; // Holds the received register value
char twelveHour = 0x00; // 0 = 24 Hour Clock Mode / 1 = 12 Hour Clock Mode
char startClock = 0x01; // 0 = Start Oscillator / 1 = Stop Oscillator
// Turn on/off: 12 hour vs. 24 hour clock
err_code = nrf_drv_twi_tx(&m_twi,MCP7940_I2C, REG_RTCHOUR, 1);
err_code = nrf_drv_twi_rx(&m_twi, MCP7940_I2C, registerValue, sizeof(MCP7940_I2C));
if (twelveHour == 0x00) err_code = nrf_drv_twi_tx(&m_twi,MCP7940_I2C, REG_RTCHOUR, bitClear (registerValue, 6));
if (twelveHour == 0x01) err_code = nrf_drv_twi_tx(&m_twi,MCP7940_I2C, REG_RTCHOUR, bitSet (registerValue, 6));
// Turn on/off: Oscillator (starts the clock)
err_code = nrf_drv_twi_rx(&m_twi, MCP7940_I2C, registerValue, 1);
if (startClock == 0x00) err_code = nrf_drv_twi_tx(&m_twi,MCP7940_I2C, REG_RTCSEC, bitClear (registerValue, 7));
if (startClock == 0x01) err_code = nrf_drv_twi_tx(&m_twi,MCP7940_I2C, REG_RTCSEC, bitSet (registerValue, 7));
}
Hi,
I am trying to do init sequence but not able to START Clock Oscillator of MCP7940
void init_MCP7940() {
char registerValue = 0x00; // Holds the received register value
char twelveHour = 0x00; // 0 = 24 Hour Clock Mode / 1 = 12 Hour Clock Mode
char startClock = 0x01; // 0 = Start Oscillator / 1 = Stop Oscillator
// Turn on/off: 12 hour vs. 24 hour clock
err_code = nrf_drv_twi_tx(&m_twi,MCP7940_I2C, REG_RTCHOUR, 1);
err_code = nrf_drv_twi_rx(&m_twi, MCP7940_I2C, registerValue, sizeof(MCP7940_I2C));
if (twelveHour == 0x00) err_code = nrf_drv_twi_tx(&m_twi,MCP7940_I2C, REG_RTCHOUR, bitClear (registerValue, 6));
if (twelveHour == 0x01) err_code = nrf_drv_twi_tx(&m_twi,MCP7940_I2C, REG_RTCHOUR, bitSet (registerValue, 6));
// Turn on/off: Oscillator (starts the clock)
err_code = nrf_drv_twi_rx(&m_twi, MCP7940_I2C, registerValue, 1);
if (startClock == 0x00) err_code = nrf_drv_twi_tx(&m_twi,MCP7940_I2C, REG_RTCSEC, bitClear (registerValue, 7));
if (startClock == 0x01) err_code = nrf_drv_twi_tx(&m_twi,MCP7940_I2C, REG_RTCSEC, bitSet (registerValue, 7));
}
Please attach a logic trace of the I2C lines when you run the init_MCP7940() function.
pls guide or let me know further which transactions traces required will update it
Are you calling the init_MCP7940() function at all? You seem to be writting to the same register (0xDE) over and over again. Does 0xDE correspond with REG_RTCHOUR or REG_RTCSEC?
Yes calling init_MCP7940()
Below register maps:
const uint8_t MCP7940_I2C = 0xDE;
const uint8_t MCP7940_RTCSEC = 0x00; ///< Timekeeping, RTCSEC Register address
const uint8_t MCP7940_RTCMIN = 0x01; ///< Timekeeping, RTCMIN Register address
const uint8_t MCP7940_RTCHOUR = 0x02; ///< Timekeeping, RTCHOUR Register address
const uint8_t MCP7940_RTCWKDAY = 0x03; ///< Timekeeping, RTCWKDAY Register address
const uint8_t MCP7940_RTCDATE = 0x04; ///< Timekeeping, RTCDATE Register address
const uint8_t MCP7940_RTCMTH = 0x05; ///< Timekeeping, RTCMTH Register address
const uint8_t MCP7940_RTCYEAR = 0x06; ///< Timekeeping, RTCYEAR Register address
const uint8_t MCP7940_CONTROL = 0x07; ///< Timekeeping, RTCCONTROL Register address
const uint8_t MCP7940_OSCTRIM = 0x08; ///< Timekeeping, RTCOSCTRIM Register address
const uint8_t MCP7940_ALM0SEC = 0x0A; ///< Alarm 0, ALM0SEC Register address
const uint8_t MCP7940_ALM0MIN = 0x0B; ///< Alarm 0, ALM0MIN Register address
const uint8_t MCP7940_ALM0HOUR = 0x0C; ///< Alarm 0, ALM0HOUR Register address
const uint8_t MCP7940_ALM0WKDAY = 0x0D; ///< Alarm 0, ALM0WKDAY Register address
const uint8_t MCP7940_ALM0DATE = 0x0E; ///< Alarm 0, ALM0DATE Register address
const uint8_t MCP7940_ALM0MTH = 0x0F; ///< Alarm 0, ALM0MTH Register address
const uint8_t MCP7940_ALM1SEC = 0x11; ///< Alarm 1, ALM1SEC Register address
const uint8_t MCP7940_ALM1MIN = 0x12; ///< Alarm 1, ALM1MIN Register address
const uint8_t MCP7940_ALM1HOUR = 0x13; ///< Alarm 1, ALM1HOUR Register address
const uint8_t MCP7940_ALM1WKDAY = 0x14; ///< Alarm 1, ALM1WKDAY Register address
const uint8_t MCP7940_ALM1DATE = 0x15; ///< Alarm 1, ALM1DATE Register address
const uint8_t MCP7940_ALM1MTH = 0x16; ///< Alarm 1, ALM1MONTH Register address
const uint8_t MCP7940_PWRDNMIN = 0x18; ///< Power-Fail, PWRDNMIN Register address
const uint8_t MCP7940_PWRDNHOUR = 0x19; ///< Power-Fail, PWRDNHOUR Register address
const uint8_t MCP7940_PWRDNDATE = 0x1A; ///< Power-Fail, PWDNDATE Register address
const uint8_t MCP7940_PWRDNMTH = 0x1B; ///< Power-Fail, PWRDNMTH Register address
const uint8_t MCP7940_PWRUPMIN = 0x1C; ///< Power-Fail, PWRUPMIN Register address
const uint8_t MCP7940_PWRUPHOUR = 0x1D; ///< Power-Fail, PWRUPHOUR Register address
const uint8_t MCP7940_PWRUPDATE = 0x1E; ///< Power-Fail, PWRUPDATE Register address
const uint8_t MCP7940_PWRUPMTH = 0x1F; ///< Power-Fail, PWRUPMTH Register address
const uint8_t MCP7940_RAM_ADDRESS = 0x20; ///< NVRAM - Start address for SRAM
const uint8_t MCP7940_ST = 7; ///< MCP7940 register bits. RTCSEC reg
const uint8_t MCP7940_12_24 = 6; ///< RTCHOUR, PWRDNHOUR & PWRUPHOUR
const uint8_t MCP7940_AM_PM = 5; ///< RTCHOUR, PWRDNHOUR & PWRUPHOUR
const uint8_t MCP7940_OSCRUN = 5; ///< RTCWKDAY register
const uint8_t MCP7940_PWRFAIL = 4; ///< RTCWKDAY register
const uint8_t MCP7940_VBATEN = 3; ///< RTCWKDAY register
const uint8_t MCP7940_LPYR = 5; ///< RTCMTH register
const uint8_t MCP7940_OUT = 7; ///< CONTROL register
const uint8_t MCP7940_SQWEN = 6; ///< CONTROL register
const uint8_t MCP7940_ALM1EN = 5; ///< CONTROL register
const uint8_t MCP7940_ALM0EN = 4; ///< CONTROL register
const uint8_t MCP7940_EXTOSC = 3; ///< CONTROL register
const uint8_t MCP7940_CRSTRIM = 2; ///< CONTROL register
const uint8_t MCP7940_SQWFS1 = 1; ///< CONTROL register
const uint8_t MCP7940_SQWFS0 = 0; ///< CONTROL register
const uint8_t MCP7940_SIGN = 7; ///< OSCTRIM register
const uint8_t MCP7940_ALMPOL = 7; ///< ALM0WKDAY register
const uint8_t MCP7940_ALM0IF = 3; ///< ALM0WKDAY register
const uint8_t MCP7940_ALM1IF = 3; ///< ALM1WKDAY register
const uint32_t SECONDS_PER_DAY = 86400; ///< 60 secs * 60 mins * 24 hours
const uint32_t SECONDS_FROM_1970_TO_2000 = 946684800; ///< Seconds between year 1970 and 2000
Please let me know if any traces required at any line with break-point? Also, I can send the drivers again with a private link to your INBOX it is required?
The trace clearly show that its only the MCP7940_I2C address that is transmitted. The nrf_drv_twi_tx documentation states that the data passed to it should be a uint8_t pointer, so try passing it like this
uint8_t tx_data = REG_RTCHOUR;
err_code = nrf_drv_twi_tx(&m_twi,MCP7940_I2C,&tx_data , sizeof(tx_data));
APP_ERROR_CHECK(err_code)
Furthermore what does the bitClear (registerValue, 6) and bitSet (registerValue, 6) functions do? You are passing they're return value as the length parameter to nrf_drv_twi_tx and nrf_drv_twi_rx.
void init_MCP7940() {
char registerValue = 0x00; // Holds the received register value
char twelveHour = 0x00; // 0 = 24 Hour Clock Mode / 1 = 12 Hour Clock Mode
char startClock = 0x01; // 0 = Start Oscillator / 1 = Stop Oscillator
// Turn on/off: 12 hour vs. 24 hour clock
err_code = nrf_drv_twi_tx(&m_twi,MCP7940_I2C, REG_RTCHOUR, 1);
err_code = nrf_drv_twi_rx(&m_twi, MCP7940_I2C, registerValue, sizeof(MCP7940_I2C));
if (twelveHour == 0x00) err_code = nrf_drv_twi_tx(&m_twi,MCP7940_I2C, REG_RTCHOUR, bitClear (registerValue, 6));
if (twelveHour == 0x01) err_code = nrf_drv_twi_tx(&m_twi,MCP7940_I2C, REG_RTCHOUR, bitSet (registerValue, 6));
// Turn on/off: Oscillator (starts the clock)
err_code = nrf_drv_twi_rx(&m_twi, MCP7940_I2C, registerValue, 1);
if (startClock == 0x00) err_code = nrf_drv_twi_tx(&m_twi,MCP7940_I2C, REG_RTCSEC, bitClear (registerValue, 7));
if (startClock == 0x01) err_code = nrf_drv_twi_tx(&m_twi,MCP7940_I2C, REG_RTCSEC, bitSet (registerValue, 7));
}