'' ================================================================================================= '' '' File....... jm_i2c.spin '' Purpose.... Low-level I2C routines (requires pull-ups on SCL and SDA) '' Author..... Jon "JonnyMac" McPhalen '' Copyright (c) 2009-2020 Jon McPhalen '' -- see below for terms of use '' -- elements inspired by code from Mike Green & Chris Gadd '' E-mail..... jon.mcphalen@gmail.com '' Started.... 28 JUL 2009 '' Updated.... 16 NOV 2019 '' '' ================================================================================================= ' IMPORTANT Note: This code requires pull-ups on the SDA _and_ SCL lines -- it does not drive ' the SCL line high. con { fixed io pins } RX1 = 31 ' programming / terminal TX1 = 30 SDA1 = 29 ' eeprom / i2c SCL1 = 28 con #0, ACK, NAK var long sclpin ' bus pins long sdapin long sclmask pub null '' This is not a top-level object pub setup '' Setup I2C using Propeller EEPROM pins setupx(SCL1, SDA1) pub setupx(_scl, _sda) '' Define I2C SCL (clock) and SDA (data) pins longmove(@sclpin, @_scl, 2) ' copy pins dira[sclpin] := 0 ' float to pull-up outa[sclpin] := 0 ' write 0 to output reg dira[sdapin] := 0 outa[sdapin] := 0 sclmask := |