Calibre UK PICA93LV user manual Is to read from the slave

Page 22

CALIBRE

￿

￿

4.3.7.I2C Restart and Address Sending Routine

Function definition:

restart%(slaveaddress as integer setnack as integer)

Usage:

i2cstatus% = restart(slaveaddress%, setnack%)

Function:

procedure to send Restart and slave address of device which is to be

 

communicated with, without a Stop having been sent at the end of the last

 

transmission/reception. This routine is particularly useful for reading

 

memories which must first have a data pointer written to them to select where

 

the read is to occur from, and must then have their read address sent with a

 

Restart to proceed with the read operation.

Parameters are:

slaveaddress%

 

The slave address of the device which is to be communicated with. This will

 

be an even number if the communicated with. This will be an even number if

 

the adapter is to write to the slave, add 1 to get an odd number if the adapter

 

is to read from the slave.

 

setnack%

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, in all other cases acknowledge must be enabled. If setnack% = 0 then acknowledge is enabled, if setnack%

=1 then acknowledge is disabled. Therefore, if a read (odd numbered) address is being sent AND only 1 Byte is to be read, setnack% should be set to = 1; in all other cases it must be clear = 0.

Value Returned:

i2cstatus%

 

The value returned depends on whether the Start and address were sent.

 

If the start and address have been sent then the status returned will either be

 

&H00 (bus busy data sent and acknowledged), or &H08 (bus busy, data sent

 

but not acknowledged).

 

If the start or the address cannot be sent (either the bus remained busy or the

 

address did not get sent) 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.BAS, this value may be altered to suit your system.

I2C status on exit

&H00 bus busy and address sent and acknowledged

 

&H08 bus busy and address sent but not acknowledged

 

&H80 bus busy and address not sent.

 

(see Appendix A for details of Status codes).

Example Usage:

(see also sample programs)

Sub main

 

slaveaddress% = &HA1

' I2C Address, this is a typical slave read address

setnack% = 0

' Enable Acknowledge (see parameter descriptions)

i2cstatus% = restart(slaveaddress%, setnack%)

trash% = readbyte(setnack%)

' read the address from the adapter and discard

End Sub

 

Issue 1.3

Page 19

22/07/99

Image 22
Contents Calibre Calibre CopyrightContents General Introduction Configuring the AdapterIntroduction Packing ListInstalling the Adapter Typical PC ConnectionPower Supply Connecting the Adapter to Your SystemConnector Pinout Bus Capacitance Limitations\C\CLIB\CPICA.LIB Software Utilities\C\CLIB\SPICA.LIB \C\CLIB\MPICA.LIB\B\SOURCE\PROMREAD.BAS DOS Qbasic Library/Programs\B\SOURCE\I2CINC.BAS \B\SOURCE\PROMWRIT.BASWindows LIB/DLL Functions Int ownaddress Using the UtilitiesRoutines Int sclkInt slaveaddress Int i2cstatusInt setnack Calibre Int i2cdata Calibre Int i2cstatus Number if the adapter is to read from the slave Sclk% Qbasic RoutinesOwnaddress% I2cstatus%Slaveaddress% Setnack% I2cdata%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 ErrCode Int wrDataSendaddress Address to be accessed via the I2C, e.g. A1H Int far *transferarray Int sendbytesint far *transferarrayInt bsent Int getbytesint far *transferarray Int nobytesreadSlave using the adapter Further Information Bit 7 MSB The Pending Interrupt Not PIN Bit Bit 4 The Bus Error BER BitAppendix a Parallel I2C Communications Adapter Status Codes Bit 6 Not UsedAppendix B Parallel I2C Communications Adapter Control Codes Question Do you have software to talk to my........? Question Get corrupted transfers why is this?Most Commonly Asked I2C Questions QuestionCode. Why? Please Email Your Query to