Calibre UK IC Communication Adapter ICA93LV User Manual

Page 13

Advertising
background image

Revision 1.7

Page 12 of 27

09/12/1999

baseaddr% = &h310

‘* adapter’s base address = 0x310 (hex) *

controladdress% = baseaddr% + 1
status% = FNgetstatus%(controladdress%)
print”I

2

C Communications Adapter Status = “;status%

‘* This will read the I

2

C Communications Adapter’s current status *

5.2.3.

I

2

C Address and Start Sending Routine

Name:

sendaddress(baseaddr%, slv%, setnack%)

Usage:

call sendaddress(baseaddr%, slv%, setnack%)

Function:

procedure to send Start and slave address of device that is to be communicated
with.

Parameters are:

baseaddr%

the base address of the I

2

C Communications Adapter set by links on circuit

board.

slv%

the slave address of the device which is to be 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 I

2

C Communications Adapter transmits an

Acknowledge down the I

2

C 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 must be 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 set = 0.

Value Returned:none.

I

2

C Status on exit from routine:

The status of the I

2

C Communications Adapter will be either &h00 - bus busy and

unread data in data register or &h80 - bus busy and no unread data in data
register when a Start and Slave Address have been successfully transmitted (see
Appendix A for details of status codes).

Example Usage:

(see also sample programs)

$include “i2c.inc”

‘* This contains the I

2

C routines*

baseaddr% = &h310

‘* Adapter’s base address = 0x310 (hex) *

slv% = &ha0

‘* IC Address of slave, this is a typical write *
‘* address for an I

2

C static RAM or EEPROM *

setnack% = 0

‘* Enable Acknowledge (see parameter descriptions) *

call sendaddress (baseaddr%, slv%, setnack%)
print”Start and I

2

C Slave Address sent”

‘* This will send a Start and the I

2

C Slave Address of the device to be communicated with. *

5.2.4.

I

2

C Read Data Byte from Slave Routine

Name:

FNreadbyte%(baseaddr%, setnack%)

Usage:

databyte% = FNreadbyte%(baseaddr%, 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:

baseaddr%

the base address of the I

2

C Communications Adapter set by

links on circuit

board.

Advertising