1 Reply Latest reply on Oct 14, 2020 12:16 AM by MoTa_728816

    PSoc 5lp with i2c expander 23017

    RaSh_3782726

      Hi everyone,

       

      Help me regarding psoc 5lp interfacing with i2c expander ic 23017.

      Here I post my code but didnot work,

       

      This is One way I tried,

       

      #define I2C_SLAVE_ADDRESS (0x27)    // 5v at A0 A1 A2

       

          packet[0] = 0x01;

          packet[1] = 0x00;

          packet[2] = 0x13;

       

      uint8 packet[3];

      uint8 packet_Size = 3;

      void main()

      {

          I2C_Start();

          UART_1_Start();     /* Enabling the UART */    UART_1_PutString("\nStart\n\r");

         uint8_t status =  I2C_MasterWriteBuf(I2C_SLAVE_ADDRESS,(uint8 *)&packet,packet_Size,I2C_MODE_COMPLETE_XFER);

          sprintf(cmd,"status %d\r\n",status);       

          UART_1_PutString(cmd);

          while(0 == (I2C_MasterStatus() & I2C_MSTAT_WR_CMPLT)){

       

      }

          if(0 == (I2C_MSTAT_ERR_XFER & I2C_MasterStatus()))

          {

              I2C_MasterWriteByte(3);     //value send Which bit or GPIO set on IC 23017

              UART_1_PutString("write done\n\r");

          }

       

      }

       

       

      _________________________________________________________________________________________

      2nd way I tried,

       

       

      #define I2C_SLAVE_ADDRESS (0x27)    // 5v at A0 A1 A2

      void main()

      {

          I2C_Start();

          I2C_MasterSendStart(I2C_SLAVE_ADDRESS, I2C_WRITE_XFER_MODE);    //I2C_WRITE_XFER_MODE    (0x00u) /* Write */

          I2C_MasterWriteByte(0x01); // IODIRB register

          I2C_MasterWriteByte(0x00); // set all of port B to outputs

          I2C_MasterWriteByte(0x13); // address port B

          I2C_MasterWriteByte(0x03); // value send Which bit or GPIO set on IC 23017

          I2C_MasterSendStop();

      }

       

      ___________________________________________________________________________________________________

       

      I want to set gpio one by one .Status is 0 it is ok. But did not set the GPIO of the IC.