Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with unwanted read or write after I2C operation #709

Merged
merged 2 commits into from
May 31, 2018

Conversation

josesimoes
Copy link
Member

@josesimoes josesimoes commented May 28, 2018

Description

  • Properly set ReadSize and WriteSize vars when setting up I2C operation (always have to set these, otherwise they'll be "reusing" the values from the last operation when there was no read or write buffer causing unwanted read or write after the real operation)
  • This affects only the STM32 targets.

Motivation and Context

How Has This Been Tested?

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Signed-off-by: josesimoes [email protected]

@josesimoes josesimoes added Type: bug Series: STM32xx Everything related specifically with STM32 targets labels May 28, 2018
@nfbot
Copy link
Member

nfbot commented May 28, 2018

Hi @josesimoes,

I'm nanoFramework bot.
Thank you for your contribution!

A human will be reviewing it shortly. 😉

@josesimoes josesimoes changed the title Fix bug with wrong read after write in STM32 I2C Fix bug with unwanted read or write after I2C operation May 28, 2018
@josesimoes
Copy link
Member Author

josesimoes commented May 31, 2018

@MikroBusNet could please give this one a try with your collection of I2C devices? TIA!

@ghost
Copy link

ghost commented May 31, 2018

First functionnal tests seem to show that it is working. I get expected results on (almost) all devices I have checked.
I have used a Quail with two eeproms, one ADXL345, one BME280 and one CY8C201A0. The latter failed (see below).

I have commited (by error as I wanted to create a branch) a change in the managed assembly to enable address "0", however. This address is valid and is used by some devices (e.g. CY8C201A0).

I will make more tests with the logic analyzer to confirm that the data sent/received is what is expected.

@ghost
Copy link

ghost commented May 31, 2018

Complete test sequence with an Eeprom :

_eeprom.ReadByte(0);
0.000010000000000,I2C,Setup Write to ['172' (0xAC)] + ACK
0.000145550000000,I2C,'0' (0x00) + ACK
0.000235550000000,I2C,'0' (0x00) + ACK
0.005410450000000,I2C,Setup Read to ['173' (0xAD)] + ACK
0.005761900000000,I2C,'16' (0x10) + NAK

_eeprom.WriteByte(0, 17);
0.006406900000000,I2C,Setup Write to ['172' (0xAC)] + ACK
0.006609700000000,I2C,'0' (0x00) + ACK
0.006699700000000,I2C,'0' (0x00) + ACK
0.006789700000000,I2C,'17' (0x11) + ACK

_eeprom.ReadByte(0);
0.012066100000000,I2C,Setup Write to ['172' (0xAC)] + ACK
0.012229450000000,I2C,'0' (0x00) + ACK
0.012319450000000,I2C,'0' (0x00) + ACK
0.017516800000000,I2C,Setup Read to ['173' (0xAD)] + ACK
0.017840850000000,I2C,'17' (0x11) + NAK

_eeprom.ReadByte(231);
0.018449900000000,I2C,Setup Write to ['172' (0xAC)] + ACK
0.018545200000000,I2C,'0' (0x00) + ACK
0.018635200000000,I2C,'231' (0xE7) + ACK
0.023811500000000,I2C,Setup Read to ['173' (0xAD)] + ACK
0.024035050000000,I2C,'17' (0x11) + NAK

_eeprom.WriteByte(231, 18);
0.024659600000000,I2C,Setup Write to ['172' (0xAC)] + ACK
0.024755200000000,I2C,'0' (0x00) + ACK
0.024845200000000,I2C,'231' (0xE7) + ACK
0.024935200000000,I2C,'18' (0x12) + ACK

_eeprom.ReadByte(231);
0.030169200000000,I2C,Setup Write to ['172' (0xAC)] + ACK
0.030264550000000,I2C,'0' (0x00) + ACK
0.030354550000000,I2C,'231' (0xE7) + ACK
0.035516950000000,I2C,Setup Read to ['173' (0xAD)] + ACK
0.035612500000000,I2C,'18' (0x12) + NAK

_eeprom.WriteData(400, new Byte[] { 53, 54, 55 }, 0, 3);
0.036245650000000,I2C,Setup Write to ['172' (0xAC)] + ACK
0.036464500000000,I2C,'1' (0x01) + ACK
0.036554450000000,I2C,'144' (0x90) + ACK
0.036644450000000,I2C,5 (0x35) + ACK
0.036734450000000,I2C,6 (0x36) + ACK
0.036824450000000,I2C,7 (0x37) + ACK

_eeprom.ReadData(400, Data, 0, 3);
0.042056850000000,I2C,Setup Write to ['172' (0xAC)] + ACK
0.042351050000000,I2C,'1' (0x01) + ACK
0.042441050000000,I2C,'144' (0x90) + ACK
0.047610900000000,I2C,Setup Read to ['173' (0xAD)] + ACK
0.047713400000000,I2C,5 (0x35) + ACK
0.047803400000000,I2C,6 (0x36) + ACK
0.047893400000000,I2C,7 (0x37) + NAK

This is expected communication.

@josesimoes
Copy link
Member Author

@MikroBusNet thank you vey much for your thorough testing and reporting! 💯 🥇

@josesimoes josesimoes merged commit 2adfd34 into nanoframework:develop May 31, 2018
@josesimoes josesimoes deleted the fix-319 branch May 31, 2018 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Series: STM32xx Everything related specifically with STM32 targets Type: bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

I2C does not send correct data
2 participants