Calibre UK PICA93LV user manual Qbasic Routines, Ownaddress%, Sclk%, I2cstatus%

Page 17

CALIBRE

￿

￿

4.3.QBASIC Routines

4.3.1.I2C Setup/Initialisation Routines

Function definition:

setup (ownaddress as integer, sclk as integer)

Usage

call setup(ownaddress as integer, sclk as integer)

Function:

procedure to set up Parallel I2C Communications Adapter.

Parameters are:

ownaddress%

 

 

I2C address to which the adapter is to respond in slave mode. This forms the

 

upper 7 bits of the 8 bit address, the lowest bit being the Read(1) or Write (0)

 

bit. This means that if ownaddress% = &h57, the card will respond to a Write

 

to address &hAF. Be sure not to select an address which is already in use by

 

any other device in your I2C system. If ownaddress% &h00 the adapter will

 

monitor all I2C bus information but will not affect any data transfers, thus

 

acting as a bus monitor.

 

 

sclk%

 

 

the SCL clock rate (bit rate for I2C serial bus).

 

Value of sclk%

Approximate SCL (KHz)

 

0

90

 

1

45

 

2

11

 

3

1.5

Value Returned:

none.

 

I2C status on exit:

I2C status on exit from routine the Parallel I2C Communications Adapter will

 

have the serial interface enabled, also data reception acknowledge will be

 

enabled. The status register will contain 0x81 (assuming that no other

 

masters exist on the I2C system, if this is not the case then the contents of

 

the status register will also depend on externally generated bus activity).

Example Usage:

(see also sample programs)

'This will set up the Parallel I2C Communications Adapter with an I2C slave address of &HAE and a SCL clock rate of approximately 45KHz

sub main

ownaddress% = &h57 ' Own slave address set to &h57 (hex)

sclk% = 1

' Serial clock rate set to 45KHz

call setup(ownaddress%, sclk%)

print"Parallel I2C Communications Adapter initialised"

end sub

4.3.2.I2C Status Checking Routine

Function definition:

getstatus%()

Usage:

I2Cstatus% = getstatus

Function:

function to read status register of Parallel I2C Communications Adapter.

Parameters are:

None.

Value Returned:

i2cstatus%

 

where i2cstatus is an integer from &H00 to &HFF which indicates the current

 

status of the PICA93LV.

Issue 1.3

Page 14

22/07/99

Image 17
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 setnack Int i2cstatusInt slaveaddress 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 statuswait Libraries for Programming in Microsoft Windows EnvironmentsInt baseaddress Int wrData Int ErrCodeSendaddress Address to be accessed via the I2C, e.g. A1H Int bsent Int sendbytesint far *transferarrayInt far *transferarray 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