1.21.10.2 I2Cx_WriteForced Function
C
/* x = I2C instance number */
/* I2C master mode */
bool I2Cx_WriteForced(uint16_t address, uint8_t* pdata, size_t length)
Summary
Forced write data to the slave.
Description
Master calls this function to transmit the entire buffer to the slave even if the slave ACKs or NACKs the address or any of the data bytes. This is typically used for slaves that have to initiate a reset sequence by sending a dummy I2C transaction. Since the slave is still in reset, any or all the bytes can be NACKed. In the normal operation, if the address or data byte is NACKed, then the transmission is aborted and a STOP condition is asserted on the bus; however, the forced API continues to write data to the slave even if a NAK has been received.The function will attempt to write length number of bytes from pdata buffer to a slave whose address is specified by address. The I2C Master will generate a Start condition, write the data and then generate a Stop Condition. The function is non-blocking. It initiates bus activity and returns immediately. The transfer is then completed in the peripheral interrupt. A transfer request cannot be placed when another transfer is in progress. The library will call the registered callback function when the transfer has completed.
Precondition
I2Cx_Initialize must have been called for the associated I2C instance.
Parameters
Param | Description |
---|---|
address | 7-bit / 10-bit slave address. |
pdata | pointer to source data buffer that contains the data to be transmitted. |
length | length of data buffer in number of bytes. Also the number of bytes to be written. |
Returns
true - The request was placed successfully and the bus activity was initiated. false - The request fails, if there was already a transfer in progress when this function was called.
Example
uint8_t myData [NUM_BYTES]; void MyI2CCallback(uintptr_t context) { // This function will be called when the transfer completes. Note // that this functioin executes in the context of the I2C interrupt. } I2Cx_Initialize(); I2Cx_CallbackRegister(MyI2CCallback, NULL); if(!I2Cx_WriteForced( SLAVE_ADDR, &myData[0], NUM_BYTES )) { // error handling }
Remarks
None.