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

How to get command/data on I2C Slave, which has been send from I2C master.

Hi All,

I am trying to implement I2C Slave functionality on NRF52832, So NRF52832 will act as a I2C slave. 

So i found there is an example TWIS Slave and TWI Master Mode Drivers Example (https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v12.2.0%2Ftwi_master_with_twis_slave_example.html). 

This is geed example to start. 

But i have a doubt, i am not sure how to receive data/command from I2C master and I2C slave device should respond against that data.  

in the example there is twis_event_handler() callback function which handles read/write operation on I2C slave device, So whenever master has to read data it just send a request to the i2c slave and twis_event_handler() callback function will get triggered, we get p_event->type and p_event->data.buf_req. So in response to this I2C slave send the data to the master. 

But suppose i have to send following command/data  from master to request some data from i2c slave

1).  0xA1 0xA2  0x1 0x2

2)   0xA4 0xA5  

So, how and where i2c slave will receive this command, so that according to received data/command, i2c slave can respond to the master. It would be great help if i can get some example.

Thanks & Regards

Pradeep

Parents
  • Hi,

    You will receive events in the twis_event_handler both when a read/write is requested (TWIS_EVT_READ/WRITE_REQ) and when it is done (TWIS_EVT_READ/WRITE_DONE). When the TWI master is done writing the command, you can check the received command in the WRITE_DONE event and prepare the TX buffer with the appropriate response. When the TWI master starts the read operation, you can provide the buffer in the READ_REQ event.

    Best regards,
    Jørgen

Reply
  • Hi,

    You will receive events in the twis_event_handler both when a read/write is requested (TWIS_EVT_READ/WRITE_REQ) and when it is done (TWIS_EVT_READ/WRITE_DONE). When the TWI master is done writing the command, you can check the received command in the WRITE_DONE event and prepare the TX buffer with the appropriate response. When the TWI master starts the read operation, you can provide the buffer in the READ_REQ event.

    Best regards,
    Jørgen

Children
No Data
Related