PCA9698 i2c sample code

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PCA9698 i2c sample code

Jump to solution
1,501 Views
hfabbasi
Contributor III

Would anybody be so kind to send me the sample code for nxp K60DX256VLL10 to communicate with PCA9698 over I2C protocol to turn led on/off for bank 0?

Labels (1)
0 Kudos
1 Solution
1,476 Views
mjbcswitzerland
Specialist V

Hi

Assuming that the PCA9698 is connected with AD0, AD1 and AD2 at GND its write address is 0x40 and its read address is 0x41.

To configure the first output (only) the transmission sequence is
0x40 0x18 0xfe
which will change it from its default input to output and it will drive '0'

To change it to '1' the transmission sequence is
0x40 0x08 0x01

To change it back to '0' the transmission sequence is
0x40 0x08 0x00

uTasker I2C interface code to do it (on I2C0 at 100kb/s) is:

define I2C_WRITE_ADDRESS   0x40
define I2C_READ_ADDRESS    0x41

    static QUEUE_HANDLE I2CPortID = NO_ID_ALLOCATED;

    static const unsigned char ucConfigureOutput[] = {I2C_WRITE_ADDRESS, 0x18, 0xfe};
    static const unsigned char ucSetOutputHigh[] = {I2C_WRITE_ADDRESS, 0x08, 0x01};
    static const unsigned char ucSetOutputLow[] = {I2C_WRITE_ADDRESS, 0x08, 0x00};

    I2CTABLE tI2CParameters;

    tI2CParameters.Channel = 0;
    tI2CParameters.usSpeed = 100;                                        // 100k
    tI2CParameters.Rx_tx_sizes.TxQueueSize = 64;                         // transmit queue size
    tI2CParameters.Rx_tx_sizes.RxQueueSize = 64;                         // receive queue size
    tI2CParameters.Task_to_wake = 0;                                     // no wake on transmission termination
    I2CPortID = fnOpen(TYPE_I2C, FOR_I_O, &tI2CParameters);
    fnWrite(I2CPortID, (unsigned char *)ucConfigureOutput, sizeof(ucConfigureOutput));
    fnWrite(I2CPortID, (unsigned char *)ucSetOutputHigh, sizeof(ucSetOutputHigh));
    fnWrite(I2CPortID, (unsigned char *)ucSetOutputLow, sizeof(ucSetOutputLow));


Regards

Mark
[uTasker project developer for Kinetis and i.MX RT]
Contact me by personal message or on the uTasker web site to discuss professional training, solutions to problems or rapid product development requirements

For professionals searching for faster, problem-free Kinetis and i.MX RT 10xx developments the uTasker project holds the key: https://www.utasker.com/iMX/RT1064.html

View solution in original post

0 Kudos
4 Replies
1,495 Views
nxf56274
NXP Employee
NXP Employee

Hi,

Which mcu do you use? We do not have the sample code about PCA9698. You may refer this code. It uses i2c to driver the w25q. You can use these code to try to communicate with the PCA9698.

Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
1,484 Views
hfabbasi
Contributor III

This is an example of SPI and not of I2C. Would you be so kind to share the code for I2C or atleast guide how to configure PCA9698 for turning LED on/off connected to bank 0, pin 0? What would be the sequence of device (slave) address, output configuration register and command register for output?

0 Kudos
1,477 Views
mjbcswitzerland
Specialist V

Hi

Assuming that the PCA9698 is connected with AD0, AD1 and AD2 at GND its write address is 0x40 and its read address is 0x41.

To configure the first output (only) the transmission sequence is
0x40 0x18 0xfe
which will change it from its default input to output and it will drive '0'

To change it to '1' the transmission sequence is
0x40 0x08 0x01

To change it back to '0' the transmission sequence is
0x40 0x08 0x00

uTasker I2C interface code to do it (on I2C0 at 100kb/s) is:

define I2C_WRITE_ADDRESS   0x40
define I2C_READ_ADDRESS    0x41

    static QUEUE_HANDLE I2CPortID = NO_ID_ALLOCATED;

    static const unsigned char ucConfigureOutput[] = {I2C_WRITE_ADDRESS, 0x18, 0xfe};
    static const unsigned char ucSetOutputHigh[] = {I2C_WRITE_ADDRESS, 0x08, 0x01};
    static const unsigned char ucSetOutputLow[] = {I2C_WRITE_ADDRESS, 0x08, 0x00};

    I2CTABLE tI2CParameters;

    tI2CParameters.Channel = 0;
    tI2CParameters.usSpeed = 100;                                        // 100k
    tI2CParameters.Rx_tx_sizes.TxQueueSize = 64;                         // transmit queue size
    tI2CParameters.Rx_tx_sizes.RxQueueSize = 64;                         // receive queue size
    tI2CParameters.Task_to_wake = 0;                                     // no wake on transmission termination
    I2CPortID = fnOpen(TYPE_I2C, FOR_I_O, &tI2CParameters);
    fnWrite(I2CPortID, (unsigned char *)ucConfigureOutput, sizeof(ucConfigureOutput));
    fnWrite(I2CPortID, (unsigned char *)ucSetOutputHigh, sizeof(ucSetOutputHigh));
    fnWrite(I2CPortID, (unsigned char *)ucSetOutputLow, sizeof(ucSetOutputLow));


Regards

Mark
[uTasker project developer for Kinetis and i.MX RT]
Contact me by personal message or on the uTasker web site to discuss professional training, solutions to problems or rapid product development requirements

For professionals searching for faster, problem-free Kinetis and i.MX RT 10xx developments the uTasker project holds the key: https://www.utasker.com/iMX/RT1064.html

0 Kudos
1,462 Views
hfabbasi
Contributor III

Will you be able to review my Keil code attached here which is simple code of writing "0" and "1" to pin 0, bank 0 (configured as output)?

When I debug my code, it gets stuck at line 221 of code inside function "I2C_WriteAccelReg". If I use function "I2C_MasterTransferBlocking" ( inside function "I2C_WriteAccelReg"), the code get stuck at line 952 of driver "fsl_i2c.c"

0 Kudos