/* ---------------------------------------------------------------------------- * Copyright (c) 2012, 2013 Ben Blazak * Released under The MIT License (see "doc/licenses/MIT.md") * Project located at * ------------------------------------------------------------------------- */ /** description * Very simple implementation for the Teensy 2.0 (ATmega32U4) * * - This is mostly straight from the datasheet, section 20.6.6, figure 20-11 * (the code example in C), and section 20.8.1, figure 20-12 * - Also see the documentation for `` at * * * Some other (more complete) TWI libraries for the Teensy 2.0 (and other Atmel * processors): * - [i2cmaster] (http://homepage.hispeed.ch/peterfleury/i2cmaster.zip) * - written by [peter-fleury] (http://homepage.hispeed.ch/peterfleury/) * - [the arduino twi library] * (https://github.com/arduino/Arduino/tree/master/libraries/Wire/utility) * - look for an older version if you need one that doesn't depend on all * the other Arduino stuff */ #include #include "../twi.h" // ---------------------------------------------------------------------------- /** macros/OPT__TWI__FREQUENCY/description * Implementation notes: * - The max speed for the ATmega32U4 is 400kHz (datasheet sec. 20.1) * - The max speed for the MCP23017 is 1.7MHz (datasheet pg. 1) * - The max speed for the MCP23018 is 3.4MHz (datasheet pg. 1) */ #if OPT__TWI__FREQUENCY > 400000 #error "OPT__TWI__FREQUENCY must be <= 400000" #endif // ---------------------------------------------------------------------------- void twi__init(void) { // set the prescaler value to 0 TWSR &= ~( (1<