Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ltc2991_test by
LT_I2C.h
00001 00002 /*! 00003 LT_I2C: Routines to communicate with ATmega328P's hardware I2C port. 00004 00005 REVISION HISTORY 00006 $Revision: 3659 $ 00007 $Date: 2015-07-01 10:19:20 -0700 (Wed, 01 Jul 2015) $ 00008 00009 Copyright (c) 2013, Linear Technology Corp.(LTC) 00010 All rights reserved. 00011 00012 Redistribution and use in source and binary forms, with or without 00013 modification, are permitted provided that the following conditions are met: 00014 00015 1. Redistributions of source code must retain the above copyright notice, this 00016 list of conditions and the following disclaimer. 00017 2. Redistributions in binary form must reproduce the above copyright notice, 00018 this list of conditions and the following disclaimer in the documentation 00019 and/or other materials provided with the distribution. 00020 00021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00022 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00023 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00024 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 00025 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00026 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00027 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00028 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00029 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 00032 The views and conclusions contained in the software and documentation are those 00033 of the authors and should not be interpreted as representing official policies, 00034 either expressed or implied, of Linear Technology Corp. 00035 00036 The Linear Technology Linduino is not affiliated with the official Arduino team. 00037 However, the Linduino is only possible because of the Arduino team's commitment 00038 to the open-source community. Please, visit http://www.arduino.cc and 00039 http://store.arduino.cc , and consider a purchase that will help fund their 00040 ongoing work. 00041 */ 00042 00043 /*! @file 00044 @ingroup LT_I2C 00045 Library Header File for LT_I2C: Routines to communicate with ATmega328P's hardware I2C port. 00046 */ 00047 00048 #ifndef LT_I2C_H 00049 #define LT_I2C_H 00050 00051 #include <stdint.h> 00052 //#include <Wire.h> 00053 00054 //! @name HARDWARE I2C PRESCALER VALUES 00055 //! @{ 00056 #define HARDWARE_I2C_PRESCALER_1 0 00057 #define HARDWARE_I2C_PRESCALER_4 1 00058 #define HARDWARE_I2C_PRESCALER_16 2 00059 #define HARDWARE_I2C_PRESCALER_64 3 00060 //! @} 00061 00062 //! @name I2C READ and WRITE BITS 00063 //! @{ 00064 //! Eighth bit (LSB) of I2C address indicates a "read" or "write". 00065 //! (The first seven bits are the 7-bit I2C address.) 00066 #define I2C_READ_BIT 0x01 00067 #define I2C_WRITE_BIT 0x00 00068 //! @} 00069 00070 //! @name STATUS BITS 00071 //! @{ 00072 #define STATUS_START 0x08 00073 #define STATUS_REPEATED_START 0x10 00074 #define STATUS_ADDRESS_WRITE_ACK 0x18 00075 #define STATUS_ADDRESS_WRITE_NACK 0x20 00076 #define STATUS_WRITE_ACK 0x28 00077 #define STATUS_WRITE_NACK 0x30 00078 #define STATUS_ARBITRATION_LOST 0x38 00079 #define STATUS_ADDRESS_READ_ACK 0x40 00080 #define STATUS_ADDRESS_READ_NACK 0x48 00081 #define STATUS_READ_ACK 0x50 00082 #define STATUS_READ_NACK 0x58 00083 //! @} 00084 00085 //! @name TIMEOUT AND DELAY IN US 00086 //! @{ 00087 #define HW_I2C_DELAY 1 00088 #define HW_I2C_TIMEOUT 20000 00089 //! @} 00090 00091 //! @name ACK OR NACK PARAMETER PASSED TO I2C_READ 00092 //! @{ 00093 #define WITH_ACK 0 //!< Use with i2c_read(WITH_ACK) to read with an acknowledge 00094 #define WITH_NACK 1 //!< Use with i2c_read(WITH_NACK) to read without an acknowledge. Normally used after the last byte of a multi-byte read. 00095 //! @} 00096 00097 //! @name OPTIONAL I2C Address MACRO 00098 //! @{ 00099 #define I2C_8ADDR(address) (address >> 1) //!< Use to convert an 8-bit I2C address to 7 bits. 00100 //! @} 00101 00102 #include "mbed.h" 00103 00104 class LT_I2C { 00105 private: 00106 I2C *i2c; 00107 PinName sda; 00108 PinName scl; 00109 00110 public: 00111 LT_I2C(); 00112 LT_I2C(PinName sda_, PinName scl_); 00113 00114 //! Read a byte of data at register specified by "command", store in "value" 00115 //! @return 0 on success, 1 on failure 00116 int8_t i2c_read_byte_data(uint8_t address, //!< 7-bit I2C address 00117 uint8_t command, //!< Command byte 00118 uint8_t *value //!< Byte to be read 00119 ); 00120 00121 //! Write a byte of data to register specified by "command" 00122 //! @return 0 on success, 1 on failure 00123 int8_t i2c_write_byte_data(uint8_t address, //!< 7-bit I2C address 00124 uint8_t command, //!< Command byte 00125 uint8_t value //!< Byte to be written 00126 ); 00127 00128 //! Read a 16-bit word of data from register specified by "command" 00129 //! @return 0 on success, 1 on failure 00130 int8_t i2c_read_word_data(uint8_t address, //!< 7-bit I2C address 00131 uint8_t command, //!< Command byte 00132 uint16_t *value //!< Word to be read 00133 ); 00134 00135 //! Write a 16-bit word of data to register specified by "command" 00136 //! @return 0 on success, 1 on failure 00137 int8_t i2c_write_word_data(uint8_t address, //!< 7-bit I2C address 00138 uint8_t command, //!< Command byte 00139 uint16_t value //!< Word to be written 00140 ); 00141 }; 00142 #endif // LT_I2C_H
Generated on Wed Jul 13 2022 18:29:42 by
