1.4.21.64 SERCOMx_I2C_Read_HighSpeed Function

C

/* x = SERCOM instance number */

/* I2C master mode */

bool SERCOMx_I2C_Read_HighSpeed(uint16_t address, uint8_t *pdata, uint32_t length)	

Summary

Reads data from the I2C slave in high speed mode.

Description

This function reads the data from a slave on the bus. The function will attempt to read length number of bytes into pdata buffer from a slave whose address is specified as address. The I2C Master generates a Start condition, and transmits the master code in full speed mode. After receiving a NAK, the transfer takes place in high speed mode. I2C master generates a repeated start followed by slave address which is followed by data from I2C slave and finally generates a Stop Condition. If the slave NAKs the request or a bus error is encountered on the bus, the transfer is terminated. The application can call SERCOMx_I2C_ErrorGet() function to know the cause of the error. The function is non-blocking. It initiates bus activity and returns immediately. The transfer is completed in the peripheral interrupt. A transfer request cannot be placed when another transfer is in progress. Calling the read 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 if callback is registered.

Precondition

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

Parameters

Param Description
address 7-bit / 10-bit slave address
pdata pointer to destination data buffer where the received data shouldbe stored
length length of data buffer in number of bytes. Also the number of bytesto be read.

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];

if(!SERCOM0_I2C_Read_HighSpeed( SLAVE_ADDR, &myData[0], NUM_BYTES ))
{
    // error handling
}

Remarks

None.