1 Reply Latest reply on Jun 22, 2018 3:07 AM by martyn.gallop_1759861

    I2C I2CM_0_MasterReadBuf() is limited to 256 byte transfer. How to increase this?

    martyn.gallop_1759861

      I need to read more than 256 bytes from an I2C peripheral in a single transfer.

      The standard component I2CM_0_MasterReadBuf() and associated ISR are limited to 256 bytes due to the cnt variable being uint8 instead of (a more useful) uint16. This is something that does not appear to be configurable at the build level.

      I can create a copy of the API function to use locally but is there any way to override the ISR in the build with my own version where I can also change the counter size?

        • 1. Re: I2C I2CM_0_MasterReadBuf() is limited to 256 byte transfer. How to increase this?
          martyn.gallop_1759861

          I have resolved this, the trick is in the mode parameter I2CM_MasterReadBuf().

           

          I was able to split the transfer into two consecutive calls:

          for the first mode = I2C_MODE_NO_STOP,

          for the second mode = I2C_MODE_RESTART.

           

          However it's not clear how you could do more than two blocks in a transfer without a STOP, I tried consecutive intermediate blocks with each  setting mode to:

          I2C_MODE_REPEAT_START

          I2C_MODE_NO_STOP

          I2C_MODE_REPEAT_START | I2C_MODE_NO_STOP   /* this is really what you want to work */

           

          The first of these puts a stop on the bus, the latter two end up at the CYASSERT() in the ISR

           

                      case I2CM_0_SM_MSTR_RD_ADDR:  /* After address is sent, read data */

          .........

           

                          else

                          {

                              /* Address phase is not set for some reason: error */

                              #if(I2CM_0_TIMEOUT_ENABLED)

                                  /* Exit interrupt to take chance for timeout timer to handle this case */

                                  I2CM_0_DisableInt();

                                  I2CM_0_ClearPendingInt();

                              #else

                                  /* Block execution flow: unexpected condition */

                                  CYASSERT(0u != 0u);

                              #endif /* (I2CM_0_TIMEOUT_ENABLED) */

                          }

                          break;

           

          Fortunately < 512 bytes is enough for my application!