Справочник Пользователя для Calibre UK PICA93LV

Скачать
Страница из 35
CALIBRE
Issue 1.3
 
Page 9
22/07/99
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.
I2C status on exit 
0x00 bus busy and address sent and acknowledged
0x08 bus busy and address sent but not acknowledged
0x80 bus busy and address not sent.
(see Appendix A for details of Status codes).
Example Usage:
(see also sample programs)
/* This will send a start and the I2C Slave Address of the device to be communicated with. */
main()
{
int slaveaddress, setnack, i2cstatus;
slaveaddress = 0xa0;
/* I2C Address of slave, this is a typical */
/* write for an I2C static RAM or EEPROM */
setnack = 0;
/* Enable Acknowledge (see parameter descriptions) */
i2cstatus = sendaddress(slaveaddress, setnack);
switch i2cstatus
{
case 0x00:
printf("Start and I2C Slave Address sent and acknowledged\n");
case 0x08:
printf("Start and I2C Slave Address sent and not acknowledged\n");
default:
printf("Start not sent status is %x", i2cstatus);
}
}
4.2.4.
I2C Read Data Byte from Slave Routine
Function definition:
int readbyte(int setnack)
Usage:
i2cdata = readbyte(setnack);
Function:
This is the function to read a byte of data from a slave device whose slave
read address has already been sent by sendaddress (or restart). It can be
used to disable acknowledge after reading data if it is the last but one byte to
be read.
Note: First byte read after read-address is always that address and should be
discarded. This byte should be ignored when working out when to
acknowledge/not acknowledge.