View previous topic :: View next topic |
Author |
Message |
CMatic
Joined: 11 Jan 2012 Posts: 69
|
I2C bus problem with Adafruit 8x8 Matrix with HT16K33 bd |
Posted: Sun Mar 30, 2014 9:51 pm |
|
|
I have connected a Adafruit 8x8 Square Matrix backpack board with PIC16F877a. The Adafruit 8x8 Square Matrix backpack board has an I2C chip HT16K33 to communicate over I2C bus. My program seems to be sending everything correctly over the bus but I don't see any led lighting up?
I have a logic analyzer to check the communication. I have not used HT16K33 before so any help will be much appreciated.
Thank you.
Here is my code.
Code: |
//***************************************************************************//
//Adafruit 8x8 Square Matrix display program
//The backpack board has the chip HT16K33
//The LED Dot Matrix is BL-M12X883XX
//
//
// Compiler CCS C PCWHD Version 4.126 Limited Edition(Evaluation)
//
//
// Description: The main program writes to the 8x8 matrix using the I2C Bus
// CCS Compiler has built in functions available for I2C and these are used here
//***************************************************************************//
#include <16F877a.h>
#fuses HS, NOWDT, PROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20MHz)
#define SDA_PIN PIN_D4
#define SCL_PIN PIN_D3
#use I2C(MASTER, SDA=SDA_PIN, SCL=SCL_PIN)
#define SLAVE_WRT_ADDR 0x70 //Defined by Adafruit Backpack board
#define SLAVE_READ_ADDR 0x71 //Defined by the Backpack board
#define HT16K33_BLINK_CMD 0x80
#define HT16K33_BLINK_DISPLAYON 0x01
#define HT16K33_BLINK_OFF 0
#define HT16K33_BLINK_2HZ 1
#define HT16K33_BLINK_1HZ 2
#define HT16K33_BLINK_HALFHZ 3
#define HT16K33_CMD_BRIGHTNESS 0x0E
unsigned char msgbuff[8]= {0xAA,0xFF,0xBB,0xCC,0x0D,0xAA,0x0F,0x00};
//******************Function Routines****************************************//
void setup(void);
//void Clear (void);
//void writeDisplay(int8 address, int8 data);
//void setBrightness(int8 b);
//void BlinkRate(int8 b);
//readDisplay(int8 address);
//***************************************************************************//
void main()
{
int8 data1, data2;
while(TRUE)
{
setup();
}
} // End of the main()
//***************************************************************************//
// Description : Setup the I2C on the HT16K33 device
// Argument(s) : Address of the device = 0x70 (write) 0x71 (read)
//
// Return value : None
//***************************************************************************//
void setup(void)
{
i2c_start();
i2c_write(SLAVE_WRT_ADDR);
i2c_write(0x21); // register address = 0x21 for Internal RC Osc.
//i2c_write(0x00); // Data to device -
i2c_stop();
delay_us(100);
i2c_start();
i2c_write(SLAVE_WRT_ADDR);
i2c_write(0x81); // Display On, no blinking
//i2c_write(0x00); // Data to device
i2c_stop();
delay_us(150);
i2c_start();
i2c_write(SLAVE_WRT_ADDR);
i2c_write(0xEF); // Dimming Full Bright on
//i2c_write(0x00); // Data to device
i2c_stop();
delay_us(150);
i2c_start();
i2c_write(SLAVE_WRT_ADDR);
i2c_write(0x00); // Write data to Display Ram at 0x00
i2c_write(0xAA); // Data Written "0xAA"
i2c_stop();
delay_us(150);
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Mar 30, 2014 11:00 pm |
|
|
Run this i2c bus scanner program in your 16F877A. See it it detects the
HT16K33 i2c device. Change the first 5 lines of the program in the link
so it fits your board:
http://www.ccsinfo.com/forum/viewtopic.php?t=49713
See if it finds the HT16K33 at address 0x70. |
|
|
CMatic
Joined: 11 Jan 2012 Posts: 69
|
|
Posted: Mon Mar 31, 2014 11:14 am |
|
|
Thank you so much. It worked and I found out that even though Adafruit documentation for the 8x8 matrix says that these boards have default address of 0x70, using the I2C Bus Scanner its actually is 0xE0!
Thank you again so much PCM Programmer! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Mon Mar 31, 2014 1:16 pm |
|
|
That is the old 'how I2C addresses are generated' problem.
I2C addresses are _seven bit_ values. They then have an extra bit added as bit 0. Some manufacturers list the addresses with the extra bit. Others list them without.
Best Wishes |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Mon Mar 31, 2014 2:12 pm |
|
|
Ttelmah wrote: | That is the old 'how I2C addresses are generated' problem.
I2C addresses are _seven bit_ values. They then have an extra bit added as bit 0. Some manufacturers list the addresses with the extra bit. Others list them without.
|
Right..
so if you take 0x70 and shift to the left 1 to make space for the R/W bit, you have 0xE0...
Fun!
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
CMatic
Joined: 11 Jan 2012 Posts: 69
|
|
Posted: Tue Apr 01, 2014 1:33 pm |
|
|
Ben Thank you for the insight. I lost a few hours thinking about it. |
|
|
|