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

TWI interface slave address

Hi,

I need to interface a LED driver (PCA9632) using TWI. In the TWI APIs I can't see any way to pass the slave address to the TWI instance. Speaking about the nrf_drv_twi_init function, there is no field in the parameters structs that accepts a slave address. What's the right way to use the TWI interface ?

Thanks, Paolo.

Parents Reply Children
  • Sorry ... suppose following scenario. My I2C device has address 0xC4 (for example) and I need to write some bytes to the internal register of this device with address 0x02. As I understood I need to use the nrf_drv_twi_tx function twice ? First time to send the slave address and second time to addressing the internal register for sending data ? First time wihout data ? (p_data = NULL and length = 0) ?

    Thanks, Paolo

  • Nope - if you want to just write something to the slave you use its address (which won't be 0xC4 because that's 8-bit, probably more likely 0x62) with the data you want written in whatever format the slave expects it. The data sheet for the slave will tell you what sequence of bytes address the internal register, that's part of the data not the address. perhaps the first byte of data will be 0x02 denoting a write to that register and the rest of the data will be data, perhaps the first byte will be a byte indicating a write to a register, the second byte will be 0x02 and the data will follow. All depends on your slave.

    None of that however has anything to do with the slave address which is always prepended to sequence of data sent out on the wire.

  • Ok thanks. However adding the nrf_drv_twi driver I receive the following compilation error on TWI_COUNT undefined. What's going wrong ?

  • since you didn't post the error hard to say really - however if TWI_COUNT is undefined, how about .. defining it. Most likely you've not defined any TWI instances to use leaving the config file at the default which is that there aren't any defined, or you haven't included a config file at all. Just looking briefly at the code and searching for TWI_COUNT should take about 10 seconds to find and fix.

  • I think that the problem wasn't so simple as you said (10 seconds to find and fix) ... it seems to be a bug inside the current SDK I'm using (8.1.1) see here : devzone.nordicsemi.com/.../

Related