Simple IDE I2C Bus Speed how to change
Andrew Bubble
Posts: 21
Hi I am developing some LED lamps using the Propeller chip, I am using the Adafruit 16 channel Servo / LED driver board
http://www.adafruit.com/products/815 This uses the PCA9685 LED driver chip. I originally used an Arduino board but I have infrared, the LED board together with an radio link and the interrupts were getting complicated so I chose to use the propeller chip instead.
The project is going ok but I have a problem to do with the SimpleIDE I2C bus speed, I can't find anywhere to adjust the I2C clock speed. I assume this set to 100K but I would like to increase up to 400K or higher if possible.
Is this possible and can anyone give any advice on how to achieve this.
Regards Andrew
http://www.adafruit.com/products/815 This uses the PCA9685 LED driver chip. I originally used an Arduino board but I have infrared, the LED board together with an radio link and the interrupts were getting complicated so I chose to use the propeller chip instead.
The project is going ok but I have a problem to do with the SimpleIDE I2C bus speed, I can't find anywhere to adjust the I2C clock speed. I assume this set to 100K but I would like to increase up to 400K or higher if possible.
Is this possible and can anyone give any advice on how to achieve this.
Regards Andrew
Comments
EEPROM sample code
https://code.google.com/p/propgcc/source/browse/demos/eeprom/eepromdemo.c?name=release_1_0
EEPROM Library with fast I2C function calls
https://code.google.com/p/propgcc/source/browse/lib/sys/propeller/eeprom.c?name=release_1_0
The actual I2C code is in the propeller folder
https://code.google.com/p/propgcc/source/browse/lib/sys/propeller/?name=release_1_0
Thank you for the quick response. As a generic question can the eeprom examples be used with any I2C device or are they specific to an eeprom. Below is an the two routines I use in my program the first initializes the PCA9685 device the second is used to update the device when any of the led's data changes.
void Setup_PCA9685()
{
i2c_open(PCA9685,7,6,0);
i2c_start(PCA9685);
i2c_writeByte(PCA9685,0x80);
i2c_writeByte(PCA9685,0x00);
i2c_writeByte(PCA9685,0x00);
i2c_stop(PCA9685);
//pause(200);
i2c_start(PCA9685);
i2c_writeByte(PCA9685,0x80);
i2c_writeByte(PCA9685,0x01);
i2c_writeByte(PCA9685,0x10);
i2c_stop(PCA9685);
//pause(200);
i2c_start(PCA9685);
i2c_writeByte(PCA9685,0x80);
i2c_writeByte(PCA9685,0xFE);
i2c_writeByte(PCA9685,0x0B);
i2c_stop(PCA9685);
//pause(200);
}
void Update_PCA9685()
{
int i = 0;
int pwm;
short int address = 0x08;
for(i=0; i <=14; i++)
{
i2c_start(PCA9685);
i2c_writeByte(PCA9685,0x80);
i2c_writeByte(PCA9685,address);
pwm = PWMData;
i2c_writeByte(PCA9685,pwm);
i2c_stop(PCA9685);
address++;
i2c_start(PCA9685);
i2c_writeByte(PCA9685,0x80);
i2c_writeByte(PCA9685,address);
pwm = PWMData>>8;
i2c_writeByte(PCA9685,pwm);
i2c_stop(PCA9685);
address = address + 3;
}
}
Regards Andrew
I think I have answered my question but before I try something I need some clarification, I have read through some of the .c files indicated in the last link of your reply.
In my examples listed above the I2C library had the form of i2c_open, i2c_start, byte, byte, byte then i2c_stop. I am assuming that using examples in the links you have provided I simply use the i2cWrite and define the three bytes I wish to send and the function will
put the required start at the beginning and the stop at the end.
I am off work over the weekend so I am planning on having a play.
Regards Andrew
It's very confusing to me about what causes a start sequence. The stop sequence control is pretty clear though.
The problem comes when I try to set the LED's afterwards using the update routine, this uses the same i2cWrite commands but there is a for next loop setting each of the brightness registers to a value from 0 to 4095 (full brightness), for all sixteen LED's.
Regards Andrew
Thanks for all your help, all working now. I have got the PCA9685 chip talking and I can control all the led's. I am using the I2cOpen, i2cRead and i2cWrite which runs at 400khz.
Regards Andrew
I measured the SCL frequency on a Quickstart and an AB. Both are running at 16.6KHz, 19us high and 38us low.
Seems like when functioning normally both ought to be clocking at 100KHz, 10us period.
Maybe it's a quirk of the SimpleIDE or something else?? The pulse out of P0 is 1us, if that means anything.
Dom..
Dom..
Keep in mind that they are not your only I2C library choices for SimpleIDE. For example, you can also use #include <i2c.h> to add the I2C functions built into Propeller GCC. They have a 400 kHz clock speed option running in Propeller Assembly Language (PASM) in another cog, and Jazzed posted a link to its API for it in post #6.
[Correction, the 400 kHz I2C option was written in C in an optimized way that can be executed directly by another cog. The C library could also have utilized a PASM driver, but did not in this case.]
You have many other software and language options. The Parallax Propeller Tool and PropellerIDE are two software examples that support the Spin + PASM languages. You will also encounter libraries that execute at different speeds in the Spin libraries. For example, there are I2C libraries that execute in the higher level and interpreted (lower speed) Spin language in the same cog, and others that run in the assembled PASM language (higher speed) in another cog.
P.S. Parallax provides/supports the SimpleIDE and Propeller Tool software packages for Spin, Propeller C and PASM. There are also lots of options contributed by community members listed here: ULTIMATE-List-of-Propeller-Languages. Keep in mind that these community developed languages and software packages will be at various levels of completeness, and have varying levels of support.
Dom..
Found the thread: Sawmill helpful. The code started with something simple that worked and
allowed me to whittle away until mine worked too.
Didn't see a "i2c_busy" replacement so used this instead and it seems to do the job:
That's a lot of fun for $2.
Pretty cool, do you have a line on those CC male headers?