Send more than 8192 bytes on nrf9160 using nrfx_twim

This has been asked before i2c message max buffer size but I need a little more info on the the proposed solution "break it up into chunks" from Oyvind.

Using nrfConnect SDK 1.6.1

The MAX32664 requires 8210 bytes in a flash write message between START and STOP conditions. Using the "drivers/i2c" this results in 18 bytes being sent due to TX.MAXCNT overflow.

Using the "drivers/i2c" driver provided you can send two chunks (4000 say, then 4210 bytes)- 1st without STOP and second with a STOP but this results in a repeated start being generated between the two transactions and the MAX32664 doesn't seem to like it.

is there a way to use the nrfx_twim.c driver to send the second chunk without the "repeated START". If anyone has done this with MAX32664 and nrf9160 and I'm sure someone has - any pointers or code fragments would be appreciated.

Mark

  • Hello Mark,

    You are using old version of NCS. Can you please share some part of your code? 

    Thanks.

    Best Regards,

    Kazi Afroza Sultana

  •     #include <drivers/i2c.h>

        #define MAX_PAGE_SIZE 8192
        #define CHECKBYTES_SIZE 16
        extern const struct device * i2c;
        uint8_t send[8210];
        int write_flash_page()
        {
            uint8_t sh_addr = 0x55;
            int err = i2c_write( i2c, send, MAX_PAGE_SIZE + CHECKBYTES_SIZE + 2, sh_addr );
            return err;
        }
    This code will send 18 bytes and STOP

    Using 1.6.1 because the revision of the nrf9160 is B0.

    Not sure it's case of old code - because the TWIM peripheral can only send 8192 bytes in one transaction. More like how do I get the nrfx_twim.c module to send more than the maximum(8192) before sending STOP

    Just a gap in my knowledge - was hoping a twim expert would reply and say "all you have to do is...."

    Or someone who has already done this would reply with some knowledge.

    Thanks

    Mark

  • Hello Mark,

    For nRF9160, the MAXCNT registers are 13 bits wide (0-12) that means you should be able to transfer up to 8192 bytes (which also mentioned in your referred ticket). We do not have any example code when sensor cannot perform the repeated start.  In nRF52, one could use the legacy TWI peripheral, which does not have the same limitation on transfer length like nRF9160 (but would need to update data for each byte being transferred)

    You may try i2c_transfer function (this you can control by yourself, i2c_write has always a stop flag to stop) instead of i2c_write. 

    https://github.com/crfosse/ncs_projects/blob/main/peripheral_zephyr/i2c/src/main.c 

    Thanks.

    Best Regards,

    Kazi

  • Hi Kazi

    I tried your suggestion:

        // send more than 8192 bytes
        #if 1
       void I2C_longwrite_TWIM1( uint8_t address,  uint8_t *buffer, uint32_t length )
        {
            struct i2c_msg msg[2];

            nrf_gpio_pin_set(DBG_IO_1);
            msg[0].buf = (uint8_t *)&buffer[0];
            msg[0].len = length/2;
            msg[0].flags = I2C_MSG_WRITE ;

            msg[1].buf = (uint8_t *)&buffer[length/2];
            msg[1].len = length/2;
            msg[1].flags = I2C_MSG_WRITE | I2C_MSG_STOP;

            i2c_transfer( i2c_dev1, &msg[0], 2, 0x55 );
            nrf_gpio_pin_clear(DBG_IO_1);
        }
        #endif
    But this sends [START][ADDR] [1st half of buffer] .... [START][ADDR][2nd half of buffer][STOP]
    Status read from the MAX32664 after this reports Error code.
    I need to send [START][ADDR][8192 bytes of data] [18 bytes of data] [STOP] to be successful. Any ideas on how you would get the TWIM to do that?
    Thanks
    Mark
  • Hi,

    I got a reply from Twim expert.

    It is not possible to prevent the repeated start for being issued. And it is not possible to send two separate transfers without a start condition on the second transfer. 

    Thanks.

    Best Regards,

    Kazi Afroza Sultana

Related