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

Trying to read a 24-bit register using I2C

Hi, I am trying to read a 24-bit register (with 8-bit address) using the I2C (nrf52). And the timing diagram is given below.

image description

Basically I created a 3-element array (24-bit in total)

static uint8_t m_sample[3];

and use nrf_drv_twi_rx to store the value into the array.

void read_register(uint8_t address){ 	
	ret_code_t err_code;
		
	m_xfer_done = false;
	err_code = nrf_drv_twi_tx(&m_twi, SLAVE_ADDR, &address, 1, false);
    APP_ERROR_CHECK(err_code);
    while (m_xfer_done == false);
	
	m_xfer_done = false;

    /* Read from register */
    err_code = nrf_drv_twi_rx(&m_twi, SLAVE_ADDR, m_sample, sizeof(m_sample));
    APP_ERROR_CHECK(err_code);
	
	while (m_xfer_done == false){};
}

Can anyone tell me if this works? Thank you very much.

P.S. How does the ACK and NACK work in nrf52? How can I control these two bit?

Parents
  • Hi PPendless,

    I think the approach you describe in your question should work fine. You can see the write and read sequences of TWI peripheral in the nRF52832 Product Specification, please see this page on our Infocenter.

    P.S. You cannot modify the read and write sequences, when and where the ACKs and NACKs are issued can be seen in the figures on the Infocenter page I linked to.

    Best regards

    Bjørn

Reply
  • Hi PPendless,

    I think the approach you describe in your question should work fine. You can see the write and read sequences of TWI peripheral in the nRF52832 Product Specification, please see this page on our Infocenter.

    P.S. You cannot modify the read and write sequences, when and where the ACKs and NACKs are issued can be seen in the figures on the Infocenter page I linked to.

    Best regards

    Bjørn

Children
No Data
Related