Calibre UK PICA93LV user manual Setnack%, I2cdata%

Page 19

CALIBRE

￿

￿

Sub Main

 

slaveaddress% = &HA0

' IC Address of slave, this is a typical write

 

' address for an I2C static RAM or EEPROM

setnack% = 0

' Enable Acknowledge (see parameter descriptions)

i2cstatus% = sendaddress (slaveaddress%, setnack%) Select Case i2cstatus%

case &H00

print "Start and I2C Slave Address sent and acknowledged" case &H08

print "Start and I2C Slave Address sent and not acknowledged" case else

print "Start not sent status is " + Hex$( i2cstatus%)

End Select End sub

4.3.4.I2C Read Data Byte from Slave Routine

Function definition:

readbyte%(setnack as integer)

Usage:

i2cdata% = readbyte%(setnack%)

Function:

function to read a byte of data from a slave device whose slave address has

 

already been sent by sendaddress. Can be used to disable acknowledge after

 

reading data if it is the last but one byte to be read.

Parameters are:

setnack%

 

This controls whether the Parallel I2C Communications Adapter transmits

 

and Acknowledge down the I2C Bus on reception of a byte. The last byte

 

received during a transfer must not be acknowledged, in all other cases

 

acknowledge must be enabled. 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 the case of reading 1 byte only, acknowledge will have

 

been disabled by sendaddress and so should now be enabled again after

 

reading the data.)

Value Returned:

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 &H8000 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.

I2C status on exit :

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.

Issue 1.3

Page 16

22/07/99

Image 19
Contents Calibre Copyright CalibreContents Packing List Configuring the AdapterIntroduction General IntroductionTypical PC Connection Installing the AdapterBus Capacitance Limitations Connecting the Adapter to Your SystemConnector Pinout Power Supply\C\CLIB\MPICA.LIB Software Utilities\C\CLIB\SPICA.LIB \C\CLIB\CPICA.LIB\B\SOURCE\PROMWRIT.BAS DOS Qbasic Library/Programs\B\SOURCE\I2CINC.BAS \B\SOURCE\PROMREAD.BASWindows LIB/DLL Functions Int sclk Using the UtilitiesRoutines Int ownaddressInt slaveaddress Int i2cstatusInt setnack Calibre Int i2cdata Calibre Int i2cstatus Number if the adapter is to read from the slave I2cstatus% Qbasic RoutinesOwnaddress% Sclk%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 Bit 6 Not Used Bit 4 The Bus Error BER BitAppendix a Parallel I2C Communications Adapter Status Codes Bit 7 MSB The Pending Interrupt Not PIN BitAppendix B Parallel I2C Communications Adapter Control Codes Question Question Get corrupted transfers why is this?Most Commonly Asked I2C Questions Question Do you have software to talk to my........?Code. Why? Please Email Your Query to