about i2c again
Posted: Sun Mar 19, 2006 8:18 pm
char I2C_ReadByte(char lastbyte)
{
char retVal = 0;
char mask;
//wait until the bus is idle...
mask = I2C_MaskFromBit(R_W);
while (sspstat & mask); // tx in progress?
mask = I2C_MaskFromBit(ACKEN);
mask = mask | I2C_MaskFromBit(RCEN);
mask = mask | I2C_MaskFromBit(PEN);
mask = mask | I2C_MaskFromBit(RSEN);
mask = mask | I2C_MaskFromBit(SEN);
while (sspcon2 & mask); // bus busy?
//set RCEN and wait for it to clear
mask = I2C_MaskFromBit(RCEN);
sspcon2 |= mask;
while ((sspcon2 & mask) == mask);
if (lastbyte == 0)
{
clear_bit(sspcon2, ACKDT);
} else {
set_bit(sspcon2, ACKDT);
}
//set ACKEN and wait for it to clear
mask = I2C_MaskFromBit(ACKEN);
sspcon2 |= mask;
while ((sspcon2 & mask) == mask);
retVal = sspbuf;
return (retVal);
}
Can anybody explain me how the lastbyte parameter works in the code above?
I was looking at the c code generated by the web server component, and the function there is used one time with parameter 1, and then with parameter 0
{
char retVal = 0;
char mask;
//wait until the bus is idle...
mask = I2C_MaskFromBit(R_W);
while (sspstat & mask); // tx in progress?
mask = I2C_MaskFromBit(ACKEN);
mask = mask | I2C_MaskFromBit(RCEN);
mask = mask | I2C_MaskFromBit(PEN);
mask = mask | I2C_MaskFromBit(RSEN);
mask = mask | I2C_MaskFromBit(SEN);
while (sspcon2 & mask); // bus busy?
//set RCEN and wait for it to clear
mask = I2C_MaskFromBit(RCEN);
sspcon2 |= mask;
while ((sspcon2 & mask) == mask);
if (lastbyte == 0)
{
clear_bit(sspcon2, ACKDT);
} else {
set_bit(sspcon2, ACKDT);
}
//set ACKEN and wait for it to clear
mask = I2C_MaskFromBit(ACKEN);
sspcon2 |= mask;
while ((sspcon2 & mask) == mask);
retVal = sspbuf;
return (retVal);
}
Can anybody explain me how the lastbyte parameter works in the code above?
I was looking at the c code generated by the web server component, and the function there is used one time with parameter 1, and then with parameter 0