Calibre UK ICA93LV user manual 3. I2C Address and Start Sending Routine

Page 13

baseaddr% = &h310 ‘* adapter’s base address = 0x310 (hex) * controladdress% = baseaddr% + 1

status% = FNgetstatus%(controladdress%)

print”I2C Communications Adapter Status = “;status%

‘* This will read the I2C Communications Adapter’s current status *

5.2.3.I2C 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 I2C 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 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 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.

 

I2C Status on exit from routine:

 

The status of the I2C 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 I2C routines*

baseaddr% = &h310

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

slv% = &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) *

call sendaddress (baseaddr%, slv%, setnack%) print”Start and I2C Slave Address sent”

‘* This will send a Start and the I2C Slave Address of the device to be communicated with. *

5.2.4.I2C 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 I2C Communications Adapter set by

links on circuit

 

board.

 

Revision 1.7

Page 12 of 27

09/12/1999

 

Image 13
Contents ICA93LV ContentsPacking List IntroductionSetting the Adapter Base Address Configuring the AdapterWait State Generator Bus Termination and Protection Installing the AdapterNormal/Long Distance Mode Connecting the Adapter to your System Connector PinoutVariable Voltage Bus Power Supply Bus Capacitance Limitations/Cable ChoiceIntroduction to the Utilities Getting Started Resetting the AdapterLibrary/Programs TurboBASIC Library/ProgramsRoutines 1. I2C Setup/Initialisation Routine Using the Utilities2. I2C Status Checking Routine 3. I2C Address and Start Sending Routine 4. I2C Read Data Byte from Slave Routine Send an I2C Stop Routine Write Data Byte to Slave Routine7. I2C Restart and Address Sending Routine TurboBASIC Routines 1. I2C Setup/Initialisation Routines2. I2C Status Checking Routine 3. I2C Address and Start Sending Routine Write Data Byte to Slave Routine 7. I2C Restart and Address Sending Routine Visual Basic 3.0 function SetupSendaddress Sendstop SendaddressRestart Sendbytes GetstatusGetbytes Slavelastbyte Further Information Real-Time Bus Monitor BUS ErrorBit 7 MSB The PIN Bit Appendix a I2C Communications Adapter Status CodesBit 6 Not Used Bit 5 The STS BitAppendix B I2C Communications Adapter Control Codes DOS Software Questions Question Do you have software to talk to my........?Hkeylocalmachine System