-1
\$\begingroup\$

I have a circuit with a PCA9635 PWM LED driver. I want to turn on and off LEDs one after another, but my code does not work. I think the hardware is OK. My micro is a 16F887.

Can you help me?

#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON        // Power-up Timer Enable bit (PWRT enabled)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)

#define _XTAL_FREQ 20000000


#define PCA963X_LED_OFF 0x0 //LED driver off//
#define PCA963X_LED_ON 0x1 //LED driver on//
#define PCA963X_LED_PWM 0x2 //Controlled through PWM//
#define PCA963X_LED_GRP_PWM 0x3 //Controlled through PWM/GRPPWM//
#define PCA963X_MODE2_OUTDRV 0x04 //Open-drain or totem pole//
#define PCA963X_MODE2_INVRT 0x10 //Normal or inverted direction//
#define PCA963X_MODE2_DMBLNK 0x20 //Enable blinking//
#define PCA963X_MODE1 0x00
#define PCA963X_MODE2 0x01
#define PCA963X_LED0_ON 0x02 // LED0
#define PCA963X_LED2_ON 0x04 // LED2
#define PCA963X_LED3_ON 0x05 // LED3
#define PCA963X_LED4_ON 0x06 // LED4
#define PCA963X_LED5_ON 0x07 // LED5
#define PCA963X_LED6_ON 0x08 // LED6
#define PCA963X_LED7_ON 0x09 // LED7
#define PCA963X_LED8_ON 0x0A // LED8
#define PCA963X_LED9_ON 0x0B // LED9
#define PCA963X_LED10_ON 0x0C// LED10
#define PCA963X_LED11_ON 0x0D// LED11
#define PCA963X_LED12_ON 0x0E// LED12
#define PCA963X_LED13_ON 0x0F// LED13
#define PCA963X_LED14_ON 0x10// LED14
#define PCA963X_LED15_ON 0x11// LED15



void main(void)
{
/*
ANSEL  = 0;                // Configure AN pins as digital I/O
ANSELH = 0;
PORTB = 0;
TRISB = 0;                 // Configure PORTB as output
*/ 
TRISA.f3=0;// make RA3 out------> OE of pca9635   

TRISD.f0=0;// make RD0 out for test program is correct   
      
PORTA.f0 = 0; //---> OE low
   
   PORTD.f0 =1;   // 
   Delay_ms(4000);  //add delay of 1 second 
   
   I2C1_Init(100000);
   I2C1_Start();
   I2C1_Wr(0b00101010); //-----> slave address   0x2A
   I2C1_Wr(0b00000110); //-----> slave software reset
   //I2C1_Wr(0x1 );
   I2C1_Stop();
   
   PORTD.f0 =0; 
   Delay_ms(100);  //add delay of 1 second
   
 while(1){  
   PORTA.f0 = 0; //---> OE low
   if (I2C1_Is_Idle()) {
   
   PORTD.f0 =1; 
   Delay_ms(1000); 
   
   I2C1_Start();
   I2C1_Wr(0b00101010); //-----> slave address
   I2C1_Wr(0x1);
   
   I2C1_Wr(0x01);
   I2C1_Wr(0x02);
   I2C1_Wr(0x03);
   I2C1_Wr(0x04);
   I2C1_Wr(0x05);
   I2C1_Wr(0x06);
   I2C1_Wr(0x07);
   I2C1_Wr(0x08);
   I2C1_Wr(0x09);
   I2C1_Wr(0x0A);
   I2C1_Wr(0x0B);
   I2C1_Stop();
   Delay_ms(1000); 
   
   
   I2C1_Start();
   I2C1_Wr(0b00101010); //-----> slave address
   I2C1_Wr(0xE0);
   I2C1_Wr(0xF4);
   I2C1_Wr(0x02);
   I2C1_Wr(0x02);
   I2C1_Wr(0x03);
   I2C1_Wr(0x04);
   I2C1_Wr(0x05);
   I2C1_Wr(0x06);
   I2C1_Wr(0x07);
   I2C1_Wr(0x08);
   I2C1_Wr(0x09);
   I2C1_Wr(0x0A);
   I2C1_Wr(0x0B);
   
   I2C1_Stop();
   Delay_ms(1000);
   
   I2C1_Start();
   I2C1_Wr(0b00101010); //-----> slave address
   I2C1_Wr(0b10110110); //----->control register
   I2C1_Wr(0x00);
   I2C1_Wr(1);
   I2C1_Stop();
   Delay_ms(1000);
   
   PORTD.f0 =0; 
   Delay_ms(1000);  //add delay of 1 second  
   }
 }   
}

enter image description here enter image description here

enter image description here

\$\endgroup\$
4
  • 5
    \$\begingroup\$ Reza - This is now the 3rd very similar question that you have asked and deleted. Each time you use a phrase like "it doesn't work" and are asked for more details in comments. You have done the same thing again :( Although the site allows an OP (original poster) to delete their question in some cases, it is not intended that virtually the same question will be asked again. That wastes the time of people who have taken time to start analysing the question, trying to understand it and asked for more details etc. Do not do that again. If you delete this question, then do not repost it. Thanks. \$\endgroup\$
    – SamGibson
    Oct 17, 2022 at 17:49
  • 1
    \$\begingroup\$ ”I think the hardware is OK.” Please show with oscillogram and logic analyzer. \$\endgroup\$
    – winny
    Oct 17, 2022 at 18:04
  • \$\begingroup\$ I am not sure if the code is correct or not. First, I need to make sure that the code written for the above circuit is correct. Are you sure that the code is correct? I wish I could find an example of the circuit above. \$\endgroup\$
    – Reza
    Oct 17, 2022 at 19:40
  • \$\begingroup\$ What are those I2C writes supposed to do? Are those data or register addresses or what? What you think the code does? \$\endgroup\$
    – Justme
    Oct 20, 2022 at 18:18

2 Answers 2

1
\$\begingroup\$

You are getting nothing, that is what I would expect. It appears you are shooting in the dark with this design. I immediately see one very good reason it will not work, you do not have the required pull up resistors on the SCL and SDA lines. The value of these depends on the VCC voltage. When you install them you need to run the I2C scanner code. If it gives you the address it is OK, if not you have a wiring problem. What voltage is this system operating at? I see no bulk capacitance or decoupling on the LED driver. All the correcting of the code will not help if the hardware fails. Nice schematic but an important part is missing as is the right side.

\$\endgroup\$
2
  • \$\begingroup\$ complete schematic added. SCL and SDA pull up with 10k resistors. VDD is 5v.can you help me a correct code? i write this code Due to datasheet. but i think it is wrong. i think hardware connection is ok. OE pin of PCA9635 must be low? \$\endgroup\$
    – Reza
    Oct 20, 2022 at 18:10
  • \$\begingroup\$ Use this link, it will answer the questions. nxp.com/docs/en/data-sheet/PCA9635.pdf Use 4.7K pull up. When you see a signal for example R\ or R with a bar over it indicates active low. Reading section 7 of that data sheet will answer most of your questions. \$\endgroup\$
    – Gil
    Oct 21, 2022 at 14:32
0
\$\begingroup\$

Your I2C address is wrong. It can't in any way be 0xAE.

And the code does not even use I2C protocol correctly, the while loop simply does not even address the chip.

\$\endgroup\$
1
  • \$\begingroup\$ What is the correct address of chip? \$\endgroup\$
    – Reza
    Oct 19, 2022 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.