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

nrf_drv_twi and read register

Hi, how is the new nrf_drv_twi supposed to be used for reading registers? The sequence for that is pretty much industry standard:

> Device address
< Ack 
> 0x00 (register)
< Ack
< Data
> Ack

this code will write the address twice (one w and one r) rather then doing a write and then expecting data to be clocked from the peripheral:

 nrf_drv_twi_tx(&twi, MAX7315_ADDRESS, (uint8_t*)&buf, 1, true);
 nrf_drv_twi_rx(&twi, MAX7315_ADDRESS, (uint8_t*)&buf, 1, false);
Parents
  • That isn't the sequence.

    The device address + r/w specifies the direction of transport for ALL following bytes until the next start. There is no concept of the direction flipping in the middle of a transaction like that. So you have to send the device address twice, once with 'w' to write the register location, then, on a repeated start, send address again with 'r' in order to tell the slave to transmit the data.

    Which is what the code you posted does.

    What device are you trying to interface with?

Reply
  • That isn't the sequence.

    The device address + r/w specifies the direction of transport for ALL following bytes until the next start. There is no concept of the direction flipping in the middle of a transaction like that. So you have to send the device address twice, once with 'w' to write the register location, then, on a repeated start, send address again with 'r' in order to tell the slave to transmit the data.

    Which is what the code you posted does.

    What device are you trying to interface with?

Children
No Data
Related