Author Topic: 16f1825 MCC i2c with PCA985  (Read 1095 times)

0 Members and 1 Guest are viewing this topic.

Offline JonPyroTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: gb
16f1825 MCC i2c with PCA985
« on: April 25, 2018, 01:49:23 pm »
Hi All,

I am a little lost as I have never really implemented I2C before on a PIC with MCC.

I am trying to talk to the PCA9685 (datasheet : https://www.nxp.com/docs/en/data-sheet/PCA9685.pdf) on a servo driver board bought off ebay using a 16f1825 and using MCC to generate the I2C functions. However, I am at a loss to work out how to use the functions MCC has generated.

Here is my thinking, first define the registers from the datasheet I want to access and the new pre-scaler (I want 50hz pwm for servos and not the default 200hz):

Code: [Select]
#define PCA9685_ADDRESS        0x40
#define PCA9685_MODE1          0x00
#define PCA9685_PRESCALE       0xFE
#define PCA9685_MODE1_SLEEP    0x10
#define PCA8695_MODE1_RESTART  0x80

int PreScaleValue = 0x79;

Now in the main program I should be using:
Code: [Select]
void I2C_MasterWrite(
            uint8_t *pdata,
            uint8_t length,
            uint16_t address,
            I2C_MESSAGE_STATUS *pstatus);

So would you write that something along the lines of this if I wanted to sleep the chip and change the pre-scale:

Code: [Select]
    writeBuffer[0] = PCA9685_MODE1_SLEEP;
    writeBuffer[1] = PCA9685_PRESCALE;
    writeBuffer[2] = PreScaleValue;
       
    I2C_MasterWrite(writeBuffer,1, PCA9685_ADDRESS, &status);

Any help would be appreciated ;)

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf