Skip to content

Instantly share code, notes, and snippets.

@mrT-F

mrT-F/I2C.cpp

Created Jul 30, 2019
Embed
What would you like to do?
IQS5xx I2C Port for the ESP8266 w/ Arduino Firmware
void I2C_Setup(void)
{
Wire.begin(IQS5xx_SDA, IQS5xx_SCL);
}
uint8_t I2C_Write2(uint16_t ui16RegisterAddress, uint8_t *pData, uint8_t ui8NoOfBytes)
{
uint8_t i;
Wire.beginTransmission(IQS5xx_ADDR);
// Send the address
Wire.write((uint8_t)(ui16RegisterAddress>>8));
Wire.write((uint8_t)(ui16RegisterAddress));
// Send the data.
for(i = 0; i < ui8NoOfBytes; i++) {
Wire.write(*pData);
pData++;
}
uint8_t result = Wire.endTransmission(true);
return result == 0 ? TRUE : FALSE;
}
uint8_t I2C_Read2(uint16_t ui16RegisterAddress, uint8_t *pData, uint8_t ui8NoOfBytes)
{
// Send the address
Wire.beginTransmission(IQS5xx_ADDR);
Wire.write((uint8_t)(ui16RegisterAddress>>8));
Wire.write((uint8_t)(ui16RegisterAddress));
uint8_t result = Wire.endTransmission(false);
// Now request data
Wire.requestFrom(IQS5xx_ADDR, ui8NoOfBytes, true);
uint16_t limit = Wire.available();
// consider raising error here if limit != ui8NoOfBytes
for (uint16_t i = 0; i < limit; i++) {
*pData = Wire.read();
pData++;
}
return result == 0 ? TRUE : FALSE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.