5.3. DLLs for Programming in Microsoft Windows 3.X Environments15
6. Further Information21
7. The Real-Time Bus Monitor22
Appendix A I
Appendix B – I
Appendix C - The Most Commonly Asked I
2
C Communications Adapter Status Codes23
2
C Communications Adapter Control Codes24
2
C Questions25
Revision 1.7
09/12/1999
Calibre UK Limited
Cornwall House, Cornwall Terrace
Bradford, West Yorkshire, BD8 7JS, England
Tel No: (01274) 394125
Fax No: (01274) 730960
Email sales@calibreuk.com
web-site www.calibreuk.com
1.Introduction
2
The I
C Communications Adapter is a half length PC interface card designed to fit any IBM PC
compatible expansion slot. Based on the Philips PCF8584 bus controller, it featur es full I
compatibility as either a master or slave. I
2
C connections are made via a 9 way “D” sock et. This product
2
C bi-directional
complies with the requirements of EEC Directive 89/336 for EMC and is CE marked.
1.1.Packing List
2
C Communications Adapter is supplied with the following items:-
Your I
A.I
2
C CD ROM
B. The ICA93 plug-in card (the actual adapter)
TO AVOID DAMAGE TO THIS PRODUCT PLEASE BE SURE TO READ PAGE 7, SECTION 5.4
BEFORE USE
Revision 1.7Page 1 of 27
09/12/1999
2.Configuring the Adapter
NOTE:MANY COMPONENTS ON THE ADAPTER CARD ARE STATIC SENSITIVE.
OBSERVE NORMAL STATIC SENSITIVE PRECAUTIONS WHEN HANDLING THE
CARD!
The adapter is supplied in a standard configuration which should suit most applications.
However, some features are link selectable. Read the following section to change the
configuration.
The standard configuration is:
base address = 0310 (Hex)
number of wait States = 1
hardware interrupts disabled
bus termination & protection off
2.1.Setting the Adapter Base Address
The card occupies a pair of PC I/O addresses and responds to input/output commands. Set the hex
starting address of this pair using LK1, LK2 and LK3 within the following range:
The standard configuration is LK1-3 at “0” giving a start address of 0310 (Hex).
2.2.Wait State Generator
Data validity is assured by delaying the PC bus using the IOCHRDY signal. The number of wait states
imposed on the PC bus is link selectable from 1 to 4 using LK4.
The card is supplied with LK4 in the “1” position, which is suitable for machines up to 10 MHz clock rate.
your machine implements dynamic speed switching on I/O channel access (as do most good
PCs), position 1 is correct no matter what its clock speed.
If a PC with a faster clock is used which does not switch speed on I/O channel access, it may be
necessary to increase the number of cycles delay to achieve the same absolute time delay.
Use the following table as a guideline for choosing the right position for your machine:
PC up to 10MHzPosition 1
PC over 10MHz, up to 16MHzPosition 2
PC over 16MHz, up to 20MHzPosition 3
PC over 20 MHzPosition 4
The best position is the minim um number of wait st ates while maintaining data security. This can easily
be found by trial and error.
The ICA93 operates correctly in all 'well behaved' faster machines. In m ost cases jus t one wait state will
be fine in even the fastest of machines. However, some rogue PCs that do not obey correct I/O tim ing
may cause problems occasionally. If you suspect this is a problem, try using the adapter in another
computer if poss ible to prove the fault. For fur ther help regarding tim ings contact your ICA93 supplier for
technical support. The standard configuration is with one Wait State selected.
If
Revision 1.7Page 2 of 27
09/12/1999
Important Note: Due to the internal operation of the ICA93, it must not be accessed ov er the PC
bus (read or written) more t han once every nine of its ow n clock cycles. The ICA93 is clocked at
12MHz; therefore it MUST NOT be accessed more than once every 0.75 microseconds. If this
requirement is not observed operation may become erratic. This is usually only encountered in
very fast PCs, however it must be borne in mind when writing software if say the system hardware
might be updated in the future. When timing problems are encountered it is invariably this which
is causing the difficulties, not the selection of the number of wait states. This is automatically
controlled by the Windows DLLs, but must be checked by the programmer when using the DOS
routines.
2.3.Interrupt Generation
The adapter is designed for either polled or interrupt driven operation. Interrupts are generated after the
2
sending or reception of any byte on the I
C Bus. The pulse is negative going with a duration of approx .
100nS, the interrupt being signalled by the rising edge of this pulse.
Link 5 allows the selection of which PC interrupt line the card is connected to:
As can be seen, the card is capable of connecting to f our out of the eight available PC I/O interrupts. T he
final choice will depend on what other peripherals are connected to the PC.
The standard configuration is with the interrupts disabled, i.e. LK5 in the “NONE” position.
2.4.Bus Termination and Protection
2
Normally the system to which the I
C Communications Adapter is to be connected should already have
master pull up resistors f itted to the SCL and SDA lines. If this is not the case, LK10 and LK12 can be
used to connect 4K7 pull up resistors to the var iable supply on these lines. The standard conf iguration is
with these resistors disconnected.
The SCL and SDA lines are protected by 100R series resistors befor e exiting the adapter via the 9 way
“D” socket. Upstream of the series resis tors, the SCL and SDA pins on the PCF8584 are pulled up with
2
high value resistors (10K). These ensure that the I
C Bus is in a defined state even if no other devices are
connected. The standard configuration is with these resistors connected using LK9 and LK11
LK13 and LK14 connect optional protection diodes to the SCL and SDL lines. When selected, these lines
are clamped to the 0V and variable supply lines giving protection against tr ansients. If these diodes are
2
connected, the external I
C system will not function if the adapter is connected but not powered up. The
standard configuration is with these diodes disconnected.
2.5.Installing the Adapter
NOTE:BEFORE INSTALLING THE ADAPTER IN YOUR PC, OBSERVE ANY SAFETY
PRECAUTIONS GIVEN BY THE MANUFACTURER OF THE COMPUTER.
NORMAL ANTI-STATIC HANDLING PRECAUTIONS SHOULD BE OBSEVED TO
AVOID ANY DAMAGE TO THE ICA93 OR THE COMPUTER.
Switch off the power to the PC and remove the mains plug from its socket before opening the case.
Plug the adapter into any available slot. Ensure the fixing screw is replaced in the com puter rear panel to
hold the adapter firmly in place.
Close the case, reconnect the mains lead and switch on the computer.
Revision 1.7Page 3 of 27
09/12/1999
3.Connecting the Adapter to your System
3.1.Connector Pinout
All external connections are made via a 9 way “D” socket:
PinNormal Mode
10V
20V
30V
40V
5NC
6SDA (Bi-directional)
7+V Variable bus voltage
8SCL (Bi-directional)
9NC
NOTE:THE PINS MARKED NC MUST NOT BE CONNECTED IN NORMAL MODE.
3.2.Normal/Long Distance Mode
The ICA93 does NOT support the 4- wire long distanc e mode which the 5V only ICA90 model can oper ate
in. This is the only incompatibility between the two models.
3.3.Bus Capacitance Limitations/Cable Choice
2
The maxim um allowable capacitance on the I
C bus in normal mode depends on the value of the SCL
and SDA master pull-ups, but never exceeds 400pF. Refer to Phillips Technical Handbook Book 4 Parts
12a and 12b for further details (s ee Section 8 - F urther Inf orm ation f or r efer ences) . Care should be tak en
in choosing a length and type of interconnecting cable, which will not exceed this limit.
2
For most systems with a distance of a few metres between the I
C Communications Adapter and the
target system, screened cable is NO T recommended, as it is lik ely to introduce too much capacitance.
However, the EMC performance of an unscreened cable is always potentially poorer than a screened
one. The Adapter's EMC perform ance even with an unscreened cable is good - but this may not be true
of the target system! If you are in any doubt at to the best way to connect up your system with EMC in
mind please contact your supplier or Calibre for advice.
3.4.Variable Voltage Bus Power Supply
Pin 7 on the “D” connector is connected to the variable bus voltage power rail. Power for external circuitr y
can be drawn from here, but care should be taken never to short it to 0V or to exceed 250mA loading. It is
short circuit and overload protected by a self-res etting thermal fuse but prolonged s horting could cause
the ICA93 to generate an excessive amount of heat inside your computer.
When shipped to you, the bus voltage was pre-set at 3.3V for use with low voltage memories. You can
adjust the voltage between 2V and 6V by inserting a small screwdriver through the hole in the card
mounting bracket. As you adjust the voltage (you can monitor it by connecting a m eter to pin 7 of the bus
connector) the bus logic levels will track, keeping at 30% / 70% of s upply for low and high level thresholds
respectively.
The Links 6, 7, and 8 are factory set to VAR and
Your ICA93 has been factory set for use on 3.3V I
MUST NOT BE MOVED.
2
C bus systems. Use on 5V I2C bus systems
without adjusting the voltage control WILL CAUSE PERMANENT DAMAGE to the IC93. The fault is
factory detectable and you WILL BE CHARGED FOR THE REPAIR.
Revision 1.7Page 4 of 27
09/12/1999
4.Getting Started
4.1.Resetting the Adapter
A reset forces the adapter into a well defined state, ready for initialisation. T he card uses the s ame reset
line as the PC so either a power up or hard reset (press the <RESET> button on your PC) will suffice.
4.2.Introduction to the Utilities
The utilities supplied with the adapter contain simple DOS routines in both C and Tur boBASIC, which can
be used for setup and basic communications. This is a list of the DOS utilities supplied:
C Library/Programs
Procedure or
File NameSubroutine NameBrief Functional Description
i2c.hsetupSets user defined initial conditions.
getstatusReads status register.
sendaddressSends slave address, data transmission mode and start signal.
sendstopSends stop signal.
writebyteWrites a byte of data to a previously specified address.
readbyteReads a byte of data from a previously specified address.
restartSends Restart and slave address of device, which is to be
communicated with, without sending a Stop.
count.cSends a counting sequence of 0 to 99 to a seven segment
display driver.
count.exeExecutable version of above.
ram.cWrites then reads back data from a series of RAM locations.
Checks for correct readback.
ram.exeExecutable version of above.
setup.cSets up typical initial conditions – Own Slave Address = AE
Procedure or
File NameSubroutine NameBrief Functional Description
i2c.incsetupSets user defined initial conditions.
FNgetstatus%Reads status register.
sendaddressSends slave address, data transmission mode and start signal.
sendstopSends stop signal.
writebyteWrites a byte of data to a previously specified address.
FNreadbyte%Reads a byte of data from a previously specified address.
restartSends restart and slave address of device which is to be
communicated with, without sending a Stop.
count.basSends a counting sequence of 0 to 99 to a seven segment
display driver.
tbcount.exeExecutable version of above.
ram.basWrites then reads back data from a series of RAM locations.
Checks for correct readback.
tbram.exeExecutable version of above.
16 bit Windows DLLs f or use with Visual Basic 3.0 and Microsoft C++1.5 are included on the dis c. See
Section 7.3 for a detailed description of the routines available. All library functions listed for the DOS
routines are covered. Additionally some extra multiple operation functions are supplied.
Revision 1.7Page 5 of 27
09/12/1999
5.Using the Utilities
Each utility is documented in a standard form at, which lists its name, usage, f unction, and effect on the
adapter is given. Following a reset, the adapter should be setup prior to any data transfer.
5.1.C Routines
2
5.1.1.I
C Setup/Initialisation Routine
Name:setup(base, own, sclk)
Usage:setup(base, own, sclk);
Function:procedure to set up I
2
C Communications Adapter.
Parameters are:
int basebase address of adapter set by links on circuit board.
int ownI
2
C address to which the adapter is to respond in slave mode. This forms the
upper 7 bits of the 8 bit address; the lowest bit being the Read (1) or Write (0) bit.
This means that if own = 0x57, the card will respond to a W rite to address 0xAE
and a Read to address 0xAF. Be sure not to selec t an address that is already in
2
use by any other device in your I
2
all I
C bus information but will not aff ect any data transfers, thus acting as a bus
C system. If own = 0x00 the adapter will monitor
monitor.
int sclkthe SCL clock rate (bit rate for I
2
C serial bus).
Value of sclkApproximate SCL (kHz)
090
145
211
31.5
Value Returned:none.
2
I
C status on exit from routine:
2
The I
C Communications Adapter will have the serial interfac e enabled; also data
reception acknowledge will be enabled. The status register will contain 0x81
(assuming that no other m asters exist on the I
then the contents of the status register will also depend on externally generated
bus activity).
Example Usage: (see also sample programs)
#include <stdio.h>
#include <dos.h>/*Optional, but recommended if your compiler */
/*supports DOS I/O functions */
2
#include <i2c.h>/*This contains the I
C routines */
main
{
int base, own, sclk;
base = 0x310;/* Adapter’s base address = 0x310 (hex) */
own = 0x57;/* Own slave address set to 0x57 (hex) */
sclk = 1;/* Serial clock rate set to 45KHz */
setup(base, own sclk);
2
printf(“I
C Communications Adapter initialised\n”);
}
/* This will set up the I
/* address of 0x310, an I
2
C Communications Adapter with a base */
2
C slave address of 0xAE and a SCL */
/* clock rate of approximately 45KHz */
5.1.2.I
2
C Status Checking Routine
2
C system, if this is not the cas e
Name:getstatus(controladdress)
Usage:status = getstatus(controladdress);
Function:function to read status register of I
2
C Communications Adapter.
Revision 1.7Page 6 of 27
09/12/1999
Parameters are:
int controladdress address of I
by links on circuit board).
Value Returned:
2
C control register. This is equal to 1+(base address of adapter s et
int <status>where status is an integer from 0x00 to 0x FF which indicates the current status
2
C Communications Adapter . See Appendix A for details of the s tatus values
of I
returned.
2
I
C status on exit from routine:
The status of the I
2
C Communications Adapter will not be affected by using the
getstatus function.
Example Usage: (see also sample programs)
#include <stdio.h.>
#include <dos.h>/*Optional, but recommended if your compiler */
/*supports DOS I/O functions */
2
#include <i2c.h>/*This contains the I
C routines */
main
{
int status, base, controladdress;
base = 0x310;/*Adapter’s base address = 0x310 (hex) */
controladdress = base + 1;
Status = getstatus (controladdress);
2
printf(“I
C Communications Adapter Status = %x\n”, status);
}
/*This will read the I
5.1.3.I
2
C Address and Start Sending Routine
2
C Communications Adapter’s current status */
Name:sendaddress (base, slv, setnack)
Usage:sendaddress(base, slv, setnack)
Function:procedure to send Start and slave address of device that is to be com munic ated
with.
Parameters are:
2
int basethe base address of the I
C Communications Adapter set by links on circuit
board.
int slvthe slave address of the device which is to be communic ated with. T his will be an
even number if the adapter is to write to the slave, add 1 to get an odd num ber if
the adapter is to read from the slave.
2
int setnackthis controls whether the I
Acknowledge down the I
2
C Bus on reception of a byte. The last byte received
C Communications Adapter transmits an
during a transfer mu st not be acknowledged, in all other cases acknowledge is
enabled, if setnack = 1 then acknowledge is disabled. T herefore, 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.
2
C status on exit from routine
I
The status of the I
2
C/ 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 */
2
#include <i2c.h>/* This contains the I
C routines */
main
Revision 1.7Page 7 of 27
09/12/1999
{
int base, slv, setnack;
base = 0x310;/* Adapter’s bas address = 0x310 (hex) */
slv = 0xa0;/* I
2
C Address of slave, this is a typical */
/* write for an I
2
C static RAM or EEPROM */
setnack = 0;/* Enable Acknowledge (see parameter */
/* descriptions) */
sendaddress(base, slv, setnack);
2
printf(“Start and I
C Slave Address sent\n”);
}
/* This will send a start and the I
2
C Slave Address of the device */
/* to be communicated with. */
5.1.4.I
2
C Read Data Byte from Slave Routine
Name:readbyte(base, setnack)
Usage:data = readbyte(base, setnack);
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.
Note: First byte read after read-address is always that address and should be discarded. This byte
should be ignored when working out when to acknowledge/not acknowledge.
Parameters are:
2
int baseThe base address of the I
C Communications Adapter set by links on circuit
board.
int setnackThis controls whether the I
Acknowledge down the I
2
C Bus on reception of a byte. The last byte received
2
C Communications Adapter transmits an
during a transfer must not be ac knowledged, in all other cas es m ust be enabled.
If setnack = 0 then acknowledge is enabled, if setnack = 1 then acknowledge is
disabled. Therefore, if the LAST BUT ONE byte is to be read, setnack should be
set to = 1; in all other cases it mu st be set = 0. (in case of reading 1 byte only,
acknowledge will have been disabled by sendaddress and so should now be
enabled again after reading the data, hence setnack = 0 for reading a single byte
of data.)
Value Returned:
int <data>The function reads the byte of data and returns an integer equal to the value
read.
2
C status on exit from routine:
I
The status of the I
2
C 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 depending on whether any more bytes of data have been
transmitted by the slave device which is being read. (See Appendix A f or details
of the 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 */
2
#include <i2c.h>/* This contains the I
C functions */
main
{
int base, setnack, data;
base = 0x310;/* Adapter’s base address = 0x310 (hex) */
setnack = 0;/* Enable acknowledge - only one byte it to */
/* be read (see parameter descriptions) */
data = readbyte(base, setnack);
printf(“Data read was %x\n”, data);
}
Revision 1.7Page 8 of 27
09/12/1999
/* 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:
2
int baseThe base address of the I
C Communications Adapter set by links on circuit
board.
int dataThe byte of data which is to be written to the slave device.
Value Returned:none.
2
C status on exit from routine:
I
The status of the I
2
C 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 */
2
#include <i2c.h>/* This contains the I
C 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. */
2
5.1.6.Send an I
C Stop Routine
Name:sendstop(controladdress)
Usage:sendstop(controladdress);
Function:procedure to send a stop (end of communication signal) down the I
ending a transmission or reception with a slave which was addressed previously
by sendaddress.
Parameters are:
2
int controladdressthe address of the I
C Communications Adapter control register, equal to
1+(base address set by links on circuit board).
Value Returned:none.
2
C status on exit from routines:
I
The status of the I
2
C/ 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 I
2
C Communications
Adapter, since this other mas ter may well have taken control of the bus by the
time a program next uses getstatus to read the status r egister. (See Appendix A
for details of Status Codes).
Example Usage:(see also sample programs)
#include <stdio.h>
Revision 1.7Page 9 of 27
09/12/1999
2
C Bus,
#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”);
2
}/* This will write a Stop to the I
5.1.7.I
2
C Restart and Address Sending Routine
C Bus */
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 m ust have their address sent as a Restart to proceed with the
read operation.
Parameters are:
2
int basethe base address of the I
C Communications Adapter set by links on the circuit
board.
int slvthe slave address of the device which is to be communic ated with. T his will be an
even number if the adapter is to write to the slave, add 1 to get an odd num ber if
the adapter is to read from the slave.
2
int setnackthis controls whether the I
down the I
2
C Bus on reception of a byte. The last byte received during a transfer
C communications Adapter trans m its an Ack nowledge
must not be acknowledged, in all other cases ac knowledge must be enabled, if
setnack = 1 then acknowledge is disabled. Therefor e, 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.
2
C status on exit from routine:
I
The status of the I
2
C/ 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 */
2
#include <12c.h>/* This contains the I
C functions */
main
{
int base, slv, setnack;
base = 0x310;/* Adapter’s base address = 0x310 (hex) */
2
slv = 0xa1;/* I
C Address of slave, this is a typical read */
/* address for an I
2
C static RAM or EEPROM */
setnack = 0;/* Enable Acknowledge (see parameter descriptions)*/
restart(base, slv, setnack);
}
5.2.TurboBASIC Routines
2
5.2.1.I
C Setup/Initialisation Routines
Revision 1.7Page 10 of 27
09/12/1999
Name:setup (baseaddr%, own%, sclk%)
Usage:call setup(baseaddr%, own%, sclk%)
Function:procedure to set up I
2
C Communications Adapter.
Parameters are:
baseaddr%base address of adapter set by links on circuit board.
own%I
2
C address to which the adapter is to respond in slave mode. This forms the
upper 7 bits of the 8 bit address, the lowest bit being the Read(1) or W rite ( 0) bit.
This means that if own% = &h57, the card will respond to a W rite to address
&hAF. Be sure not to select an address that is alr eady in use by any other device
2
in your I
C system. If own% &h00 the adapter will monitor all I2C bus information
but will not affect any data transfers, thus acting as a bus monitor
sclk%the SCL clock rate (bit rate for I
2
C serial bus).
Value of sclk%Approximate SCL (kHz)
090
145
211
31.5
Value Returned:none.
2
I
C status on exit from routine:
2
The I
C Communications Adapter will have the serial interfac e enabled, also data
reception acknowledge will be enabled. The status register will contain &h81
(assuming that no other m asters exist on the I
2
C system, if this is not the cas e
then the contents of the status register will also depend on externally generated
bus activity).
Example Usage:(see also sample programs)
2
$include “i2c.inc”‘* This contains the I
C routines*
baseaddr% = &h310‘* Adapter’s base address = &h310 (hex) *
own% = &h57‘* Own slave address set to &h57 (hex) *
sclk% = 1‘* Serial clock rate set to 45KHz *
call setup(baseaddr%, own%, sclk%)
2
C Communications Adapter initialised”
print”I
‘* This will set up the I
‘* of &h310, an I
2
C Communications Adapter with a base address *
2
C slave address of &hAE and a SCL clock rate of *
‘* approximately 45KHz *
5.2.2.I
2
C Status Checking Routine
Name:FNgetstatus%(Controladdress%)
Usage:status% = FNgetstatus%(controladdress%)
Function:function to read status register of I
2
C Communications Adapter.
Parameters are:
controladdress%address of I
2
C control register. This is equal to 1+(base address of adapter s et
by links on circuit board).
Value Returned:
<status%>where status is an integer from &h00 to &hF F which indicates the current status
2
of the I
C communica tions Adapter. Appendix A for details of the status values
returned.
2
I
C status on exit from routine:
The status of the I
2
C Communications Adapter will not be affected by using the
FNgetstatus% function.
Example Usage:(see also sample programs)
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 com munic ated
with.
Parameters are:
2
baseaddr%the base address of the I
C Communications Adapter set by links on circuit
board.
slv%the slave address of the device which is to be communic ated with. T his will be an
even number if the adapter is to write to the slave, add 1 to get an odd num ber if
the adapter is to read from the slave.
2
setnack%this controls whether the I
Acknowledge down the I
2
C Bus on reception of a byte. The last byte received
C Communications Adapter transmits an
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.
2
C Status on exit from routine:
I
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)
2
$include “i2c.inc”‘* This contains the I
C routines*
baseaddr% = &h310‘* Adapter’s base address = 0x310 (hex) *
slv% = &ha0‘* IC Address of slave, this is a typical write *
2
‘* address for an I
C static RAM or EEPROM *
setnack% = 0‘* Enable Acknowledge (see parameter descriptions) *
call sendaddress (baseaddr%, slv%, setnack%)
2
print”Start and I
‘* This will send a Start and the I
5.2.4.I
2
C Slave Address sent”
2
C Slave Address of the device to be communicated with. *
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:
2
baseaddr%the base address of the I
C Communications Adapter set by links on circuit
board.
Revision 1.7Page 12 of 27
09/12/1999
2
setnack%this controls whether the I
Acknowledge down the I
2
C Communications Adapter transmits and
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 setnac k% = 0 then ack nowledge is enabled, if setnac k% = 1
then acknowledge is disabled. Therefore, if the LAST BUT ONE byte is to be
read, setnack% should be set to =1; in all other cases it m ust be set = 0. (In the
case of reading 1 byte only, acknowledge will have been disabled by
sendaddress and so should now be enabled again after reading the data, hence
setnack% = 0 for reading a single byte of data.)
Value Returned:
<databyte%>the function reads the byte of data and returns an integer equal to the value read.
2
C status on exit from routine:
I
The status of the I
2
C/ the Communications Adapter will be either &h00 - bus the
busy and unread data in the data register or &h80 - bus busy and no unread data
in the data register depending on whether any more bytes of data have
been transmitted by the slave device which is being read. (See Appendix A for
details of Status Codes).
Example Usage:(see also sample programs)
2
$include”i2c.inc”‘* This contains the I
C routines *
baseaddr% = &h310‘* Adapter’s base address = 310 (hex) *
setnack% = 0‘* Enable Acknowledge - only one byte is to be read *
‘* (see parameter descriptions) *
databyte% = FNreadbyte%(baseaddr%, setnack%)
print “Data read was “;databyte%
‘* 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.2.5.Write Data Byte to Slave Routine
Name:writebyte(baseaddr%, databyte%)
Usage:call writebyte(baseaddr%, databyte%)
Function:procedure to write a byte of data to a slave device whose slave address has
already been sent by sendaddress.
Parameters are:
2
baseaddress%the base address of the I
C Communications Adapter set by links on circuit
board.
databyte%the byte of data which is to be written to the slave device.
Value Returned:none.
2
C status on exit from routine:
I
The status of the I
2
C Communications Adapter will be &h00 - bus busy and data
in the data register transmitted successfully. (See Appendix A for details of
Status Codes).
Example Usage:(see also sample programs)
2
$include “i2c.inc”‘* This contains the I
C routines *
baseaddr% = &h310‘* Adapter’s base address = 310 (hex) *
databyte% = &h69‘* Data byte which is to be transmitted*
call writebyte(baseaddr%, data byte%)
print”Data has been transmitted”
‘* This will write a byte of data to a slave previously addressed by sendaddress. *
Function:procedure to send a Stop (end of communication signal) down the I
ending a transmission or rec eption with a slave that was address previously by
sendaddress.
Parameters are:
2
controladdress%The address of the I
C Communications Adapter control register, equal to
1+(base address set by links on circuit board).
Value Returned:none.
2
C status on exit from routine:
I
The status of the I
2
C/ the Communications Adapter will be &h81 - 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 I
2
C Communications
Adapter, since this other mas ter may well have taken control of the bus by the
time a program next uses getstatus to read the status r egister. (See Appendix A
for details of Status Codes).
2
C Bus,
Example Usage:(see also sample programs)
2
$include “i2c.inc”‘* This contains the I
C routines*
baseaddr% = &h310‘* Adapter’s base address = 310 (hex) *
controladdress% = baseaddr% + 1‘* Control Register address *
call sendstop(controladdress%)
print”Stop has been transmitted”
2
‘* This will write a stop to the I
5.2.7.I
2
C Restart and Address Sending Routine
C Bus*
Name:restart(baseaddr%, slv% setnack%)
Usage:call restart(baseaddr%, 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 the 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 then have their read address sent with a Restart to
proceed with the read operation.
Parameters are:
2
baseaddr%the base address of the I
C Communications Adapter set by links on circuit
board.
slv%the slave address of the device which is to be communic ated with. T his will be an
even number if the 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.
2
setnack%this controls whether the I
Acknowledge down the I
2
C Bus on reception of a byte. The last byte received
C Communications Adapter transmits an
during a transfer must not be acknowledged, in all other cases acknowledge
must be enabled. If setnac k% = 0 then ack nowledge is enabled, if setnac k% = 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.
2
C status on exit from routine:
I
The status of the I
2
C/ the Communications Adapter will be either &h00 - bus the
busy and unread data in the data register or &h80 - bus busy and no unread data
in the data register when a Restart and Salve Address have been succ essfully
transmitted (see Appendix A for details of Status Codes).
Example Usage:
2
$include “i2c.inc”‘* This contains the I
C routines*
baseaddr% = &h310‘* Adapter’s base address = 310 (hex) *
Revision 1.7Page 14 of 27
09/12/1999
2
slv% = &ha1‘* I
C Address of slave, this is a typical read address *
‘* for an I
2
C static RAM or EEPROM*
setnack% = 0‘* Enable Acknowledge (see parameter descriptions) *
call restart(baseaddr%, slv%, setnack%)
2
print”Restart and I
‘* This will send a Restart and the I
C Slave Address sent”
2
C Slave Address of the device to *
5.3.DLLs for Programming in Microsoft Windows 3.X Environments
5.3.1.Files
\readme.docUser Information
\c\i2inc.h“C” function prototypes
2
\c\cali2c.libI
C “C” library
\vb30\cali2c.basVisual Basic 3.0 declarations
\vb30cali2c.dllI
2
C Visual Basic dynamic link library
C functions
– Function Prototypes
The following function prototypes are required by the DLL, these are defined in the file I2CINC.H
Void far_pascal_export setup (int baseaddress, int ownaddress, int sclk, int statuswait);
int far_pascal_export sendaddress (int sendaddress, int setnack);
int far_pascal_export restart (int slaveaddress, int setnack);
int far_pascal_export getstatus (void);
int far_pascal_export writebyte (int wrData);
int far_pascal_export readbyte (int setnack);
int far_pascal_export sendstop (void);
int far_pascal_export recover (void);
int far_pascal_export sendbytes (int_far *transferarray);
int far_pascal_export getbytes (int_far *transferarray);
void far_pascal_export slavelastbyte (void);
To ensure the prototypes are added correctly copy the file I2CINC.H into the directory containing your
project and add the line: #include “I2CINC.H”
Remember to add the library CALI2C.LIB to your project make file.
Visual Basic 3.0 function
Add the file CALI2.BAS to your project, this contains the declarations for the procedures within the DLL.
If the DLL is not in the root directory change the path to the DLL to suit your system.
The sendbytes and getbytes functions pass the transfer array to the DLL by reference, the following
example indicates how to do this:
ReDim transferarray (0 to 258) ‘remember 3 locations are required for the slave write and word
addresses so array allows 256 bytes of data.
transferarray (0) = &HA0‘slave write address.
transferarray (1) = &H00‘slave word address.
Transferarray (2) = 256‘the number of bytes.
Bytes_sent = sendbytes(transferarray(0))
DLL function descriptions
– Applies to both C++ and Visual Basic
setup
Function specificationVoid setup(int baseaddress, int ownaddress, int sclk, int statuswait)
Revision 1.7Page 15 of 27
09/12/1999
baseaddress is the address at which the adapter has been ins talled, e.g.
310H
ownaddress I2C address to which the adapter is to respond in slave
mode. This forms the upper 7 bits of the 8 bit address, the lowest bit
being the read (1) or write (0) bit. This means that if ownaddress = 57H
the card will respond to a write address of AEH and a read address of
AFH.
Statuswait is a period of time (in micr oseconds) to wait for the required
bus status. If this tim e-out expires the I
2
C functions will exit returning an
error code.
sclk is clock rate (bit rate for the I
2
C serial bus) when operating as a
master.
Value of sclkApproximate SCL-kHz
090
145
211
31.5
Parameters returnednone.
Prerequisitesnone.
Functional descriptionThis function characterises the PC and initialises adapter ready for I
2
transfers.
sendaddress
Functional specificationInt sendaddress (int slaveaddress, int setnack)
slaveaddress is the address to be accessed via the I2C, e.g. A0H
setnack 1 for no acknowledge 0 for acknowledge – see Functional
Description
Parameters returnedErrCode. If the transfer time out occurs error code 8001H is returned
otherwise the status is returned.
C
Prerequisitesadapter must be configures by running
setup.
Functional descriptionThe function waits for the bus to be free. Then sends the slave addres s
with the appropriate acknowledge.
The acknowledge is set ready for the data tr ansfer af ter the addres s and
hence in read mode (odd address being sent) if only one byte is to be
read the setnack param eter m ust equal 1. If m ore than one byte is to be
read or if in write mode (even address being sent) then setnack must
equal 0.
writebyte
Function specificationInt writebyte (int wrData)
wrData is the byte of data to be written.
Paramteres returnedErrCode. If the transfer time out occurs error code 8004H is returned
otherwise the status is returned.
PrerequisitesAdapter must be configur ed using
setup,
start and write address sent by
sendaddress.
Functional descriptionThe function writes the data to the adapter and then waits for it to be
sent. Should a time-out occur dur ing the sending of the data then error
code 8004H is returned, otherwise the status is returned. Writebyte is
compatible with both master write and slave write modes.
readbyte
Function specificationInt readbyte (int setnack)
Revision 1.7Page 16 of 27
09/12/1999
Parameters returnedI
Setnack 1 for no acknowledge 0 for acknowledge.
2
Cdata, the data read, if a time-out occurs the ErrCode 8005H is
returned.
PrerequisitesAdapter must be configur ed using
setup,
start and read address sent by
sendaddress.
Functional DescriptionIf setnack is 1 the function writes 40H to the control register to es tablish
the correct acknowledge procedure. The data is read from the adapter.
IMPORTANT: SETNACK MUST = 1 WHEN READING THE LAST AND
THE LAST BUT ONE BYTES IN A SEQUENCE OF BYTES
SETNACK MUST = 0 FOR ALL OTHER READS. IF THIS FORMAT IS
NOT STRICTLY FOLLOWED THEN THE ADAPTER AND BUS WILL
NOT OPERATE CORRECTLY.
WHEN READING ANOTHER I2C DEVICE THE FIRST BYTE READ
USING THE READBYTE FUNCTION IS ALWAYS THE SLAVE
ADDRESS OF THAT DEVICE. THIS MUST BE READ AND
DISCARDED BEFORE THE REAL DATA CAN BE READ. DO NOT
COUNT THIS EXTRA READ WHEN CONSIDERING WHETHER OR
NOT TO ACKNOWLEDGE.
Should a time-out occur then an error code 8005H is r eturned, otherwise
the data is returned. Readbyte is compatible with both mast er read and
slave read modes.
sendstop
Function specificationInt sendstop ( )
Parameters returnedErrCode. If the transfer time out occurs error code 8002H is returned
otherwise the status is returned.
PrerequisitesAdapter must be configur ed using
setup.
Should normally only be used
at the end of transmission. Correct acknowledge sequence must have
been applied if the transmission was a read.
Functional descriptionInstruct the adapter to send a stop code and wait for it to be sent. Should
a time-out occur during the s ending of a stop then an error code 8002H
is returned, otherwise the status is returned.
restart
Function specificationInt restart (int slaveaddress, int setnack)
Slaveaddress is the address to be accessed via the I2C, e.g. A1H
Setnack 1 for no acknowledge 0 for acknowledge – see Functional
Description.
Parameters returnedErrCode. If the transfer time out occurs error code 8003H is returned
otherwise the status is returned.
PrerequisitesAdapter must be configur es us ing
have previously been sent using
setup.
sendaddress.
A start and slave address must
Usually a data pointer
would already have been written using writebyte.
Functional descriptionSends a start code and the slave address specified and presets the
acknowledge status depending on the value of setnack. The
acknowledge is set ready for the data transfer after the address and
hence in read mode (odd address being sent) if only one byte is to be
read the setnack param eter m ust equal 1. If m ore than one byte is to be
read or if in write mode (even address being sent) then setnack must
equal 0.
The function waits for the addres s to be sent. Should a time-out occ ur
during the sending of an address then an error code 8003H is returned,
otherwise the status is returned.
Revision 1.7Page 17 of 27
09/12/1999
getstatus
Function specification:Int getstatus ( )
2
Parameters returnedI
Cstatus, the current value of the bus status.
PrerequisitesAdapter must be configured using
setup.
Functional descriptionThe function reads status word from the adapter and returns it.
recover
Function specification:Int recover
Parameters returnedErrCode. If the bus recovery failed error code 8006H is returned
otherwise the status is returned.
PrerequisitesAdapter must be configured using
setup.
Functional descriptionThis function issues two consecutive stop com mands on the bus, with a
delay in between. It then clears the adapter registers and reads the
status. This should normally set the adapter into a known idle state when
a bus error or other problem has occurred.
If the status does not indicate bus f ree or the Bus Err or bit is s till s et then
8006H is returned otherwise the status is returned.
sendbytes
Function specificationInt sendbytes (int far *transferarray)
The far pointer must point to a single dim ensional ar ray the format of which is detailed below. The calling
function must have initialised elements 0, 1 and 2 prior to calling the function.
Element noElement nameDescription
0slaveaddress
Slaveaddress is the address to be acces sed via the I
2
C
Bus, this is in hexadecimal e.g. A0H.
1wordaddressWordaddress is the offset within the slave to which the
first byte of data is to be written, see transmission form at
for more details.
2nobytesThe number of bytes (n) to be sent. Min value 1.
3byte 0First byte to be sent.
“
“
byte nLast byte to be sent.
Parameters returnedbsent, the number of bytes actually sent.
PrerequisitesAdapter must be configured using
Array elements 0, 1 and 2
setup.
must be initialised. Usually elements 3 to n would also be initialised.
Array must be pre-defined to a size at least large enough to hold all the
parameters and data concerned.
Transmission formatThere are two transmission formats, these are:
i. start-slaveaddress-byte(s)-stop
If transmission format i.) is required set the wordaddress to a number greater than FFH.
ii. start-slaveaddress-wordaddress-byte(s)-stop
If transmission format ii.) is required set the wordaddress to a number less than or equal to FFH.
Functional descriptionThe function determines the required transmission format and then
sends a start code and the slave address. If transm ission format ii) has
been selected the wordaddress is sent.
The data bytes are then transmitted sequentially.
Should a time-out occur or he slave not acknowledge a transfer the
transmission is terminated by a stop and the number of bytes actually
transmitted is returned.
Revision 1.7Page 18 of 27
09/12/1999
When all the bytes have been transm itted a stop is issued and the total
number of bytes is returned.
Sendbytes can only be used in master write mode.
getbytes
Function specificationInt getbytes (int far *transferarray)
The far pointer must point to a single dimensional array the format of which is detailed below.
The calling function must have initialised elements 0, 1 and 2 prior to calling the function.
Element noElement nameDescription
0Slaveaddress
Slaveaddress is the address to be accessed via the I
2
C
Bus, this is in hexadecimal e.g. A0H.
1Wordaddr essWordaddres s is the offset within the slave to which the
first byte of data is to be written, see transmission
format for more detail.
2NobytesThe number of bytes (n) to be sent. Min value 1.
3byte 0First byte read.
“
“
byte nLast byte read.
Parameters returnednobytesread, the number of bytes actually read.
PrerequisitesAdapter must be configured using
Array elements 0, 1 and 2
setup.
must be initialised. Elements 3 to n do not need to be initialised since
they are where the read data is returned. Array must be pre-defined to a
size at least large enough to hold all the parameters and data concerned.
Transmission formatIf the slaveaddress has the least significant but set ( 1) then this form s a
read address, if the least significant bit is clear (0) then this forms the
write address e.g. A0H is the write address and A1H is the as sociated
read address.
Getbytes supports two transfer formats these being:
i. start-slavereadaddress-byte(s)-stop
To select transfer format i.) pass the read address as slave address.
The wordaddress is not used in this format and is ignored by getbytes.
ii. start-slavewriteaddress-wordaddress-restart-slavereadaddress-byte(s)-stop
To select transfer format ii.) pass the write address as slaveaddress.
In this format the wordaddress must be valid.
Wordaddress is a pointer to the first byte of data to be read.
Nobytestoread is the number of bytes to be read. The minimum value allowable is 1.
Functional descriptionThe function determines the required transmission transfer format,
sends the appropriate sequence of start(s) and slave address(es) and
checks for acknowledges where necessary.
If the slave fails to ack nowledge then a stop is sent and nobytesread is
returned equal to 0.
The first data byte read is the slave read address sent(see readbyte
description). This is dis c ar ded, it is not r etur ned in the trans f er arr ay. The
data bytes are then read and stored in the transfer array. At the
appropriate point acknowledges are ceased – for the last and the last but
one byte to be transferred.
A stop is sent after the last byte has been read. On completion the
number of bytes read is returned.
Should a time-out occur the transfer is terminated by a stop and the
number of bytes successfully read is returned.
Revision 1.7Page 19 of 27
09/12/1999
Getbytes can only be used in master read mode.
slavelastbyte
Function specificationvoid slavelastbyte( )
Parameters returnednone.
PrerequisitesAdapter must be configur ed using
This function would normally
setup.
only be called following the end of a transmission in s lave write mode –
when the adapter is being read as a slave, by another master, not when
writing to a slave using the adapter.
Functional descriptionThis function is used when the adapter is a slave being read by a master
elsewhere on the bus – the adapter is in slave write mode. T he function
must be called im mediately after the master indicates the last byte has
been read (by not acknowledging that byte) this function is required to
clear the I
2
C data lines so that the master can send a stop signal.
Revision 1.7Page 20 of 27
09/12/1999
6.Further Information
The following references may be found useful when using the adapter:
Philips Semiconductors Technic al Handbook Book 4 Parts 12a and 12b. These give details of the
I2C compatible ICs, and the I
2
C Bus specification. The PCF8584P used on the adapter is
included in later editions. Where the data sheet and this m anual disagree, this manual should
always be followed when using the adapter.
Philips Components Data Sheet for PCF8584
2
Philips Application Note No EIE/AN90001 - Interfacing PCF8584 I
C bus controller to 80(C) 51
family micro contro llers. T his gives som e us eful c ode but is not written direc tly for the PC. Please
note - the hardware information on the PCF8584 given in this application note sometimes
contradicts the data sheet referenced in 8.2, ingeneral the data sheet is correct; the only
exception is that a Stop should be sent as c3 (H ex) - as shown in the application, not 43 (hex) implied in the data sheet ) see Appendix B of this manual f or details of control c odes). W here in
doubt, follow this manual.
Revision 1.7Page 21 of 27
09/12/1999
7.The Real-Time Bus Monitor
The program REALTIM1.EXE in the MONTOR directory is a completely non-invasive real-time bus
monitor which records ac tivity on an I
file. This file can be printed out or examined with a word-process or as required. The m onitor can record
up to 30,000 operations on the I
2
C-bus.
2
C-bus, post-processes the data and s tores the results in an ASCII
For the real-time m onitor to work correctly it must be run using an 8MHz 286 AT type computer or any
faster machine ( 386/486 are ideal). Also, no TSR programs or background applications m ust be active
while running the monitor.
The monitor program can write quite large data files to disc; it must be copied from the floppy disc
supplied onto your hard disc before being executed.
The monitor program has to run very fast and without interruptions in order to ac c urately recor d data f r om
2
C-bus. To achieve this it re-vectors the normal BIOS k eyboard and clock-tick interr upt routines and
the I
uses these for its own purposes. It is essential that the monitor program is exited cleanly – this is
achieved by pressing any alphanumeric key on the keyboard while it is monitoring; the monitor pr ogram
will restore the normal interrupts when it finishes.
Do not attempt to run the real-time monitor from any version of Windows
The following mnemonics are used by the monitor program in the ASCII file which it produces.
SaXXStart code followed by address, acknowledged.
SnXXStart code followed by address, not acknowledged.
DaXXData byte, acknowledged.
DnXXData byte, not acknowledged.
STOPStop code.
BUS ERRORA bus error has occurred. This is non-fatal to the m onitor but a small am ount of
data may have been lost whilst recovery was taking place.
Note:The program REALTIM1 expects the ICA93 adapter to be configured as supplied (i.e. default
base address, no interrupts). If this is not the case please r ef er to Sect ion 3 of the User Manual f or details
of the correct link pos itions. T he one exc eption is the bus pull- ups. T hese m ay be on or off on the ICA93;
bus terminations must be present somewhere on the bus for it to operate. The alternative program,
REALTIM2 is identical except it is for an ICA93 configured with an alternative base address of 0x312.
Revision 1.7Page 22 of 27
09/12/1999
Appendix A I
2
C Communications Adapter Status Codes
This is an eight bit register, read using the getstatus routine. Each individual bit has its own meaning as
follows:
Bit 7 (MSB) - The PIN Bit
The PIN bit “Pending Interrupt Not” is a read-only flag which is used to synchronize serial com munication.
Each time a serial data transmission is initiated (by sendaddress routine or setting STA bit) the PIN will be
set (= 1) automatically. After successful transmission of one byte (9 clock pulses, inc luding acknowledge),
this bit will be automatically reset (= 0) indicating a complete transmission. When the ENI bit (enable
interrupt) is also set, the PIN triggers an exter nal interrupt via the selected IRQ line when PIN is reset.
When in receiver m ode, the PIN is also reset on com pletion of each r eceived byte. In polled applications,
the PIN bit is tested (using the getstatus routine) to determine when a serial transmission has been
completed. In receiver m ode, the PIN bit is tested (using the readbyte func tion). W hen the PIN becom es
set all other status bits will be reset, with the exception of the BB (not Bus Busy) bit.
In short, when transmitting data, if PIN = 0 then the data has been sent, if PIN = 1 then it has not. W hen
receiving data, if PIN = 0 then there is unread received data ready to read, if PIN = 1 then either the data
received has already been read, or no data has yet been received.
Bit 6 - Not Used
This bit is not currently used and will always = 0.
Bit 5 - The STS Bit
2
When in slave- receiver mode (i.e. transm ission initiated by a master elsewhere on the I
C bus), the flag
STS = 1 when an externally generated Stop condition is detected, otherwise STS = 0. This flag is used
only in slave-receiver mode.
Bit 4 - The BER Bit
The BER (Bus Error) bit. BER = 1 when a misplaced Start or Stop has been detected, otherwise BER = 0.
2
This can be quite serious sinc e the I
C devices on the bus may be left in an undefined state after a bus
error has occurred - in s ome circum stances the only way to get the bus going again may be to reset all
2
the I
C devices on it.
Bit 3 - The LRB/ADO Bit
The LRB (Last received Bit) / ADO ( Address 0 “General Call” Addr ess Received) bit. T his dual function
2
status bit holds the value of the last received bit over the I
C bus when AAS (Bit 2) = 0. Normally this will
be the value of the slave acknowledge; thus check ing for slave acknowledgem ent is done via testing of
the LRB bit. When AAS (Bit 2) = 1 (“ Addressed As Slave”), the I
2
C Communications Adapter has been
addressed as a slave and the ADO bit will = 1 if the slave address received was the “General Call”
address. For further inf ormation on the “General Call” Address, see the Philips data book s referenced in
Section 8 of this User Manual.
Bit 2 - The AAS Bit
The AAS (“Addressed As Slave”) bit. When acting as a slave-receiver, this flag is set = 1 when an
2
incoming address over the I
C bus matches the value defined by the setup routine, or if the slave addr ess
received was the I2C bus “General Call” address (00 Hex). In all other circumstances, AAS = 0.
Bit 1 - The LAB Bit
The LAB (Lost Arbitration) bit. This bit is set = 1 when, in m ultimaster operation (m ore than one master
2
present on the I
C bus) arbitration is lost to another master on the I2C bus. In all other circumstanc es,
LAB = 0.
Bit 0 - The BB Bit
2
The BB (not Bus Busy) bit. This is a read- only flag indicating when the I
that the bus is busy, and access is not possible (unless of course it is busy because the I
C bus is in use. BB = 0 indicates
2
Communications Adapter itself has control of the bus). This bit is set = 1 by Stop conditions and reset = 0
by Start conditions. In short, BB = 1 means that the bus is free and a new transmission can be started.
Revision 1.7Page 23 of 27
09/12/1999
C
Appendix B – I
2
C Communications Adapter Control Code s
The Control Register should norm ally be written using the setup, sendaddress and s endstop routines. To
implement more advanced functions such as enabling hardware interrupt generation or implementing
long distance mode, these routines may need to be modified or the users own routines used in their
place.
The Control Register is accessed by writing to I/O address:
1+Base address of card (set by links on board).
The Data Register is accessed by writing to I/O address:
Base address of card (set by links on board).
2
E.g. in C, outp(0x311, 0xc3); would cause an I
generate a Stop condition on the I
2
C bus. For detailed information on thes e codes, the Philips data sheet
C Communications Adapter with base address = 0x310 to
on the PCF8584 device (see Section 8, Further Information)
0x00read/write own address register (followed by a data byte to the data register).
0x20read/write clock register (followed by a data byte to the data register).
After either of the above operations, 0x41 must be written to the control register to re-enable the I
2
interface.
0xc3send a Stop signal over the I
0x41I
2
C NOP (no operation) instruction, acknowledge enabled.
2
C bus.
(Use 0x41 and 0x40 to turn on and off acknowledge)
C
0x45( While bus is fr ee) - Send Start & slave address, ack nowledge enabled. The address to
be sent must have first been written to the data register before sending the startcode.
0x45( W hile already master on the bus) - Send Repeated Start & slave address (Restart). T he
address to be sent is placed in the data register after sending the start code.
0x47s end Stop, Start, slave address (i.e. restart trans mission without releasing control of the
2
I
C bus). The address to be sent is placed in the data register after sending the start
code.
To execute the last four instructions with acknowledge disabled, i.e. negative ack nowledge - nack, set;
send the control code-1, e.g. 0x40, 0x44, 0x46.
Revision 1.7Page 24 of 27
09/12/1999
Appendix C - The Most Commonly Asked I
2
C Questions
General Questions
QuestionWill my adapter work in a Pentium PC?
Answer Yes and there is no need to alter LK 4 from the position in which your adapter was shipped.
QuestionWill my adapter run I2C clock speeds greater than 90KHz?
Answer At the moment your adapter is limited by the Bus Controller chip f itted, to a maximum of 90KHz
as a master and 100KHz as a slave.
QuestionWill my adapter work under Windows NT4* or Windows 95*?
AnswerThe adapter will work under both these systems without problems, but the software
supplied with the adapter is 16 bit only. Windows NT and Windows 95 DLLs are available
please contact our sales team for further information.
The bus monitors are best run from DOS (not Windows DOS Shell) as this minimises the risk of
missing part of a transfer.
* All trade marks acknowledged
QuestionHow can I find out if the adapter is clashing with another card in my PC?
AnswerIf your adapter is located at a base address of 310H (as shipped) then run the bus
monitor (REALTIM1) application supplied following the instructions in the adapter
manual. W ith no activity on the bus the monitor should display a fix 'A', st op the monitor
and edit the file produced if the file states that the bus was free and the status was 81H
then your adapter is indeed located at 310H and there are no clashes within the PC.
If your adapter is at 312H then repeat the above using the REALTIM2 bus monitor.
QuestionI get corrupted transfers why is this?
AnswerThe most likely reason for corrupted transfers is either incorrect bus termination or
excessive capacitance - see the manual for details.
QuestionDo you have software to talk to my........?
AnswerUnfortunately there are too many I2C devices for us to be able to offer complete solutions
- although we can supply a windows based application called W INI2C which is designed
for those just starting I2C or wishing to perform simple I2C tasks, please contact our
sales team or look on our web site, www.calibreuk.com for further information.
QuestionI am trying to read from a device, the first time my software w orks fine but w hen I
try again I can't get anything what's wrong?
AnswerPlease check that you are changing the value of Setnack in accordance with the m anual,
it is likely that you have not made Setnack 1 for the last
last but one bytes being
AND
read.
DOS Software Questions
QuestionMy I2C adapter locks up with a constant status - why?
AnswerIf you are using either the 'C' or Basic library functions supplied with the adapter on a f as t
PC it is possible that the PC is polling the status register too quic kly, the simplest way to
prevent this is to add a small delay prior to reading the status in the getstatus routine.
Alternatively use the windows DLL supplied as these automatically allow for speed of the
PC at run-time.
Windows 95 and NT Questions
QuestionMy software cannot find the adapter. Your Windows software reports that it cannot
configure the adapter. Why is this?
AnswerHave you registered the device driver as detailed in the software manual? If so check that
the address links (see adapter manual for details) ar e correct for the location at which
you registered the driver.
QuestionI think I have registered the driver how can I find out if I have?
AnswerYou need to inspect the registry as follows
Revision 1.7Page 25 of 27
09/12/1999
Windows 95 START - Run regedit
HKEY_LOCAL_MACHINE
|
|--SYSTEM
|
|--CurrentControlSet
|
|--Services
|
|--Class
Windows NT START - Run regedit
HKEY_LOCAL_MACHINE
|
|--SYSTEM
|
|--CurrentControlSet
|
|--Services
|
|--WinRT
|
|--WinRT
|
|--WinRTdev0
|
|--Parameters
|--Section0
|--Section1
|
|--WinRTdev0
|
|--Parameters
|--Section0
|--Section1
QuestionI am using your Windows 95 / NT DLL and I am always getting a time out error
code. Why?
AnswerCheck the Syntax of the setup function, swapping the Status Wait and Sc lk parameters
most usually causes this problem.
The correct syntax is i2cstatus = setup (baseaddress, ownaddress, sclk, statuswait)
QuestionI have read the manual and still cannot get the communications to run. What do I
do next?
AnswerCheck that you have fully im plemented the protocol between the adapter and the other
I2C devices see the device manufacturers data sheet for details.
Check that the software you have written is logically and syntactically correct - this is
probably the most common cause of software faults we have to deal with.
Send us the following details:-
1)The link settings of the adapter.
2)A sketch of the relevant I2C hardware including the location of bus termination.
3)The type and speed of processor within your PC and which operating system,
you are running.
4)Brief software listings, or which Calibre software you are running.
5)The serial number of your I2C adapter, or when you purchased it.
PLEASE EMAIL YOUR QUERY TO:techsupport@calibreuk.com
OR FAX YOUR QUERY TO:44-1274-730960
We will endeavour to help you.
Revision 1.7Page 26 of 27
09/12/1999
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.