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

I²C communication between a nrf5240 and a MCP3221

Hello, 

I would like to implement an I²C communication between a nrf52840 and a MCP3221 (which is an ADC). 

The first 7-bit of the MCP3121 are 0b1001101. I guess the slave address is 0x4D. 

I developed the following function in order to communication with the MCP3221. 

ret_code_t I2C_register_read(uint8_t slave_addr, uint8_t reg_addr, uint8_t * pdata, uint32_t bytes)
{
ret_code_t ret_code;
ret_code = nrf_drv_twi_tx(p_twi_master,slave_addr, &reg_addr,1,false);
if(ret_code != NRF_SUCCESS)
{
return ret_code;
}

ret_code = nrf_drv_twi_rx(p_twi_master,slave_addr, pdata, bytes);

return ret_code;
}

I think that slave_addr=0x4D but I don't know what reg_addr to use. 

When I read the MCP3121 datasheet, it appears that there is no register. So what register address (reg_addr) am I suppoed to use ? Shall I use other TWI function ? 

Thank you for your help ! 

Parents
  • From the MCP3121 datasheet, "The eighth bit of the slave address determines if the master device wants to read conversion data or write to the MCP3021. When set to a 1, a read operation is selected. When set to a 0, a write operation is selected. There are no writable registers on the MCP3021, therefore, this bit must be set to a 1 to initiate a conversion."


    ret_code = nrf_drv_twi_rx(p_twi_master,slave_addr, pdata, bytes);

    should be sufficient.

Reply
  • From the MCP3121 datasheet, "The eighth bit of the slave address determines if the master device wants to read conversion data or write to the MCP3021. When set to a 1, a read operation is selected. When set to a 0, a write operation is selected. There are no writable registers on the MCP3021, therefore, this bit must be set to a 1 to initiate a conversion."


    ret_code = nrf_drv_twi_rx(p_twi_master,slave_addr, pdata, bytes);

    should be sufficient.

Children
No Data
Related