LPI2C Slave Callback

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPI2C Slave Callback

Jump to solution
1,178 Views
RehabSoliman
Contributor I

Hello All, I want to understated the  LPI2C Slave Callback 

void lpi2c0_SlaveCallback0(i2c_slave_event_t slaveEvent,void *userData);

what is meant by userData? in the code example it used as the instance 

I want to do :

1- the master will send the frame ID and after that based on this ID the slave will send frame that  related to the ID and I want to use the lpi2c0_SlaveCallback0 function but I don't know how to use it 

so if anyone  could help me in this part?

 

0 Kudos
1 Solution
1,153 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

If slaveListening item is set, the slave interrupt is enabled at initialization time and the slave always listens to the line for a master addressing it. Any events are reported to the application through the callback function provided at initialization time.

So Master always starts with sending device address with R/W bit. Upon receving this, callback is called with I2C_SLAVE_EVENT_RX_REQ or I2C_SLAVE_EVENT_TX_REQ events depending R/W bit received. You can use LPI2C_DRV_SlaveSetRxBuffer() or LPI2C_DRV_SlaveSetTxBuffer() to provide the appropriate buffers for transmit or receive with given number of bytes to be transfered. As shown in the demo example.
If master still sending or requesting more bytes you got I2C_SLAVE_EVENT_RX_FULL or I2C_SLAVE_EVENT_TX_EMPTY events and above functions can be called again.
For stop or repeated start condition detected an I2C_SLAVE_EVENT_STOP event is called.

So the usage depends on used protocol, I think. Obviously if master request data from specified slave address/register it looks like below

PetrS_0-1663328940853.png

Master sends device address with R/W =0 followed by address/register to be read then repeat start is send. Using driver you got I2C_SLAVE_EVENT_RX_REQ, you define receive buffer. After next byte received you should get I2C_SLAVE_EVENT_STOP event and first byte in receive buffer should be address, in your case ID probably. As master then sends again device address with R/W = 1, you got I2C_SLAVE_EVENT_TX_REQ event an you can specify the TX buffer to be sent.

BR, Petr

View solution in original post

0 Kudos
3 Replies
1,154 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

If slaveListening item is set, the slave interrupt is enabled at initialization time and the slave always listens to the line for a master addressing it. Any events are reported to the application through the callback function provided at initialization time.

So Master always starts with sending device address with R/W bit. Upon receving this, callback is called with I2C_SLAVE_EVENT_RX_REQ or I2C_SLAVE_EVENT_TX_REQ events depending R/W bit received. You can use LPI2C_DRV_SlaveSetRxBuffer() or LPI2C_DRV_SlaveSetTxBuffer() to provide the appropriate buffers for transmit or receive with given number of bytes to be transfered. As shown in the demo example.
If master still sending or requesting more bytes you got I2C_SLAVE_EVENT_RX_FULL or I2C_SLAVE_EVENT_TX_EMPTY events and above functions can be called again.
For stop or repeated start condition detected an I2C_SLAVE_EVENT_STOP event is called.

So the usage depends on used protocol, I think. Obviously if master request data from specified slave address/register it looks like below

PetrS_0-1663328940853.png

Master sends device address with R/W =0 followed by address/register to be read then repeat start is send. Using driver you got I2C_SLAVE_EVENT_RX_REQ, you define receive buffer. After next byte received you should get I2C_SLAVE_EVENT_STOP event and first byte in receive buffer should be address, in your case ID probably. As master then sends again device address with R/W = 1, you got I2C_SLAVE_EVENT_TX_REQ event an you can specify the TX buffer to be sent.

BR, Petr

0 Kudos
496 Views
Ayaz
Contributor III

Hi

I am facing an issue with the example code for the lpi2c_flexio_that the slave doesnot not receive the data even thought i am using the defaults configurations for the example code  ,i think the slave callback function is not been called.

0 Kudos
1,151 Views
RehabSoliman
Contributor I

thanks for your replay 

I use the callback function on the slave side in case of the master send Frame ID the salve receive it and push this id to the upper layer to take the data related to this id to send it to the master after send read request but the correct data send to the master in the next request not in the same read request so I need when the master send the frame id the slave take this id and send the data in the same request

I will attach the code of the slave and of the master  

could you help me to solve this issue ?

0 Kudos