1.2.21.57 1.3.25.57 1.4.21.57 1.5.25.57 1.6.22.57 1.7.23.57 1.9.19.57 1.29.23.57 1.30.18.57 1.31.18.57 1.32.26.57 1.33.16.57 1.37.18.57 1.38.21.57 1.39.18.57 1.40.20.57 SERCOMx_I2C_WriteRead Function

C

/* x = SERCOM instance number */

/* I2C master mode */

bool SERCOMx_I2C_WriteRead(uint16_t address, uint8_t *wdata, uint32_t wlength, uint8_t *rdata, uint32_t rlength)	

Summary

Write and Read data from I2C slave

Description

This function writes data from wdata buffer to the slave of given address and of size (in bytes) equal to wlength. Master then generates a repeated start and does a read operation. Read operation reads data into rdata buffer of size (in bytes) equal to rlength from the slave. Master generates a stop condition after reading the data.

Precondition

SERCOMx_I2C_Initialize must have been called for the associated SERCOM I2C instance.

Parameters

Param Description
address 7-bit / 10-bit slave address
wdata pointer to write data buffer
wlength write data length in bytes
rdata pointer to read data buffer
rlength read data length in bytes

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 myTxData [NUM_BYTES] = {'1', '0', ' ', 'B', 'Y', 'T', 'E', 'S'};
uint8_t myRxData [NUM_BYTES] = {0};
    
    if(!SERCOM0_I2C_WriteRead( SLAVE_ADDR, &myTxData[0], NUM_BYTES, myRxData, NUM_BYTES ))
    {
        // error handling
    }
    

Remarks

Calling this function is not the same as calling the SERCOMx_I2C_Write() function and then calling the SERCOMx_I2C_Read() function. The SERCOMx_I2C_WriteRead function will insert a Repeated Start condition between the Write and the Read stages. The SERCOMx_I2C_Write() and the SERCOMx_I2C_Read() function generates a stop condition after the write and the read has completed.