very simple sample code for PCA9956A (24 channel current control LED driver)
Fork of PCA9955_simple by
Diff: main.cpp
- Revision:
- 1:2a3b314f4996
- Parent:
- 0:3afedead559b
diff -r 3afedead559b -r 2a3b314f4996 main.cpp --- a/main.cpp Wed Oct 10 00:48:16 2012 +0000 +++ b/main.cpp Mon Oct 07 04:03:57 2013 +0000 @@ -7,19 +7,22 @@ #include "mbed.h" -#define PCA9955_ADDRESS 0xC0 +#define PCA9956A_ADDRESS 0x02 +#define IREF_INIT 0x10 I2C i2c( p28, p27 ); char init_array[] = { 0x80, // Command 0x00, 0x05, // MODE1, MODE2 - 0xAA, 0xAA, 0xAA, 0xAA, // LEDOUT[3:0] + 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, // LEDOUT[3:0] 0x80, 0x00, // GRPPWM, GRPFREQ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // PWM[7:0] 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // PWM[15:8] - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, // IREF[7:0] - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, // IREF[15:8] + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // PWM[23:16] + IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, // IREF[7:0] + IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, // IREF[15:8] + IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, // IREF[23:16] 0x08 // OFFSET: 1uS offsets }; @@ -29,19 +32,18 @@ char data[ 2 ]; int i = 0; - i2c.write( PCA9955_ADDRESS, init_array, sizeof( init_array ) ); + i2c.write( PCA9956A_ADDRESS, init_array, sizeof( init_array ) ); while ( 1 ) { - if ( !(i & 0xFFF) ) { - data[ 0 ] = 0x42; + if ( !(i % (256 * 24)) ) { + data[ 0 ] = 0x3F; data[ 1 ] = 0x00; - i2c.write( PCA9955_ADDRESS, data, 2 ); + i2c.write( PCA9956A_ADDRESS, data, 2 ); } else { - data[ 0 ] = 0x0A + ((i >> 8) & 0xF); + data[ 0 ] = 0x0A + ((i >> 8) % 24); data[ 1 ] = i & 0xFF; - i2c.write( PCA9955_ADDRESS, data, 2 ); - + i2c.write( PCA9956A_ADDRESS, data, 2 ); } wait_ms( 1 ); i++;