Raspberry Pi GPIO Library  0.3
Library allowing for control of the Raspberry Pi's GPIO pins.
Functions | Variables
i2c.c File Reference

Contains C source for the I2C functionality. More...

#include "i2c.h"

Go to the source code of this file.

Functions

errStatus gpioI2cSetup (void)
 Initial setup of I2C functionality. More...
 
errStatus gpioI2cCleanup (void)
 Disables the I2C controller and unmaps the memory used for the i2c functionality. This function should be called when finished with the I2C module. More...
 
errStatus gpioI2cSet7BitSlave (uint8_t slaveAddress)
 Sets the 7-bit slave address to communicate with. More...
 
errStatus gpioI2cWriteData (const uint8_t *data, uint16_t dataLength)
 Writes data to the address previously specified by gpioI2cSet7BitSlave(). More...
 
errStatus gpioI2cReadData (uint8_t *buffer, uint16_t bytesToRead)
 Read a number of bytes from I2C. The slave address should have been previously set with gpioI2cSet7BitSlave(). More...
 
errStatus gpioI2cSetClock (int frequency)
 Sets the I2C Clock Frequency. More...
 

Variables

static volatile uint32_t * gI2cMap = NULL
 Pointer which will be mmap'd to the I2C memory in /dev/mem.
 
static int i2cByteTxTime_ns
 The time it takes ideally transmit 1 byte with current I2C clock.
 

Detailed Description

Contains C source for the I2C functionality.

This is is part of https://github.com/alanbarr/RaspberryPi-GPIO a C library for basic control of the Raspberry Pi's GPIO pins. Copyright (C) Alan Barr 2012

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file i2c.c.

Function Documentation

◆ gpioI2cCleanup()

errStatus gpioI2cCleanup ( void  )

Disables the I2C controller and unmaps the memory used for the i2c functionality. This function should be called when finished with the I2C module.

Returns
An error from errStatus.
Examples:
i2c_example_bitexpander.c, i2c_example_eeprom.c, and i2c_example_temp_sensor.c.

Definition at line 156 of file i2c.c.

◆ gpioI2cReadData()

errStatus gpioI2cReadData ( uint8_t *  buffer,
uint16_t  bytesToRead 
)

Read a number of bytes from I2C. The slave address should have been previously set with gpioI2cSet7BitSlave().

Parameters
[out]bufferA pointer to a user defined buffer which will store the bytes.
bytesToReadThe number of bytes to read.
Returns
An error from errStatus.
Examples:
i2c_example_eeprom.c, and i2c_example_temp_sensor.c.

Definition at line 348 of file i2c.c.

◆ gpioI2cSet7BitSlave()

errStatus gpioI2cSet7BitSlave ( uint8_t  slaveAddress)

Sets the 7-bit slave address to communicate with.

This value can be set once and left if communicating with the same device.

Parameters
slaveAddress7-bit slave address.
Returns
An error from errStatus.
Examples:
i2c_example_bitexpander.c, i2c_example_eeprom.c, and i2c_example_temp_sensor.c.

Definition at line 217 of file i2c.c.

◆ gpioI2cSetClock()

errStatus gpioI2cSetClock ( int  frequency)

Sets the I2C Clock Frequency.

Note
The desired frequency should be in the range: I2C_CLOCK_FREQ_MIN <= frequency <= I2C_CLOCK_FREQ_MAX.
Parameters
frequencyDesired frequency in Hertz.
Returns
An error from errStatus
Examples:
i2c_example_eeprom.c.

Definition at line 465 of file i2c.c.

◆ gpioI2cSetup()

errStatus gpioI2cSetup ( void  )

Initial setup of I2C functionality.

gpioSetup() should be called prior to this.

Returns
An error from errStatus.
Examples:
i2c_example_bitexpander.c, i2c_example_eeprom.c, and i2c_example_temp_sensor.c.

Definition at line 36 of file i2c.c.

◆ gpioI2cWriteData()

errStatus gpioI2cWriteData ( const uint8_t *  data,
uint16_t  dataLength 
)

Writes data to the address previously specified by gpioI2cSet7BitSlave().

Parameters
[in]dataPointer to the start of data to transmit.
dataLengthThe length of data.
Returns
errStatus An error from errStatus
Examples:
i2c_example_bitexpander.c, i2c_example_eeprom.c, and i2c_example_temp_sensor.c.

Definition at line 243 of file i2c.c.