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!
Please check still NAK
Yes, but you are reading back the value of the register, i.e. 0x07. Wasnt that what you wrote to the register previously? What is the return code of nrf_drv_twi_rx()? Is it NRF_ERROR_DRV_TWI_ERR_DNACK or NRF_ERROR_DRV_TWI_ERR_ANACK?
err_code = 0
Ok, if the nrf_drv_twi_rx call does not return a non-zero error code, then things are working as they should. Could you try to run the following code and see if the rx_data[0] is 0x80. If it is then the code is working as intended.
// Initizalize buffers uint8_t tx_data[] = {REG_RTCSEC, 0x80 }; // Set TX buffer - Write 0x80 ( Enable Osc) to REG_RTCSEC register uint8_t rx_data[] = {}; // Empty RX buffer // Write Tx data to MCP7940 err_code = nrf_drv_twi_tx(&m_twi,MCP7940_I2C,tx_data , sizeof(tx_data),false); APP_ERROR_CHECK(err_code); // Select REG_RTCSEC register and use repeated start (only send 1 byte of tx buffer) err_code = nrf_drv_twi_tx(&m_twi,MCP7940_I2C,tx_data , 1 ,true); APP_ERROR_CHECK(err_code); // Read REG_RTCSEC register err_code = nrf_drv_twi_rx(&m_twi,MCP7940_I2C,rx_data,1); APP_ERROR_CHECK(err_code);
Best regards
Bjørn
Yes getting 0x80
Below is the attached Arduino init sequence:
Wire.begin(); // Start I2C as master device Wire.setClock(i2cSpeed); // Set the I2C bus speed Wire.beginTransmission(MCP7940_ADDRESS); // Address the MCP7940M uint8_t errorCode = Wire.endTransmission(); // See if there's a device present if (errorCode == 0) // If we have a MCP7940M { clearRegisterBit(MCP7940_RTCHOUR, MCP7940_12_24); // Use 24 hour clock setRegisterBit(MCP7940_CONTROL, MCP7940_ALMPOL); // assert alarm low, default high _CrystalStatus = readRegisterBit(MCP7940_RTCSEC, MCP7940_ST); // Status bit from register _OscillatorStatus = readRegisterBit(MCP7940_RTCWKDAY, MCP7940_OSCRUN); // Oscillator state from register }MCP7940.h
Yes getting 0x80
Below is the attached Arduino init sequence:
Wire.begin(); // Start I2C as master device Wire.setClock(i2cSpeed); // Set the I2C bus speed Wire.beginTransmission(MCP7940_ADDRESS); // Address the MCP7940M uint8_t errorCode = Wire.endTransmission(); // See if there's a device present if (errorCode == 0) // If we have a MCP7940M { clearRegisterBit(MCP7940_RTCHOUR, MCP7940_12_24); // Use 24 hour clock setRegisterBit(MCP7940_CONTROL, MCP7940_ALMPOL); // assert alarm low, default high _CrystalStatus = readRegisterBit(MCP7940_RTCSEC, MCP7940_ST); // Status bit from register _OscillatorStatus = readRegisterBit(MCP7940_RTCWKDAY, MCP7940_OSCRUN); // Oscillator state from register }MCP7940.h
Great, then you are good to go. You should be able to reuse the snippet I provided to configure the MCP7940. My suggestion would be to capture a trace of the Arduino Init sequence to see which values that are written to which register and then just copy paste the code snippet I provided and change the REG_RTCSEC register value and the 0x80 to match what you're seeing in the trace.