This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

I2C interfacing to PCA9532 peripheral

hi everyone im only starting learning about microcomputers so please forgive any mistakes i make.
ARM core, LPC2478 microprocessor, board is the MCB2478.
im trying to communicate via I2C to the PCA9532, specifically a read operation, the write is no problem, my issue is with the repeated start of the read operation. when i simulate the code i the repeated start does not occur and it just writes out last byte of data in the I20DAT register, so clearly i must be doing something wrong. i have been been looking through both the LPC24xx UM and the PCA5932 UM cannot find what i might be doing wrong. if anyone could give me some help would be great. my attempted code is below.

void set_start(void); //set start condition
 /* function to read the input0 register. the input0 register contains the status of LED0 to LED7 on the PCA9532 */
int read_switch(void)
{

         unsigned char a;                //  ?variable to hold ipunt0 register byte

        /* start condition */

         set_start();


        I20DAT = 0xC0;                                   // address of PCA9532 wit read bit set

        I20CONCLR = I2C_SI|I2C_STA ;     // clear bits

        while (!(I20CONSET & I2C_SI));       // wait

        I20DAT = 0x00;                                   // AI bit clear and input0 register

        I20CONCLR = I2C_SI;                              // clear si bit

        while (!(I20CONSET & I2C_SI));       // wait

        set_start();

        I20DAT = 0xC1;                                   // address of PCA9532 wit read bit set

        I20CONCLR = I2C_SI|I2C_STA ;     // clear bits

        while (!(I20CONSET & I2C_SI));       // wait


        I20CONSET = I2C_STO;                     // generate stop bit

        I20CONCLR =I2C_SI;                               // clear si bit

        while (!(I20CONSET & I2C_STO));      // wait

        a = I20DAT;                                              // give the contents of the data register to the variable


        return a;                                                // return that variable

}

void set_start(void)
{
        I20CONCLR = I2C_AA | I2C_SI |I2C_STA |I2C_STO;
        I20CONSET = I2C_STA     ;            // repeated start

        while (!(I20CONSET & I2C_SI));       // wait
}

0