This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Unable to write 8210 bytes on I2c bus

Hi,

I am facing the issue of sending 8210 bytes of data to my slave device.

I am using NRF52840 interfaced with the MAX32664 maxim sensor hub.

I tried both approaches to transmit data with a legacy as well as easyDMA enabled case.

On the forum, I found a similar case on this link "i2c message max buffer size - Nordic Q&A - Nordic DevZone - Nordic DevZone (nordicsemi.com)" however could not resolve the issue.

observation made on the saleae logic analyzer:

when tried to transmit 

1)8210 bytes - it sends the first 18 bytes data + write address

2)8192 bytes - it sends the 0 bytes of data + write address (code gets stuck)

3)8191 bytes - it sends the first 255 bytes of data + write address 

4)8190 bytes - it sends the first 254 bytes of data + write address 

5) 7936 BYTES - it sends the 0 bytes of data + write address (code gets stuck)

I am failing to understand this buffer overflow at multiples of 256(case 2 and case 5).....

I did try sending the data into chunks of 200 without issuing stop byte and at the end of 8210th byte sent the stop bit, but the slave responds with an illegal command sequence error.

Info:

NRF52840 custom board 

NRF SDK17 is used

18 bytes + write address

255 bytes +write address

  • Hi Jorgen,

    I migrated from code nrfx_twi to nrfx_twim successfully.

    I want to write 28 pages  (28 x 8210bytes) 1 page at a time.

    for the same, I have made 28 static buffers in the code containing 8210 bytes in a sequence.  

    Now with your suggestions, I have written 13 pages successfully out of 28 but as soon as it tries to write the 14th page the function returns error code 16.

    what error code 16 refers to?

    how do I resolve it?

    Thank you 

    -Gaurav

  • Hi,

    Error code 16 means NRF_ERROR_INVALID_ADDR. If you are declaring 28 static buffers containing 8210 bytes, this will consume 224kB of RAM, which is almost the full RAM size of the nRF52840 (256kB).

    From the API documentation for nrfx_twim_tx, you can see the reason for this error code:

    NRFX_ERROR_INVALID_ADDR The provided buffer is not placed in the Data RAM region.

    Most likely, the buffers does not fit in RAM and cause some issues. Do you need to declare all buffers at once, or can you re-use the same buffer for more than one transfer? Storing the data in flash initially and copy it to one or a couple buffers while transmitting may be a better approach.

    Best regards,
    Jørgen

  • Hi Jorgen,

    Thanks for your help, each and every suggestion given by you helped me narrow down my issues.

    I ultimately resolved the issue and able to write all the pages successfully.

    I wanted to tag your second last reply as a verified answer but it doesn't show me options.

    Thanks

    Regards 

    -Gaurav

Related