Calibre UK PICA93LV user manual Int i2cdata

Page 13

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 re-enabled. */ main()

{

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

Image 13
Contents Calibre Copyright CalibreContents Introduction Configuring the AdapterGeneral Introduction Packing ListTypical PC Connection Installing the AdapterConnector Pinout Connecting the Adapter to Your SystemPower Supply Bus Capacitance Limitations\C\CLIB\SPICA.LIB Software Utilities\C\CLIB\CPICA.LIB \C\CLIB\MPICA.LIB\B\SOURCE\I2CINC.BAS DOS Qbasic Library/Programs\B\SOURCE\PROMREAD.BAS \B\SOURCE\PROMWRIT.BASWindows LIB/DLL Functions Routines Using the UtilitiesInt ownaddress Int sclkInt slaveaddress Int i2cstatusInt setnack Calibre Int i2cdata Calibre Int i2cstatus Number if the adapter is to read from the slave Ownaddress% Qbasic RoutinesSclk% I2cstatus%Slaveaddress% I2cdata% Setnack%See Appendix a for details status codes I2cstatus% Is to read from the slave Int baseaddress Libraries for Programming in Microsoft Windows EnvironmentsInt statuswait Int wrData Int ErrCodeSendaddress Address to be accessed via the I2C, e.g. A1H Int far *transferarray Int sendbytesint far *transferarrayInt bsent Int nobytesread Int getbytesint far *transferarraySlave using the adapter Further Information Appendix a Parallel I2C Communications Adapter Status Codes Bit 4 The Bus Error BER BitBit 7 MSB The Pending Interrupt Not PIN Bit Bit 6 Not UsedAppendix B Parallel I2C Communications Adapter Control Codes Most Commonly Asked I2C Questions Question Get corrupted transfers why is this?Question Do you have software to talk to my........? QuestionCode. Why? Please Email Your Query to