HELP - Interrfacing to I2C Chips using Basic_I2C_Driver
hawkeye89736
Posts: 6
Hello,
I am still fairly new to the Propeller Chip and the Spin language, but have used the Basic chip. I am working on a model railroad project trying to control LED indications of track turnout switches (using DPDT switches generating 5v signals for input to microcontroller). I am going to be using Microchip's MCP23008 I/O expander to give me the neccessary I/Os for this project (52 I/Os total). This IC uses the I2C protocol and right now I am trying to "play" with controlling the EEPROM using the Basic_I2C_Driver from the OBEX. I can't seem to get the test program I am writing to read the EEPROM. I will attach my code below. As I said, I am farily new to the Spin language, but I think I am using either the I2C driver wrong, or the serial terminal wrong (using serial terminal to display what is read). Can anyone help me figure out what is going wrong? I am using the Parallax P8X32A QuickStart board. If you would like to know what I am planning to do for the whole project, let me know and maybe we can find a better solution. I have a few lines commented out due to trying different methods. It seems like I am pulling some information using the read command, but it does not change when the Write data is changed. Also, when I review the driver, it looks like there is nothing in the read/writebyte subs that send the data to the I2C bus.
Thanks,
Josh
I am still fairly new to the Propeller Chip and the Spin language, but have used the Basic chip. I am working on a model railroad project trying to control LED indications of track turnout switches (using DPDT switches generating 5v signals for input to microcontroller). I am going to be using Microchip's MCP23008 I/O expander to give me the neccessary I/Os for this project (52 I/Os total). This IC uses the I2C protocol and right now I am trying to "play" with controlling the EEPROM using the Basic_I2C_Driver from the OBEX. I can't seem to get the test program I am writing to read the EEPROM. I will attach my code below. As I said, I am farily new to the Spin language, but I think I am using either the I2C driver wrong, or the serial terminal wrong (using serial terminal to display what is read). Can anyone help me figure out what is going wrong? I am using the Parallax P8X32A QuickStart board. If you would like to know what I am planning to do for the whole project, let me know and maybe we can find a better solution. I have a few lines commented out due to trying different methods. It seems like I am pulling some information using the read command, but it does not change when the Write data is changed. Also, when I review the driver, it looks like there is nothing in the read/writebyte subs that send the data to the I2C bus.
Thanks,
Josh
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 eepromAddress = $7000 VAR byte buffer[32] byte wtf OBJ i2c : "Basic_I2C_Driver_1.spin" pst : "Parallax Serial Terminal.spin" 'PRI readIt ' if i2c.ReadPage(i2c#BootPin, i2c#EEPROM, eepromAddress, @buffer, 32) ' abort ' an error occurred during the read 'PRI writeIt | startTime ' if i2c.WritePage(i2c#BootPin, i2c#EEPROM, eepromAddress, @buffer, 32) ' abort ' an error occured during the write ' startTime := cnt ' prepare to check for a timeout ' repeat while i2c.WriteWait(i2c#BootPin, i2c#EEPROM, eepromAddress) ' if cnt - startTime > clkfreq / 10 ' abort ' waited more than a 1/10 second for the write to finish PUB Main wtf := 0 i2c.Initialize(28) ' i2c.Start(28) ' i2c.WritePage(28,%1010,%000,$7333,1) i2c.Writebyte(28,%111,$11,%01010111) 'i2c.WriteWait(28,%1010,%000) 'wtf := i2c.ReadPage(28,%1010,%000,$7333,1) wtf := i2c.ReadByte(28,%000,$12) '6C 'i2c.Stop(28) pst.Start(115200) repeat waitcnt(clkfreq + cnt) pst.Str(String ("test")) pst.Str(wtf) pst.NewLine waitcnt(clkfreq + cnt) pst.NewLine
Comments
Also, when you post code please wrap it in [noparse] [/noparse] tags.
Hi hawkeye89736 ...
Last year I bought a couple of the MCP23008 IC's, and wrote a rudimentary object for it.
No problem.
I didn't. The original I2C driver was modified by James Burrows, and he added a couple extra methods (and modified a couple of other ones) . The extra methods are used in my objects. Mike Green in the meantime had updated his object.
I will have to sit down and closely examine the updated object by Mike Green since my objects run with the modified James Burrow's object.
The old driver was basically for addressing EEPROM's etc, where as the latest version was modified for non-memory devices -- according to the version log.
Some of my objects use the James Burrows added on methods, so I will more likely have to insert his code into my objects if I am going to use Mike Green's updated object.