Projekte
workwind
BGX1 firmware
i2c.h
Projekte
Forum
Doku
Öffentliche Projekte
Startseite
Beispielprogramme
Projekte von anderen
Welcome
Username
Passwort
Eingeloggt bleiben
Zugangsdaten vergessen?
Registrieren
Projektverwaltung
⇨ Please choose! ⇦
——————————————————
✎ Create new project...
★ Browse existing projects...
——————————————————
⚬ MotorTest#1
⚬ C Tutorial 8#1
⚬ NIBO2 C Project#1
⚙ C Tutorial 15#1
⚬ 2010_11_18_el_test001#1
BGX1 firmware
adc.c
adc.h
battery.xbm
bgx1_protocol.h
Biene.xbm
display.c
display.h
exclamation.xbm
gfx.c
gfx.h
i2c.c
i2c.h
i2cconf.h
images.c
images.h
iodefs.h
iodefs_bgx1.h
main.c
MarsRover.xbm
Nase.xbm
nicai_logo.xbm
pwm.c
pwm.h
question.xbm
smily1.xbm
smily2.xbm
Project details
Compiler settings
Nachrichten
Sie sind nicht eingeloggt.
Neuigkeiten
★
NiboRoboLib 3.6
2017-01-17: Neue Version 3.6
★
NiboRoboLib 3.4.1
2016-04-16: Neue Version 3.4.1
★
Coding Tutorial
2015-11-22: Jetzt auch für den NIBO burger!
Site-Statistic
7433 private projects
378 public projects
16180353 lines compiled
58212 builds
NIBO
@
bgx1_firmware/i2c.h [read only]
/*! \file i2c.h \brief I2C interface using AVR Two-Wire Interface (TWI) hardware. */ //***************************************************************************** // // File Name: 'i2c.h' // Title: I2C interface using AVR Two-Wire Interface (TWI) hardware // Author: Pascal Stang - Copyright (C) 2002-2003 // Modified: Nils Springob 2010 // // This code is distributed under the GNU Public License // which can be found at http://www.gnu.org/licenses/gpl.txt // /// \ingroup driver_avr /// \defgroup i2c I2C Serial Interface Function Library (i2c.c) /// \code #include "i2c.h" \endcode /// \par Overview /// This library provides the high-level functions needed to use the I2C /// serial interface supported by the hardware of several AVR processors. /// The library is functional but has not been exhaustively tested yet and is /// still expanding. Thanks to the standardization of the I2C protocol and /// register access, the send and receive commands are everything you need to /// talk to thousands of different I2C devices including: EEPROMS, Flash memory, /// MP3 players, A/D and D/A converters, electronic potentiometers, etc. /// /// \par About I2C /// I2C (pronounced "eye-squared-see") is a two-wire bidirectional /// network designed for easy transfer of information between a wide variety /// of intelligent devices. Many of the Atmel AVR series processors have /// hardware support for transmitting and receiving using an I2C-type bus. /// In addition to the AVRs, there are thousands of other parts made by /// manufacturers like Philips, Maxim, National, TI, etc that use I2C as /// their primary means of communication and control. Common device types /// are A/D & D/A converters, temp sensors, intelligent battery monitors, /// MP3 decoder chips, EEPROM chips, multiplexing switches, etc. /// /// I2C uses only two wires (SDA and SCL) to communicate bidirectionally /// between devices. I2C is a multidrop network, meaning that you can have /// several devices on a single bus. Because I2C uses a 7-bit number to /// identify which device it wants to talk to, you cannot have more than /// 127 devices on a single bus. /// /// I2C ordinarily requires two 4.7K pull-up resistors to power (one each on /// SDA and SCL), but for small numbers of devices (maybe 1-4), it is enough /// to activate the internal pull-up resistors in the AVR processor. To do /// this, set the port pins, which correspond to the I2C pins SDA/SCL, high. /// For example, on the mega163, sbi(PORTC, 0); sbi(PORTC, 1);. /// /// For complete information about I2C, see the Philips Semiconductor /// website. They created I2C and have the largest family of devices that /// work with I2C. /// /// \Note: Many manufacturers market I2C bus devices under a different or generic /// bus name like "Two-Wire Interface". This is because Philips still holds /// "I2C" as a trademark. For example, SMBus and SMBus devices are hardware /// compatible and closely related to I2C. They can be directly connected /// to an I2C bus along with other I2C devices are are generally accessed in /// the same way as I2C devices. SMBus is often found on modern motherboards /// for temp sensing and other low-level control tasks. // //***************************************************************************** #ifndef I2C_H #define I2C_H //#include "global.h" #include <stdint.h> // include project-specific configuration #include "i2cconf.h" // types typedef enum { I2C_IDLE = 0, I2C_BUSY = 1, I2C_MASTER_TX = 2, I2C_MASTER_RX = 3, I2C_SLAVE_TX = 4, I2C_SLAVE_RX = 5 } eI2cStateType; // functions //! Initialize I2C (TWI) interface void i2c_init(void); //! Set the I2C transaction bitrate (in KHz) void i2c_setBitrate(uint16_t bitrateKHz); // I2C setup and configurations commands //! Set the local (AVR processor's) I2C device address void i2c_setLocalDeviceAddr(uint8_t deviceAddr, uint8_t genCallEn); //! Set the user function which handles receiving (incoming) data as a slave void i2c_setSlaveReceiveHandler(void (*i2cSlaveRx_func)(uint8_t receiveDataLength, uint8_t* recieveData)); //! Set the user function which handles transmitting (outgoing) data as a slave void i2c_setSlaveTransmitHandler(uint8_t (*i2cSlaveTx_func)(uint8_t transmitDataLengthMax, uint8_t* transmitData)); // Low-level I2C transaction commands //! Send an I2C start condition in Master mode void i2c_sendStart(void); //! Send an I2C stop condition in Master mode void i2c_sendStop(void); //! Wait for current I2C operation to complete void i2c_waitForComplete(void); //! Send an (address|R/W) combination or a data byte over I2C void i2c_sendByte(uint8_t data); //! Receive a data byte over I2C // ackFlag = TRUE if recevied data should be ACK'ed // ackFlag = FALSE if recevied data should be NACK'ed void i2c_receiveByte(uint8_t ackFlag); //! Pick up the data that was received with i2cReceiveByte() uint8_t i2c_getReceivedByte(void); //! Get current I2c bus status from TWSR uint8_t i2c_getStatus(void); // high-level I2C transaction commands //! send I2C data to a device on the bus void i2c_masterSend(uint8_t deviceAddr, uint8_t length, uint8_t *data); //! receive I2C data from a device on the bus void i2c_masterReceive(uint8_t deviceAddr, uint8_t length, uint8_t* data); //! send I2C data to a device on the bus (non-interrupt based) uint8_t i2c_masterSendNI(uint8_t deviceAddr, uint8_t length, uint8_t* data); //! receive I2C data from a device on the bus (non-interrupt based) uint8_t i2c_masterReceiveNI(uint8_t deviceAddr, uint8_t length, uint8_t *data); //! Get the current high-level state of the I2C interface eI2cStateType i2c_getState(); #endif
Compiler results:
Werbung
Online
lincolngreenwood0