Calibre UK PICA93LV user manual Calibre

Page 12

CALIBRE

￿

￿

 

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.

Issue 1.3

Page 9

22/07/99

Image 12
Contents Calibre Calibre CopyrightContents Configuring the Adapter IntroductionGeneral Introduction Packing ListInstalling the Adapter Typical PC ConnectionConnecting the Adapter to Your System Connector PinoutPower Supply Bus Capacitance LimitationsSoftware Utilities \C\CLIB\SPICA.LIB\C\CLIB\CPICA.LIB \C\CLIB\MPICA.LIBDOS Qbasic Library/Programs \B\SOURCE\I2CINC.BAS\B\SOURCE\PROMREAD.BAS \B\SOURCE\PROMWRIT.BASWindows LIB/DLL Functions Using the Utilities RoutinesInt ownaddress Int sclkInt i2cstatus Int slaveaddressInt setnack Calibre Int i2cdata Calibre Int i2cstatus Number if the adapter is to read from the slave Qbasic Routines Ownaddress%Sclk% I2cstatus%Slaveaddress% Setnack% I2cdata%See Appendix a for details status codes I2cstatus% Is to read from the slave Libraries for Programming in Microsoft Windows Environments Int baseaddressInt statuswait Int ErrCode Int wrDataSendaddress Address to be accessed via the I2C, e.g. A1H Int sendbytesint far *transferarray Int far *transferarrayInt bsent Int getbytesint far *transferarray Int nobytesreadSlave using the adapter Further Information Bit 4 The Bus Error BER Bit Appendix a Parallel I2C Communications Adapter Status CodesBit 7 MSB The Pending Interrupt Not PIN Bit Bit 6 Not UsedAppendix B Parallel I2C Communications Adapter Control Codes Question Get corrupted transfers why is this? Most Commonly Asked I2C QuestionsQuestion Do you have software to talk to my........? QuestionCode. Why? Please Email Your Query to