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
  • I don't use it but .. it must be something like this

    Your slave address is 0xDE, you said, that's the pre-shifted one, Nordic uses just the 7 bits, so it's 0xDE >> 1 or 0x6F. That diagram shows a standard I2C transaction (you should read the spec) so the first byte is the address, shifted, finishing with a '0' which means 'write'.

    So assuming you want to write 0x12 to the register with address 0x20 and you've set the TWI up already

    static uint8_t data[2]; // should be a static buffer especially if you're using the callback mode
    data[0] = 0x20;
    data[1] = 0x12
    nrf_drv_twi_tx( &instance, 0x6F, data, 2, xfer_pending );
    

    instance is the instance you set up, xfer_pending depends on what you're doing (ie are you going to do a repeated start to read data back). That writes out the address and two bytes of data to TWI.

  • Thank you

    I followed your procedure and did the same for read. And I am not able to read in debug mode.

    ALL the pins are connected properly double checked the PCB with my schematics. And the slave is responding have an LED for response which glows.

    please find my code and read cycle attached in my previous answer above.

    can you help me for READ CYCLE ??

Reply
  • Thank you

    I followed your procedure and did the same for read. And I am not able to read in debug mode.

    ALL the pins are connected properly double checked the PCB with my schematics. And the slave is responding have an LED for response which glows.

    please find my code and read cycle attached in my previous answer above.

    can you help me for READ CYCLE ??

Children
No Data
Related