Any example code for I2C
Sawmiller
Posts: 276
do we have any example code for I2C ? in C for the prop that is.
i am looking at i2c.h in propgcc/propeller-elf/include and see the briefs... but i could use a lil more if someone know of some code.
dan
i am looking at i2c.h in propgcc/propeller-elf/include and see the briefs... but i could use a lil more if someone know of some code.
dan
Comments
Here's a Spin2Cpp-created project for the Wii Nunchuk that uses i2c. Hopefully, you'll be able to mod as needed. This is a Zip of a SimpleIDE project.
TestWiNunchukC.zip
dgately
dan
i was looking for example code because i have written the functions as i think they need to be, foe example
i2c_Address = simple_i2cOpen( DS1721_Addr,i2cSCL,i2cSDA); // get a i2c address for the ds1721 chip
flag = i2cWrite(i2c_Address,DS1721_Addr,AccessConfig,8,False); // tell DS1721 we are going to config
if (flag == 0)
printf("Success on config \n");
if (flag == -1)
printf("Failure on config\n");
pause (1000);
flag = 2;
flag = i2cWrite(i2c_Address,DS1721_Addr,Cont_09_Bit,8,True); // tell DS1721 9 bit accuracy
if (flag == 0)
printf("Success on 9 bit\n");
pause (1000);
flag = 2;
flag = i2cWrite(i2c_Address,DS1721_Addr,StartConvert,8,False);
if (flag == 0)
printf("success on starting conversion of temp\n");
and i am getting success printf's ( flag coming back as zero )
but i am not getting a valid temp reading, have gone over my wiring several times
( using a setup that i put together in 2008 and used spin with.)
i am excited about being able to use C with the prop, but was hoping for more documentation like the prop manual ( which is a lil more wordy ) or like the way they did the sx when they were programming that.
coming back to programming after a 5 year hiatus so i am a lil rusty.
spin2cpp appears to work, but doesn't interact with the library
sorry, don't mean to be so verbose.
dan
i2c_simple.c
if you have time, please look.
this is the latest itteration, was trying simple open, so i didnt have to figure out cog driver yet, but i commented out simple and am playing with the cog driver
where did you find i2c_simple.c ?
am trying to see why I2C_COGDRIVER COG; works
but if i uncomment I2C_SIMPLE i2c_Address; it doesnt work the same.
sigh
thanks for the help, i will work on this some more, and see if i can't dragg my head out of where it is
http://code.google.com/p/propgcc/
It's in propgcc/lib/sys/propeller.
But for now its working.
Thanks David.