Hardware Reference
In-Depth Information
return(_data);
}
This function requests 1 byte of data from either chip, depending on the
value of chipSelect . If data is present in the I 2 C buffer, that data is copied into
the local variable _data and then returned. If no data is available, the function
returns zero.
Reading words is just like reading bytes, only 2 bytes are read. This func-
tion obtains a byte of data from both chips, merges them into a word, and then
returns that data. This is accomplished with the following:
uint16_t PCF8574AP::readWord(void)
{
byte _data0 = 0;
byte _data1 = 0;
Wire.requestFrom(_chip0Address, 1);
if(Wire.available())
{
_data0 = Wire.read();
}
Wire.requestFrom(_chip1Address, 1);
if(Wire.available())
{
_data1 = Wire.read();
}
return(word(_data1, _data0));
}
Things become slightly more complex when reading a specii c bit, requiring
bitwise operations:
bool PCF8574AP::readBit(uint8_t pos)
{
byte _data = 0;
// Is the bit requested out of range?
if (pos > 15)
return 0;
if (pos < 8)
Wire.requestFrom(_chip0Address, 1);
else
{
Wire.requestFrom(_chip1Address, 1);
pos -= 8;
Search WWH ::




Custom Search