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
If you want to start the oscillator, then you need to set bit 7 in REG_RTCSEC to 1, i.e. you need to write 0x80 not 0x07.
The read operation is Not Acknowledged so it could be that you have to select the register you want to read from before
// Read REG_RTCSEC register
uint8_t tx_data[] = {REG_RTCSEC };
uint8_t rx_data[] = {0};
// Select REG_RTCSEC register and use repeated start
err_code = nrf_drv_twi_tx(&m_twi,MCP7940_I2C,tx_data , sizeof(tx_data),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);
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