3 Replies Latest reply on Dec 24, 2015 4:21 AM by user_274318315

    Interrupt free I2C functions ...

    user_274318315

      Greetings.

         

      We are testing PSOC I2C interaction with some 3rd party devices and getting odd results using the high-level MasterXXX functions. To try and isolate issues and ensure fewer unintended consequences I've written I2C read and write functions that follow the following patterns. They appear to work more consistenly but we are still seeing some odd errors. Would anyone care to critique and/or comment? I would be much obliged!

         

      TVMIA

         

      Jerry

         

      ------------------------------------------------------------------------------------------

         

      // N.B. all function return values are checked by a general purpose error flag decoder if return value is not I2C_MSTR_NO_ERROR

         

      // N.B I2C_Master interrupts are all disabled and cleared at startup

         

          I2C_DisableInt();
          I2C_ClearPendingInt();

         

      // I2CWrite pattern

         

      I2C_MasterSendStart(device_address, I2C_WRITE_XFER_MODE); // send start write mode

         

      I2C_MasterWriteByte(register_address); // register address on the device is 8 bits

         

      I2C_MasterWriteByte(data[0..N-1]); // write N bytes to the bus

         

      I2C_MasterSendStop();  // send stop

         

      // I2CRead pattern

         

      I2C_MasterSendStart(device_address, I2C_WRITE_XFER_MODE); // we need to write the register address before we read

         

      I2C_MasterWriteByte(register_address); // write it

         

      I2C_MasterSendRestart(device_address, I2C_READ_XFER_MODE); // switch transfer mode as we now wish to read

         

      data[0..n-1] = I2C_MasterReadByte(I2C_NAK_DATA); // read N bytes

         

      I2C_MasterSendStop();  // and then stop the I2C transaction.

         

      ------------------------------------------------------------------------------------------