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
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));
}
Custom defined which works as below:
https://www.arduino.cc/reference/en/language/functions/bits-and-bytes/bitclear/
https://www.arduino.cc/reference/en/language/functions/bits-and-bytes/bitset/
Will update the traces & API call as per this soon!
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)
Pls check the trace of REG_RTCHOUR,
const uint8_t MCP7940_RTCHOUR = 0x02; ///< Timekeeping, RTCHOUR Register address
Yes, now you are writing to register with address 0x02 of the device with address 0xDE, but you are not providing the value you want to write to register 0x02.
uint8_t tx_data[] = {REG_RTCHOUR, <value to write to REG_RTCHOUR register> }; err_code = nrf_drv_twi_tx(&m_twi,MCP7940_I2C,tx_data , sizeof(tx_data)); APP_ERROR_CHECK(err_code)
Pls check
const uint8_t MCP7940_ST = 7; ///< MCP7940 register bits. RTCSEC reg //REST variables remains same as above while(1) { uint8_t tx_data[] = {REG_RTCSEC, MCP7940_ST }; uint8_t rx_data[] = REG_RTCSEC; //trying to start oscillator err_code = nrf_drv_twi_tx(&m_twi,MCP7940_I2C,tx_data , sizeof(tx_data),false); APP_ERROR_CHECK(err_code); err_code = nrf_drv_twi_rx(&m_twi,MCP7940_I2C,rx_data,1); nrf_delay_ms(1); }