1.3.2.4.4 I2C_BB_WriteForced Function
C
bool I2C_BB_WriteForced(uint16_t address, uint8_t *pdata, size_t length)
Summary
Force writes data to the slave.
Description
I2C 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.
The function is non-blocking. It initiates bus activity and returns immediately. The transfer is then completed in the timer peripheral interrupt. A transfer request cannot be placed when another transfer is in progress. Calling the write forced function when another function is already in progress will cause the function to return false.
The library will call the registered callback function when the transfer has terminated.
Precondition
I2C_BB_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 written. |
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 function executes in the context of the I2C interrupt. } I2C_BB_Initialize(); I2C_BB_CallbackRegister(MyI2CCallback, NULL); if(I2C_BB_WriteForced( SLAVE_ADDR, &myData[0], NUM_BYTES ) == false) { // error handling }
Remarks
This API will be generated only if Forced Write option is enabled in MHC