Hardware Reference
In-Depth Information
}
if(Wire.available())
{
_data = Wire.read();
}
return(bitRead(_data, pos));
}
The function reads in data from one of the chips with Wire.requestFrom() ,
depending on the bit position. If the requested bit is between 0 and 7, the request
is sent to chip 0; otherwise it is sent to chip 1. Then, the Arduino function
bitRead() is called, extracting the bit that was requested and returning it as a
boolean value.
All the read functions have been completed, but it isn't over yet. The write
functions need to be written. Writing a byte is straightforward:
bool PCF8574AP::writeByte(uint8_t data, bool chipSelect)
{
if (chipSelect == 0)
{
Wire.beginTransmission(_chip0Address);
_chip0Output = data;
Wire.write(_chip0Output);
}
else if (chipSelect == 1)
{
Wire.beginTransmission(_chip1Address);
_chip1Output = data;
Wire.write(_chip1Output);
}
else
{
return false;
}
Wire.endTransmission();
return true;
}
As with readByte() , writeByte() selects only one chip. If chipSelect is 0,
an I 2 C transmission begins at chip 0. data is copied to _chip0Output , and its
contents are sent to the device. If chip 1 is selected, the same operation occurs,
but for chip 1. Finally, the data is sent, and the function returns true .
Writing a word is similar:
bool PCF8574AP::writeWord(uint16_t data)
{
Wire.beginTransmission(_chip0Address);
_chip0Output = ((uint8_t) ((data) & 0xff));
Search WWH ::




Custom Search