I2C can not read more than 20 data in one time

Any bugs you encounter with Flowcode should be discussed here.
Xbiotec
Posts: 217
http://meble-kuchenne.info.pl
Joined: Thu Sep 23, 2021 3:44 pm
Location: France
Has thanked: 35 times
Been thanked: 26 times

I2C can not read more than 20 data in one time

Post by Xbiotec »

hi,
I'm working on I2c with I2C master with TTGO ESP32, I found that transaction read is working well with length (LengthToRead)<=20 if more than 20 not working.
I2C read.jpg
I2C read.jpg (142.09 KiB) Viewed 7234 times
I2CRead.fcfx
(20.38 KiB) Downloaded 674 times
Thx for your prompt reply
Seb

LeighM
Valued Contributor
Posts: 489
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 83 times
Been thanked: 262 times

Re: I2C can not read more than 20 data in one time

Post by LeighM »

Hi Seb,
The size of the Data buffer needs increasing

Code: Select all

Data[20]
can only hold up to 20 bytes.
This needs to be Data[24] to accept a read of 24 bytes.

Xbiotec
Posts: 217
Joined: Thu Sep 23, 2021 3:44 pm
Location: France
Has thanked: 35 times
Been thanked: 26 times

Re: I2C can not read more than 20 data in one time

Post by Xbiotec »

Hi,
I put to 20 before to send you to make a test and forget to replace by 24 but even if you increase it to 24 the result will be NG.
Seb

LeighM
Valued Contributor
Posts: 489
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 83 times
Been thanked: 262 times

Re: I2C can not read more than 20 data in one time

Post by LeighM »

Ah, OK.
Yes, I've just checked the generated code and you are correct.
The I2C Master component is limiting the buffer size to 20 bytes, as passed to the I2C CAL component, and the CAL C then inhibits the transfer of 24 bytes into a 20 byte buffer.
A quick fix would be for you to directly use the I2C CAL component, rather than the I2C Master component (until it gets fixed).
Component Libraries -> Search

Xbiotec
Posts: 217
Joined: Thu Sep 23, 2021 3:44 pm
Location: France
Has thanked: 35 times
Been thanked: 26 times

Re: I2C can not read more than 20 data in one time

Post by Xbiotec »

ok thx, do you think this could be fixed next week ?
Seb

medelec35
Matrix Staff
Posts: 2086
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 644 times
Been thanked: 702 times

Re: I2C can not read more than 20 data in one time

Post by medelec35 »

Hi Seb, it's a balance between how many bytes and how much memory that's used.
If you let me know how many bytes you wish to read, I can increase the buffer size accordingly as a temp measure.
Martin

mnfisher
Valued Contributor
Posts: 1628
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 142 times
Been thanked: 761 times

Re: I2C can not read more than 20 data in one time

Post by mnfisher »

A possible easy fix...

In i2c_master:

Code: Select all

MX_UINT16 FCD_005f1_I2C_Master1__Transaction_Read(MX_UINT8 *FCL_BUFFER, MX_UINT16 FCLsz_BUFFER, MX_UINT16 FCL_LENGTH)
{
    //Local variable definitions
    MX_UINT16 FCR_RETVAL;


    // .Return = cal_i2c :: Transaction_Read(.Buffer, .Length)
    FCR_RETVAL = FC_CAL_I2C_Transaction_Read_1(FCL_BUFFER, 20, FCL_LENGTH);   // Change 20 to FCLsz_BUFFER

    return (FCR_RETVAL);
}
The call to i2c::TransactionRead has a size of 20 hardcoded in - this should be FCLsz_BUFFER. This shouldn't affect the memory usage of the library as the buffer is passed by reference - and the user controls how big the buffer is...
The cal_i2c_transaction read returns nothing if length > size of buffer so at present requesting anything >20 bytes will fail...

Martin

Xbiotec
Posts: 217
Joined: Thu Sep 23, 2021 3:44 pm
Location: France
Has thanked: 35 times
Been thanked: 26 times

Re: I2C can not read more than 20 data in one time

Post by Xbiotec »

Could tell me what should I do ?
I'm not sure to understand.
Seb

mnfisher
Valued Contributor
Posts: 1628
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 142 times
Been thanked: 761 times

Re: I2C can not read more than 20 data in one time

Post by mnfisher »

The fix needs to be applied to the component code - so is a fix for Matrix...

However, you can test it...

Try:
I2CReadTest.fcfx
(21.37 KiB) Downloaded 526 times
Note - the call to the macro Read instead of using the component's read..

Martin

Xbiotec
Posts: 217
Joined: Thu Sep 23, 2021 3:44 pm
Location: France
Has thanked: 35 times
Been thanked: 26 times

Re: I2C can not read more than 20 data in one time

Post by Xbiotec »

it work's thx
Seb

Post Reply