i2c help, I'm a propeller newb and I need help to get the i2c running to drive
www.sparkfun.com/commerce/product_info.php?products_id=8579
It looks easy to use.. but I need a bit of help.. I looked at some of the I2c objects, but they seem to be for eeproms mostly.. not very helpfull.
thanks for any help I can get.
It looks easy to use.. but I need a bit of help.. I looked at some of the I2c objects, but they seem to be for eeproms mostly.. not very helpfull.
thanks for any help I can get.

Comments
Where is it, I didnt see it on the exchange. I'm reading the i2c demo app v2 and am reading it.. Its a bit over my head, but I'm slowly making headway
http://www.rayslogic.com/propeller/Programming/I2C/I2C.htm
Someone took it and posted it to OBEX.· Normally, this would annoy me, but since it was really Mike Green's code anyway, I don't complain!
If you search OBEX for I2C, you'll find it there too...
Ray
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
Below is an example from some code I just grabbed. Note that there is first a 'start' condition that includes the SCL pin number. Then the address plus write bit. Then another byte that tells the I2C device where (the register address) to read from. After setting this info, there is a 'stop' sent. Next there is another 'start' condition, address plus READ bit (1), read the first byte, then read the next byte while putting the data into a WORD correctly using bitshift, then a STOP. After the data was read, return with the info requested. Of course what you are trying to accomplish will be different, but the datasheet will usually tell you what is required to either read or write from the device.
OBJ i2c1 : "minimali2cdriver" PUB Testdevice repeat if ReadKeyPadA > 0 'just an example of using the i2c code below 'do something else PUB ReadKeyPadA i2c2.i2cStart(i2cSCL2) 'start the transaction i2c2.i2cWrite(i2cSCL2, KPaaddr + 0) i2c2.i2cWrite(i2cSCL2, 1) ' read address i2c2.i2cstop(i2cSCL2) i2c2.i2cStart(i2cSCL2) i2c2.i2cWrite(i2cSCL2, KPaaddr + 1) 'start the read KPAPinInput := i2c2.i2cRead(i2cSCL2, 0) 'read first bit field 0 - 7 keys KPAPinInput |= i2c2.i2cRead(i2cSCL2, 1) << 8 'read second bit field 8 - 15 i2c2.i2cStop(i2cSCL2) return KPAPinInputPost Edited (TChapman) : 5/14/2009 1:09:19 AM GMT
but to test it I only need to send commands to address $00 (broadcast addie)
6.1.1 Basic Commanding Commands are sent to the BlinkM’s address (or the general call address). The bytes of the command are sent one after the other. Thus to send the command “{‘f’,0xff,0x00,0x00}” (i.e. “Fade to full red”): #include “Wire.h” Wire.begin(); // set up I2C Wire.beginTransmission(0x09);// join I2C bus, to BlinkM 0x09 Wire.send(‘f’); // ‘f’ == fade to color Wire.send(0xff); // value for red channel Wire.send(0x00); // value for blue chan. Wire.send(0x00); // value for green chan. Wire.endTransmission(); // leave I2C bus[noparse][[/noparse]/code]
Using the minimali2cdriver I posted, it translates to something like this:
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 'Physical Inputs i2cSCL = 28 '<<<<<<set your actual pins here i2cSDA = 29 OBJ i2c : "minimali2cdriver" PUB Start TEST 'run the i2c method below repeat 'stay alive PUB TEST i2c.start(i2cSCL) 'start condition send SCL pin number i2c.write(i2cSCL, %0000_1000 + 0) 'send address $09 plus write bit '0' i2c.write(i2cSCL, "f") 'not sure here about this i2c driver sending 'f' as a ascii, may need to convert to hex first? someone comment i2c.write(i2cSCL, $FF) 'value for red channel to $FF i2c.write(i2cSCL, $00) 'value for blue channel to $00 i2c.write(i2cSCL, $00) 'value for green channel $00 i2c.i2cstop(i2cSCL) 'stop conditionTheoretically if you have everything hooked up right, you should get RED. You may be able to delete the 'f' fade line and have it still work without a fade.
Post Edited (TChapman) : 5/14/2009 2:06:27 AM GMT
I'm going to order one or two of those blink M's so I can test code and stuff.
Using the minimali2cdriver I posted, it translates to something like this:
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 'Physical Inputs i2cSCL = 28 '<<<<<<set your actual pins here i2cSDA = 29 OBJ i2c : "minimali2cdriver" PUB Start TEST 'run the i2c method below repeat 'stay alive PUB TEST i2c.start(i2cSCL) 'start condition send SCL pin number i2c.write(i2cSCL, %0000_1000 + 0) 'send address $09 plus write bit '0' i2c.write(i2cSCL, "f") 'not sure here about this i2c driver sending 'f' as a ascii, may need to convert to hex first? someone comment i2c.write(i2cSCL, $FF) 'value for red channel to $FF i2c.write(i2cSCL, $00) 'value for blue channel to $00 i2c.write(i2cSCL, $00) 'value for green channel $00 i2c.i2cstop(i2cSCL) 'stop conditionTheoretically if you have everything hooked up right, you should get RED. You may be able to delete the 'f' fade line and have it still work without a fade.
where you have it sending $09, I think you have the binary value wrong.. that looks to be $08, should be %0000_1001 I think.
anyway.. my blinkm's should arrive tomorrow. so I'll see if this works and hack it to do what I want
will fiddle some more a bit later.
Post Edited (TChapman) : 5/15/2009 6:42:19 PM GMT
I'm connecting it up via the diagram in the manual, gnd, 5 volt, and sda and sclk
sda is on 23, and scl is 22
00 - broadcast blinkm
18 - blinkm(2 of them default address.)
160 - eeprom address.
so I'm getting there [noparse]:)[/noparse]
now all I need to do is to try the other code bit.
CON
· _clkmode·············· = xtal1 + pll16x
· _xinfreq·············· = 5_000_000·
··· 'Physical Inputs
··· i2cSCL············· = 0···· '<<<<<<set your actual pins here
··· i2cSDA············· = 1
OBJ
··· i2c······· : "minimali2cdriver"················
PUB Start
····· i2c.i2cstart(i2cSCL)
····· TES·· 'run the i2c method below
········ repeat·· 'stay alive
PUB TES
·· i2c.i2cstart(i2cSCL)··· 'start condition··· send SCL pin number
·· i2c.i2cwrite(i2cSCL, %0001_0010)··· 'send address $09 plus write bit '0'
·· i2c.i2cwrite(i2cSCL, "n")····· 'not sure here about this i2c driver sending 'f' as a ascii, may need to convert to hex first?· someone comment
·· i2c.i2cwrite(i2cSCL, $FF)··· 'value for red channel to $FF
·· i2c.i2cwrite(i2cSCL, $00)··· 'value for blue channel to $00
·· i2c.i2cwrite(i2cSCL, $00)··· 'value for green channel $00
·· i2c.i2cstop(i2cSCL)····· 'stop condition
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ D Rat
Dave Ratcliff· N6YEE
Post Edited (ratronic) : 5/15/2009 10:03:50 PM GMT
everything else seems to work though
pub set························································································
· i2c.i2cstart(i2cSCL)······················ 'start condition··· send SCL pin number······························
· i2c.i2cwrite(i2cSCL, %0000_0000)··· 'send general call address of '0'························
· i2c.i2cwrite(i2cSCL, "A")·················'send·set address command of·'A'
· i2c.i2cwrite(i2cSCL, %0000_1001)··· 'new address you want (x09) for blinkm···················
· i2c.i2cwrite(i2cSCL, $d0)················'send 'd0'
· i2c.i2cwrite(i2cSCL, $0d)················'send '0d'
· i2c.i2cwrite(i2cSCL, %0000_1001)··· 'new address you want (x09)for blinkm (repeated)
· i2c.i2cstop(i2cSCL)······················· 'stop condition·····················································
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ D Rat
Dave Ratcliff· N6YEE
once I do that, then I can setup a program to do that one at a time for each one I get.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ D Rat
Dave Ratcliff· N6YEE
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 'Physical Inputs i2cSCL = 0 '<<<<<<set your actual pins here i2cSDA = 1 OBJ i2c : "minimali2cdriver" PUB Start TES 'run the i2c method below repeat 'stay alive PUB TES i2c.i2cstart(i2cSCL) 'start condition send SCL pin number i2c.i2cwrite(i2cSCL, %0000_0000) 'send address $00 plus write bit '0' i2c.i2cwrite(i2cSCL, "o") 'stop all scripts i2c.i2cstop(i2cSCL) waitcnt(clkfreq / 10 + cnt) i2c.i2cstart(i2cSCL) 'start condition send SCL pin number i2c.i2cwrite(i2cSCL, %0000_0010) 'send address $01 plus write bit '0' i2c.i2cwrite(i2cSCL, "n") 'send the command to set color right away, no fade. i2c.i2cwrite(i2cSCL, $ff) 'value for red channel i2c.i2cwrite(i2cSCL, $ff) 'value for green channel i2c.i2cwrite(i2cSCL, $ff) 'value for blue channel i2c.i2cstop(i2cSCL) 'stop condition waitcnt(clkfreq / 10 + cnt) i2c.i2cstart(i2cSCL) i2c.i2cwrite(i2cSCL, %0000_0100) 'send address $02 plus write bit '0' i2c.i2cwrite(i2cSCL, "n") 'send the command to set color right away, no fade. i2c.i2cwrite(i2cSCL, $01) 'value for red channel i2c.i2cwrite(i2cSCL, $01) 'value for green channel i2c.i2cwrite(i2cSCL, $01) 'value for blue channel i2c.i2cstop(i2cSCL) 'stop conditionthis now works.. I had to use this code to set each blinkm's address..
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 'Physical Inputs i2cSCL = 0 '<<<<<<set your actual pins here i2cSDA = 1 OBJ i2c : "minimali2cdriver" PUB Start i2c.i2cstart(i2cSCL) TES 'run the i2c method below repeat 'stay alive PUB TES i2c.i2cstart(i2cSCL) 'start condition send SCL pin number i2c.i2cwrite(i2cSCL, %0000_0000) 'send address $09 plus write bit '0' i2c.i2cwrite(i2cSCL, "A") 'send the command to set color right away, no fade. i2c.i2cwrite(i2cSCL, $01) 'value for red channel i2c.i2cwrite(i2cSCL, $d0) 'value for green channel i2c.i2cwrite(i2cSCL, $0d) 'value for blue channel i2c.i2cwrite(i2cSCL, $01) 'value for blue channel i2c.i2cstop(i2cSCL) 'stop conditionit does work. so I'm happy.. I think my issue with the address set was that I was using f11 which put it in eeprom, so that as soon as I powered it up with both blinkm's installed. it would set both again [noparse]:)[/noparse] so when I do the set address I'm doing it as f10, which only programmed the ram.