/*Optional, but recommended if your compiler */ /*supports DOS I/O functions */
/*This contains the I2C routines */

Parameters are:

 

int controladdress

address of I2C control register. This is equal to 1+(base address of adapter set

 

by links on circuit board).

Value Returned:

 

int <status>

where status is an integer from 0x00 to 0xFF which indicates the current status

 

of I2C Communications Adapter. See Appendix A for details of the status values

 

returned.

I2C status on exit from routine:

The status of the I2C Communications Adapter will not be affected by using the getstatus function.

Example Usage: (see also sample programs) #include <stdio.h.>

#include <dos.h>

#include <i2c.h> main

{

int status, base, controladdress;

base = 0x310;/*Adapter’s base address = 0x310 (hex) */ controladdress = base + 1;

Status = getstatus (controladdress);

printf(“I2C Communications Adapter Status = %x\n”, status);

}

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

5.1.3.I2C Address and Start Sending Routine

Name:

sendaddress (base, slv, setnack)

Usage:

sendaddress(base, slv, setnack)

Function:

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

 

with.

Parameters are:

 

int base

the base address of the I2C Communications Adapter set by links on 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 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 set = 0.

Value Returned:none.

 

I2C status on exit from routine

 

The status of the I2C/ the Communications Adapter will be either 0x00 - bus busy

 

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

 

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 <stdio.h>

 

#include <dos.h>

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

 

/* compiler supports DOS I/O functions */

#include <i2c.h>

/* This contains the I2C routines */

main

 

Revision 1.7

Page 7 of 27

09/12/1999

 

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