Doxtest  1
i2c.c File Reference

I2C Bus Master Driver Implementation. More...

Go to the source code of this file.

Macros

Delay Macros

These macros must be adjusted to the actual target hardware.

#define delay_1us()   { _nop(); _nop(); }
 Delay execution for 1us. More...
 
#define delay_2us()   { delay_1us(); delay_1us(); }
 Delay execution for 2us. More...
 
I/O Port Access Macros

These macros must be adjusted to the actual target hardware.

#define set_sda(state)
 Set SDA Output State. More...
 
#define get_sda()   IO_I2C_SDA
 Read SDA Input State. More...
 
#define set_scl(state)
 Set SCL Output State. More...
 
Bit Transfer Macros

The bit transfer operations are implemented as macros to reduce the call overhead.

#define write_bit(databit)
 Output a bit. More...
 
#define read_bit(databit)
 Read a bit. More...
 

Functions

Public Functions

Documentation is found in module header

void i2c_start (void)
 
void i2c_stop (void)
 
bool i2c_write (uint8 data)
 
uint8 i2c_read (ack_t ack)
 

Detailed Description

I2C Bus Master Driver Implementation.

Customer: Source Graphics

Project: Cafissimo 1B

Controller: Holtek HT46x232

Compiler: Holtek C 2.02

Created: 02.09.2005 Peter Horn, Micropool GmbH

Copyright: (C) Micropool GmbH

Id:
i2c.c 288 2006-02-22 14:43:47Z Peter Horn

Definition in file i2c.c.

Macro Definition Documentation

#define delay_1us ( )    { _nop(); _nop(); }

Delay execution for 1us.

Definition at line 45 of file i2c.c.

#define delay_2us ( )    { delay_1us(); delay_1us(); }

Delay execution for 2us.

Definition at line 48 of file i2c.c.

#define set_sda (   state)
Value:
( \
state ? \
(DIR_I2C_SDA = DIR_INPUT, _nop(), 0) : \
(IO_I2C_SDA = LOW, DIR_I2C_SDA = DIR_OUTPUT, 0) \
)

Set SDA Output State.

Parameters
statePin state 0: Low, 1: Hi-Z

Implements the target dependent method to set the SDA line.

Definition at line 70 of file i2c.c.

#define get_sda ( )    IO_I2C_SDA

Read SDA Input State.

Returns
Current level at the SDA pin

Definition at line 83 of file i2c.c.

#define set_scl (   state)
Value:
( \
state ? \
(OUT_I2C_SCL = HIGH, 0) : \
(OUT_I2C_SCL = LOW, 0) \
)

Set SCL Output State.

Parameters
statePin state 0: Low, 1 High

Implements the target dependent method to set the SCL line.

Definition at line 93 of file i2c.c.

#define write_bit (   databit)
Value:
{ \
set_sda(databit); \
set_scl(HIGH); \
delay_2us(); \
set_scl(LOW); \
}

Output a bit.

Parameters
databitValue of bit to output
Timing diagram
                 _______
SCL  ___________/  2us  
     _______ ______________
SDA  _______X______________
Precondition
SCL must be LOW

Definition at line 128 of file i2c.c.

#define read_bit (   databit)
Value:
{ \
set_sda(HIGH); \
set_scl(HIGH); \
databit = get_sda(); \
set_scl(LOW); \
}

Read a bit.

Parameters
databitlvalue to receive the read bit (e.g. name of a variable)
Timing diagram
          _______
SCL  ____/  2us  
     _ __________ __
SDA  _X__________X__
 
              ^- Sampling Point
Precondition
SCL must LOW
Postcondition
IO_SDA is Hi-Z

Definition at line 155 of file i2c.c.