1 2 Previous Next 19 Replies Latest reply on Nov 9, 2016 12:48 AM by pmartinez_1655886 Go to original post
      • 15. Re: Psoc and I2C with PCA9685
        pmartinez_1655886

        The wire is very short. It is a smd pcb. We have tested with an osciloscope and sda and scl are reaching the second i2c device. Write8 function doesn' return any fail now when I do the initializacion. this is the code fot that:

           

         

           

        [code]

           

        void PWM_setAllPWM(uint8_t on, uint8_t off){
            uint8_t test_var = 0x00;
           
           test_var =  PWM_write8(ALLLED_ON_L,  on&0xff);
           test_var = PWM_write8(ALLLED_ON_H,  on>>8);
           test_var = PWM_write8(ALLLED_OFF_L, off&0xff);
           test_var = PWM_write8(ALLLED_OFF_H, off>>8);
           test_var = test_var;
        }

           

        void PWM_begin(void) {
         //uint8_t mode1;
         //MOTOR_Start();
         //MOTOR_Enable();
         //CyDelay(2000);
         PWM_setAllPWM(0,0);
         PWM_reset();
         PWM_setPWMFreq(FREQ);
         
        }

           

        void PWM_reset(void) {
         uint8_t test_var = 0x00;
         test_var = PWM_write8(PCA9685_MODE1, 0x00);
         test_var = PWM_write8(PCA9685_MODE2, 0x04);
         test_var = test_var;
         CyDelay(5);
        }

           

        [/code]

           

         

           

        Read&write function:

           

         

           

        [code]

           

        uint8_t PWM_write8(uint8_t reg, uint8_t d) {
          uint8_t result = 0x00;

           

         if((result = MOTOR_I2CMasterSendStart(_addr, I2C_WRITE_XFER_MODE)))
            return result;
         if((result = MOTOR_I2CMasterWriteByte(reg)))
            return result;
         if((result = MOTOR_I2CMasterWriteByte(d)))
            return result;
         if((result = MOTOR_I2CMasterSendStop()))
            return result;
         return result;   
        }

           

        uint8_t PWM_read8(uint8_t reg) {
          uint8_t response = 0x00;
          MOTOR_I2CMasterSendStart(_addr, I2C_WRITE_XFER_MODE);
          MOTOR_I2CMasterWriteByte(reg);
          MOTOR_I2CMasterSendRestart(_addr, I2C_READ_XFER_MODE);
          //MOTOR_I2CMasterSendStop();
          response =  MOTOR_I2CMasterReadByte(I2C_NAK_DATA);
          MOTOR_I2CMasterSendStop();

           

          return response;
        }

           

        [/code]

           

         

           

        The response in every test_var during initializacion of second i2c device is 0x00. 

        • 16. Re: Psoc and I2C with PCA9685
          user_1377889

          Just for de-bugging: In PWM_read8() check all the returned values. To make debugging easier I would suggest to call a routine when an error occurs and set a breakpoint there. So you will see when looking at the call stack where the error comes from.

             

          Are you doing any interrupt driven accesses to I2C?

             

          What I am missing from datasheet of  PCA chip: there is no read register sequence, only a "Read all registers using the Auto-Increment". Might be a problem?

             

          I would suggest you to connect a logic analyzer to SDA and SCL, most are able to give a communication protocol that will help to isolate the problem.

             

           

             

          Bob

          • 17. Re: Psoc and I2C with PCA9685
            pmartinez_1655886

            I will try the logic analyzer and debug code. As soon as I get some answer with it I will post it. thank you

            • 18. Re: Psoc and I2C with PCA9685
              pmartinez_1655886

              Well, after running some tests it seems that the PCA9685 had a couple of pads causing a short and thats why pwm couldn't work. Now I have both working without problems. Thank you Bob.

              • 19. Re: Psoc and I2C with PCA9685
                user_1377889

                You are always welcome.

                   

                 

                   

                Bob

                1 2 Previous Next