CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

I2C bus problem with Adafruit 8x8 Matrix with HT16K33 bd

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

I2C bus problem with Adafruit 8x8 Matrix with HT16K33 bd
PostPosted: Sun Mar 30, 2014 9:51 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Mar 30, 2014 11:00 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 31, 2014 11:14 am     Reply with quote

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: 19513

View user's profile Send private message

PostPosted: Mon Mar 31, 2014 1:16 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 31, 2014 2:12 pm     Reply with quote

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! Smile

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
CMatic



Joined: 11 Jan 2012
Posts: 69

View user's profile Send private message

PostPosted: Tue Apr 01, 2014 1:33 pm     Reply with quote

Ben Thank you for the insight. I lost a few hours thinking about it.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group