3 Replies Latest reply on Mar 12, 2016 1:41 AM by user_1377889

    PSOC4 I2C master issue

    mao.xguo

        When I use I2C master module, I use I2C_start() function, then use I2C write function. But I can't see any signal by logistic analysis.

         

      But I2C_writebuffer function can work well. What's the reason? Do I miss to call some function?

        • 1. Re: PSOC4 I2C master issue
          user_1377889

          Welcome in the forum!

             

          You need to call at first I2C_SendStart() API.

             

          Byte I2C interface is quite simple: After setting up the component and starting it you use

             

              I2C_MasterSendStart(DeviceAddress,I2C_WRITE_XFER_MODE);    // Initialize a transaction for writing
              I2C_MasterWrite(Register);                // Indicate which register you want to write to
              I2C_MasterWriteByte(Value);                // Write to register
              I2C_MasterSendStop();                    // End of transaction

             

          When you want to read from a device you use (example for reading two bytes

             

              I2C_MasterSendStart(DeviceAddress,I2C_WRITE_XFER_MODE);    // Initialize a transaction for writing
              I2C_MasterWrite(Register);                // Indicate which register you want to write to
              I2C_MasterSendRestart(DeviceAddress,I2C_READ_XFER_MODE);
              I2C_MasterReadByte(I2C_ACK_DATA);            // Read from register
              I2C_MasterReadByte(I2C_NAK_DATA);            // Read from register, last byte is NAKed
              I2C_MasterSendStop();                    // End of transaction

             

          Not too difficult. Keep in mind that most of the APIs (except those for reading a byte) return a status byte which, when non-zero indicate an error condition.

             

          Bob

          • 2. Re: PSOC4 I2C master issue
            mao.xguo

            Thanks for your great support! Bob, now the module works well.

            • 3. Re: PSOC4 I2C master issue
              user_1377889

              You are always welcome!

                 

               

                 

              Bob