Calibre UK ICA93LV user manual 7. I2C Restart and Address Sending Routine

Page 11
int base, slv, setnack; base = 0x310;
slv = 0xa1;

#include <dos.h>

/* Optional, but recommended if your compiler */

 

/* supports DOS I/0 functions */

#include <i2c.h>

/* This Contains the I2C routines */

main

 

 

{

 

 

int base, controladdress;

 

base = 0x310;

 

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

controladdress = base + 1;

/* Control Register address */

sendstop(controladdress);

 

printf(“Stop has been transmitted\n”); }/* This will write a Stop to the I2C Bus */

5.1.7.I2C Restart and Address Sending Routine

Name:

restart(base, slv, setnack)

Usage:

restart(base, slv, setnack)

Function:

Procedure to send a Restart and the slave address of device that is to be

 

communicated with, without a Stop having been sent at the end of 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 have their address sent as a Restart to proceed with the

 

read operation.

Parameters are:

 

int base

the base address of the I2C Communications Adapter set by links on the circuit

 

board.

int 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.

int 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 = 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/ the Communications Adapter will be either 0x00 - bus the

 

busy and

unread data in the data register or 0x80 - bus busy and no

 

unread data in the data register when a Restart and Slave Address have been

 

successfully transmitted (see Appendix A for details of status codes).

Example Usage:

(see also sample programs)

#include <stdio.h>

 

 

#include <dos.h>

/* Optional, but recommended if your compiler */

 

/* supports DOS I/O functions */

#include <12c.h>

/* This contains the I2C functions */

main

 

 

{

 

 

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

/* I2C Address of slave, this is a typical read */ /* address for an I2C static RAM or EEPROM */

setnack = 0;/* Enable Acknowledge (see parameter descriptions)*/ restart(base, slv, setnack);

}

5.2.TurboBASIC Routines

5.2.1.I2C Setup/Initialisation Routines

Revision 1.7

Page 10 of 27

09/12/1999

 

Image 11
Contents ICA93LV ContentsPacking List IntroductionWait State Generator Configuring the AdapterSetting the Adapter Base Address Bus Termination and Protection Installing the AdapterBus Capacitance Limitations/Cable Choice Connecting the Adapter to your System Connector PinoutNormal/Long Distance Mode Variable Voltage Bus Power SupplyTurboBASIC Library/Programs Getting Started Resetting the AdapterIntroduction to the Utilities Library/Programs2. I2C Status Checking Routine Using the UtilitiesRoutines 1. I2C Setup/Initialisation 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 Restart SendaddressSendstop Sendbytes GetstatusGetbytes Slavelastbyte Further Information Real-Time Bus Monitor BUS ErrorBit 5 The STS Bit Appendix a I2C Communications Adapter Status CodesBit 7 MSB The PIN Bit Bit 6 Not UsedAppendix B I2C Communications Adapter Control Codes DOS Software Questions Question Do you have software to talk to my........?Hkeylocalmachine System