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.
Thx for your prompt reply
I2C can not read more than 20 data in one time
-
- 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
-
- 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
Hi Seb,
The size of the Data buffer needs increasing
can only hold up to 20 bytes.
This needs to be Data[24] to accept a read of 24 bytes.
The size of the Data buffer needs increasing
Code: Select all
Data[20]
This needs to be Data[24] to accept a read of 24 bytes.
-
- 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
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.
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
-
- 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
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
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
-
- 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
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.
If you let me know how many bytes you wish to read, I can increase the buffer size accordingly as a temp measure.
Martin
-
- 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
A possible easy fix...
In i2c_master:
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
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 cal_i2c_transaction read returns nothing if length > size of buffer so at present requesting anything >20 bytes will fail...
Martin
-
- 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
The fix needs to be applied to the component code - so is a fix for Matrix...
However, you can test it...
Try:
Note - the call to the macro Read instead of using the component's read..
Martin
However, you can test it...
Try:
Note - the call to the macro Read instead of using the component's read..
Martin