Wixel SDK
Functions | Variables
i2c.h File Reference
#include <cc2511_types.h>

Go to the source code of this file.

Functions

void i2cSetFrequency (uint16 freqKHz)
 
void i2cSetTimeout (uint16 timeoutMs)
 
void i2cStart (void)
 
void i2cStop (void)
 
BIT i2cWriteByte (uint8 byte)
 
uint8 i2cReadByte (BIT nack)
 

Variables

uint8 DATA i2cPinScl
 
uint8 DATA i2cPinSda
 
BIT i2cTimeoutOccurred
 

Detailed Description

The i2c.lib library provides a basic software (bit-banging) implementation of a master node for I2C communication (the CC2511 does not have a hardware I2C module). This library does not support multi-master I2C buses.

By default, the SCL pin is assigned to P1_0, the SDA pin is assigned to P1_1, and the bus frequency is 100 kHz with a 10 ms timeout.

Definition in file i2c.h.

Function Documentation

uint8 i2cReadByte ( BIT  nack)

Reads a byte from the I2C bus (performs a master receive).

Parameters
nackIf 1, a NACK will be sent to the slave device instead of an ACK after this byte is received. (This is used to signal conclusion of a transfer from the slave to the master.)
Returns
The byte received from the slave device. This return value is not meaningful if a timeout occurs during the read transaction (indicated by the i2cTimeoutOccurred flag).

Definition at line 217 of file i2c.c.

void i2cSetFrequency ( uint16  freqKHz)

Sets the I2C bus clock frequency. This implementation limits the range of possible frequencies to 2-500 kHz; because of rounding inaccuracies and timing constraints, the actual frequency might be lower than the selected frequency, but it is guaranteed never to be higher. The default frequency is 100 kHz. Common I2C speeds are 10 kHz (low speed), 100 kHz (standard), and 400 kHz (high speed).

Parameters
freqKHzFrequency in kHz.

Definition at line 35 of file i2c.c.

void i2cSetTimeout ( uint16  timeoutMs)

Sets the allowed delay before a low SCL line causes an I2C bus timeout, which aborts the I2C transaction and sets the i2cTimeoutOccurred flag. The default timeout is 10 ms.

Parameters
timeoutMsTimeout in milliseconds.

Definition at line 48 of file i2c.c.

void i2cStart ( void  )

Generates an I2C START condition.

Definition at line 111 of file i2c.c.

void i2cStop ( void  )

Generates an I2C STOP condition.

Definition at line 93 of file i2c.c.

BIT i2cWriteByte ( uint8  byte)

Writes a byte to the I2C bus (performs a master transmit).

Parameters
byteThe byte to be transmitted.
Returns
0 if an ACK is received from the slave device, 1 if a NACK is received. This return value is not meaningful if a timeout occurs during the write transaction (indicated by the i2cTimeoutOccurred flag).

Definition at line 190 of file i2c.c.

Variable Documentation

uint8 DATA i2cPinScl

Number of the pin to use as the SCL (clock) line of the I2C bus. See the gpio.h documentation for pin number values.

Definition at line 16 of file i2c.c.

uint8 DATA i2cPinSda

Number of the pin to use as the SDA (data) line of the I2C bus. See the gpio.h documentation for pin number values.

Definition at line 17 of file i2c.c.

BIT i2cTimeoutOccurred

This bit is a flag that is set whenever a timeout occurs on the I2C bus waiting for the SCL line to go high. The flag must be manually cleared after being read. The i2cSetTimeout() function can be used to specify the timeout delay.

Definition at line 29 of file i2c.c.