Calibre UK ICA93LV user manual Write Data Byte to Slave Routine, Send an I2C Stop Routine

Page 10

/* This will read a byte of data from a slave previously addressed */ /* by and with acknowledge already disabled by sendaddress. */ /* After reading the data, acknowledge will be re-enabled. */

5.1.5.Write Data Byte to Slave Routine

Name:

writebyte(base, data)

Usage:

writebyte(base, data)

Function:

procedure to write a byte of data to a slave device whose slave address has

 

already been sent by sendaddress.

Parameters are:

 

int base

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

 

board.

int data

The byte of data which is to be written to the slave device.

Value Returned:none.

 

I2C status on exit from routine:

 

The status of the I2C Communications Adapter will be 0x00 - bus busy and data

 

in the data register transmitted successfully. (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 <i2c.h>

/* This contains the I2C routines */

main

 

{

 

int base, data;

 

base = 0x310;

/* Adapter’s base address = 0 x 310- (hex) */

data = 0x69;

/* Data byte which is to be transmitted */

writebyte (base, data) ;

printf(“Data has been transmitted\n”);

}

/* This will write a byte of data to a slave previously addressed */ /* by sendaddress. */

5.1.6.Send an I2C Stop Routine

Name:

sendstop(controladdress)

Usage:

sendstop(controladdress);

Function:

procedure to send a stop (end of communication signal) down the I2C Bus,

 

ending a transmission or reception with a slave which was addressed previously

 

by sendaddress.

Parameters are:

 

int controladdress

the address of the I2C Communications Adapter control register, equal to

 

1+(base address set by links on circuit board).

Value Returned:none.

 

I2C status on exit from routines:

 

The status of the I2C/ the Communications Adapter will be 0x81 - bus idle and no

 

unread/untransmitted data in the data register. Note - this may not be the case in

 

a system where there is another master as well as the I2C Communications

 

Adapter, since this other master may well have taken control of the bus by the

 

time a program next uses getstatus to read the status register. (See Appendix A

 

for details of Status Codes).

Example Usage:

(see also sample programs)

#include <stdio.h>

 

Revision 1.7

Page 9 of 27

09/12/1999

 

Image 10
Contents Contents ICA93LVIntroduction Packing ListSetting the Adapter Base Address Configuring the AdapterWait State Generator Installing the Adapter Bus Termination and ProtectionVariable Voltage Bus Power Supply Connecting the Adapter to your System Connector PinoutNormal/Long Distance Mode Bus Capacitance Limitations/Cable ChoiceLibrary/Programs Getting Started Resetting the AdapterIntroduction to the Utilities 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 Write Data Byte to Slave Routine Send an I2C Stop RoutineTurboBASIC Routines 1. I2C Setup/Initialisation Routines 7. I2C Restart and Address Sending Routine2. I2C Status Checking Routine 3. I2C Address and Start Sending Routine Write Data Byte to Slave Routine 7. I2C Restart and Address Sending Routine Setup Visual Basic 3.0 functionSendaddress Sendstop SendaddressRestart Getstatus SendbytesGetbytes Slavelastbyte Further Information BUS Error Real-Time Bus MonitorBit 6 Not Used Appendix a I2C Communications Adapter Status CodesBit 7 MSB The PIN Bit Bit 5 The STS BitAppendix B I2C Communications Adapter Control Codes Question Do you have software to talk to my........? DOS Software QuestionsHkeylocalmachine System