CALIBRE
Parameters are: | int setnack |
Value Returned:
I2C status on exit :
Example Usage:
This controls whether the Parallel I2C Communications Adapter transmits an Acknowledge down the I2C Bus on reception of a byte. The last byte received during a transfer must not be acknowledged. If setnack = 0 then acknowledge is enabled, if setnack = 1 then acknowledge is disabled. Therefore, if the LAST BUT ONE byte is to be read, setnack should be set to = 1; in all other cases it must be clear = 0. (in case of reading 1 byte only, acknowledge will have been disabled be sendaddress (or restart) and so should know be enabled again after reading the data.
int i2cdata
The value returned depends on whether the data was read successfully. If the data was read then the value is returned.
If the data cannot be read (because there is none in the register) then the last status read IORed with 0x8000 will be returned.
The function will read the status a number of times before returning an error condition - this number is defined by the MAXNUMBEROFGOES constant defined in I2CINC.C, this value may be altered to suit your system.
0x00 bus busy and unread data in data register.
0x80 bus busy and no unread data in data register
The value will depend on whether any more bytes of data have been transmitted by the slave device which is being read.
(See Appendix A for details status codes). (see also sample programs)
/* This will read a byte of data from a slave previously addressed */ /* by and with acknowledge already disabled by sendaddress. */ /* After reading the data, acknowledge will be
{
int setnack, i2cdata; |
|
setnack = 0; | /* Enable acknowledge - only one byte it to */ |
| /* be read (see parameter descriptions) */ |
i2cdata = readbyte(setnack); |
|
if (i2cdata & 0x8000) == 0x8000 |
|
{ |
|
printf("Data read fault i2c status %x", i2cdata);
}
else
{
printf("Data read was %x\n", i2cdata);
}
}
Issue 1.3 | Page 10 |
22/07/99