Nrf52840 one wire protocol usage with MAX17211 IC.

Hello Everyone,

                     I am trying to implement one wire protocol for interfacing MAX17211 fuel guage IC with NRF52840. I wand to know if there is any one wire library or any example which we can use to read the registers of MAX17211. Can we read the registers of MAX17211 directly from the data pin??Or we have to follow some particular signal pattern to read the data?

Thanks & Regards,

Snehal.

Parents Reply Children
  • Hi Vidar,

             yes you are right. we can use nrf_delay_us inside an rtos task. Thank you. I thought when rtos is used only vTaskDelay should be used for creating delays.I am going to test more with the IC max17211 today. will update you.

    Regards,

    Snehal

  • Hi Vidar,

               One more thing I wanted to ask is that on the same one wire line we have attached one more I2C based IC bq2429. so basically BQ2429 is I2c based and on the same line we have MAX17211 which is one wire based. So will it cause problems in getting data from the MAX17211?? 

    The pins used for BQ2429  are as follows:-

    #define PSF_SCL_PIN NRF_GPIO_PIN_MAP(1,9)
    #define PSF_SDA_PIN NRF_GPIO_PIN_MAP(0,11)

    The pins used for MAX17211 is as follows:-

    #define PSF_SDA_PIN NRF_GPIO_PIN_MAP(0,11)

    Thanks & Regards,

    Snehal.

  • Hi Snehal,

    I guess it may be ok to share it with the i2c clock line, but this is something you need to confirm yourself. Check the datasheets and see if you can use the same pullups, etc

  • Hi Vidar,

                 We have solved the issue with MAX17211, we tried to check the pulses but it seemed that there was some problem with the hardware. So the hardware guy has now replaced the ic from MAX17211 to MAX17201. This IC is pure I2C based and I am able to connect and read some data from the IC. When I read 8bit registers I dont have any issue. But when I am trying to read 16bit register from the IC, I am getting errors:-

    I have modified the code a bit in order to read 2bytes from register. I am not able to read 16bit registers. I tried to read NPACKCFG_REG but not able to read it properly.As well as while compiling I am getting warnings like this:-

    unsigned conversion from 'int' to 'uint8_t' {aka 'unsigned char'} changes value from '437' to '181' [-Woverflow]

    #define NPACKCFG_REG     0x1B5
    
    
    
    bool i2c_register_write_max17211(uint16_t register_address, uint16_t value)
    {
    
          ret_code_t err_code;
          uint8_t tx_data[4];
    
          tx_data[0] = ( (register_address >> 8)& 0xFF );
          tx_data[1] = register_address & 0xFF;
          tx_data[2] = ((value>>8)& 0xff);
          tx_data[3] = value & 0xFF;
    
          m_xfer_done = false;
        
          err_code = nrf_drv_twi_tx(&m_twi, MAX17211_WHO_AM_I, tx_data, sizeof(tx_data), false);
      //Wait until the transmission of the data is finished
        while (m_xfer_done == false)
        {
          }
    
       // if there is no error then return true else return false
        if (NRF_SUCCESS != err_code)
        {
            NRF_LOG_INFO("FAILED");
            return false;
        }
    
        NRF_LOG_INFO("SUCCESS");
    
        return true;	
    
    }
    
    bool i2c_register_read_max17211(uint8_t register_address, uint8_t destination[2], uint8_t number_of_bytes)
    {
        ret_code_t err_code;
        //uint8_t rx_buffer[2];
    
        //Set the flag to false to show the receiving is not yet completed
        m_xfer_done = false;
        
        // Send the Register address where we want to write the data
        err_code = nrf_drv_twi_tx(&m_twi, MAX17211_WHO_AM_I, &register_address, 1, true);
    	  
        //Wait for the transmission to get completed
        while (m_xfer_done == false){}
        //vTaskDelay(1000);
    
        // If transmission was not successful, exit the function with false as return value
        if (NRF_SUCCESS != err_code)
        {
            return false;
        }
    
        //set the flag again so that we can read data from the MPU6050's internal register
        m_xfer_done = false;
    	  
        // Receive the data from the MPU6050
        //err_code = nrf_drv_twi_rx(&m_twi, MAX17211_WHO_AM_I, destination, number_of_bytes);
        err_code = nrf_drv_twi_rx(&m_twi, MAX17211_WHO_AM_I, &destination[0], sizeof(destination));
    		
        //wait until the transmission is completed
        while (m_xfer_done == false){}
        //vTaskDelay(1000);
    
    
        // if data was successfully read, return true else return false
        if (NRF_SUCCESS != err_code)
        {
            return false;
        }
        
        //NRF_LOG_INFO("DATA IS %x",destination);
        return true;
    
    }

    Can you please help? Also Is my code proper for writing 16bit register?

  • Hi,

    sne_333 said:
    I have modified the code a bit in order to read 2bytes from register. I am not able to read 16bit registers. I tried to read NPACKCFG_REG but not able to read it properly.

    What do you mean by not being able to read it properly? Are you getting the NRF_DRV_TWI_EVT_DONE event after you have called nrf_drv_twi_rx(), or are you getting a NRF_DRV_TWI_EVT_ADDRESS_NACK or NRF_DRV_TWI_EVT_DATA_NACK event?

    sne_333 said:
    unsigned conversion from 'int' to 'uint8_t' {aka 'unsigned char'} changes value from '437' to '181' [-Woverflow]

    Please show me where you are getting this warning.

Related