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

Using Nrf51422 as I2C(TWI)

Hello

I have an problem using I2C on my custom board which uses an Nrf51422 SOC. I have an RTC chip connected to it and I have no idea how to use your libraries.

The rtc 7 bit slave address is 0xDE. And they have registers which needs to be accessed according to their datasheet. As per your library for TWI I only see a function such as nrf_drv_twi_tx(nrf_drv_twi_t const * const p_instance, uint8_t address,uint8_t const * p_data,uint32_t length, bool xfer_pending); which doesn't have registers.

If you could please help me how to Read/Write data into the I2C and to its Registers.

Regards Darshan N

Parents
  • The nrf_drv_twi_tx() function doesn't have registers because registers isn't anything to do with the actual I2C protocol. I2C is just a data read/data write protocol which does exactly that, writes a chunk of data to a device at an address and reads data back from a device at an address.

    The chip you're interfacing with may be explained in the datasheet using registers, but if you read it again you should see the underlying basic I2C data transfer which accesses them is just a data transfer with a given format. Often for instance, the 'register' number you're writing to is the first byte of the data transferred, and the rest of the data is what's then written to that 'register'. A transfer may consist of writing a byte with a register number in the written data, and then reading, the chip then sends the contents of that 'register' out.

    Once you've understood the basic command sequence to your RTC chip and know how to format the data, then you'll see the function above is exactly what you need, it just sends out a chunk of formatted data.

Reply
  • The nrf_drv_twi_tx() function doesn't have registers because registers isn't anything to do with the actual I2C protocol. I2C is just a data read/data write protocol which does exactly that, writes a chunk of data to a device at an address and reads data back from a device at an address.

    The chip you're interfacing with may be explained in the datasheet using registers, but if you read it again you should see the underlying basic I2C data transfer which accesses them is just a data transfer with a given format. Often for instance, the 'register' number you're writing to is the first byte of the data transferred, and the rest of the data is what's then written to that 'register'. A transfer may consist of writing a byte with a register number in the written data, and then reading, the chip then sends the contents of that 'register' out.

    Once you've understood the basic command sequence to your RTC chip and know how to format the data, then you'll see the function above is exactly what you need, it just sends out a chunk of formatted data.

Children
No Data
Related