This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

MCP7940 drivers for nrf52840

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

Parents Reply
  • 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

Children
  • 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

    MCP7940.cpp

  • 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. 

Related