Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

AVR I2C: Error reading several bytes from slave

2 posters

Go down  Message [Page 1 of 1]

1AVR I2C: Error reading several bytes from slave Empty Reading 2 bytes from I2C slave ? Thu May 06, 2021 10:25 pm

BenZr



Hi,
I have a nearly working implementation of MAXIM DS 1621 I2C Digital Thermometer in SimulIDE.  I am testing the DS1621 as an I2C slave with an Arduino Mega as I2C master. I have problem reading 16 bits from the slave, I only get 8 bits. It looks like a problem of ACK from the master after reading the first byte.  A work around is to make twice 8 bits read at consecutive addresses but this does not work on the real chip.

I use the Wire library on the Arduino and when I request two bytes as said in the data sheet , I only get the msbyte; The code is :

Code:
Wire.beginTransmission(Address);
Wire.write(0xAA);
Wire.endTransmission();
Wire.requestFrom(Address,2);  
if (Wire.available()) msbyte = Wire.read();
delayMicroseconds(100);
if (Wire.available()) lsbyte = Wire.read();


When requesting 1 byte twice it works fine  on SimulIDE but not on the real chip. The code is:

Code:
Wire.beginTransmission(Address);
Wire.write(0xAA);
Wire.endTransmission();
Wire.requestFrom(Address,1);  
if (Wire.available()) msbyte = Wire.read();
Wire.beginTransmission(Address);
Wire.write(0xAB);
Wire.endTransmission();
Wire.requestFrom(Address,1);  
if (Wire.available()) lsbyte = Wire.read();

I have tried looking in the examples but I only found 8 bits reading.
Is it a limitation of the simulator or do I have done something wrong  in my implementation maybe of  writeByte() function on the slave ? do I have to handle the change of SDA state (to make an NACK instead of ACK) in the slave writeByte() function ?

Note that except this 16 bits read all other I2C modes are working fine.

arcachofo

arcachofo

Yes, looks like there is a problem:
https://simulide.forumotion.com/t159-arduino-sensor-help#1022

Not sure where is the problem, i'm right now trying to understand how wire library works...

arcachofo

arcachofo

Problem should be solved in 0.4.15 branch Rev 186.
I will update trunk branch soon.

BenZr



Thanks a lot for the quick answer, I will try with the new code . I have seen several changes in e-i2c , is it enough if I copy the new e-i2c.cpp and i-ei2c.h in my project ?

arcachofo

arcachofo

I have seen several changes in e-i2c , is it enough if I copy the new e-i2c.cpp and i-ei2c.h in my project ?
No, all changes are needed.

arcachofo

arcachofo

I didn't realize you are you...

Which simulide version are you using currently for your project?

BenZr



Yes it's me ,and I think I will make more use of the forum as I found very interesting reading the discussions on various topics.  

The "production version" for my labs for the students during this academic year is based on 0.3.12-SR8.
https://gitlab.ensta-bretagne.fr/zerrbe/SimulIDESense

I am also working on next academic year version based  on  0.4.15-SR1. You have put very interesting new stuff. As I do not want to pollute to much your code on this new version, I have added a separate category "ENSTA Bretagne experimental" in the bottom of the component library on the right of the GUI.

If it can be useful for you, I can give you access to my GitLab with this new version (not yet public for the time being) : the new experimental stuff is a LED coupled to a LDR sensor (to simulate optical com) and the MAXIM DS1621 U2C temperature sensor.

For testing the I2C master (Arduino Mega) reading the two bytes sent by the slave (MAXIM DS1621), I will use your updated 0.4.15 trunk as you suggested in a previous message.

arcachofo

arcachofo

am also working on next academic year version based  on  0.4.15-SR1.
Ok, I was a bit confused because 0.3.X versions don't have I2C master suport.

If it can be useful for you, I can give you access to my GitLab with this new version (not yet public for the time being) : the new experimental stuff is a LED coupled to a LDR sensor (to simulate optical com) and the MAXIM DS1621 U2C temperature sensor.
That would be nice, I'm very interested in your developments.

For testing the I2C master (Arduino Mega) reading the two bytes sent by the slave (MAXIM DS1621), I will use your updated 0.4.15 trunk as you suggested in a previous message.
Just in case (this can be confusing):
There are 2 branches right now:

0.4.15: https://launchpad.net/simulide/0.4.15
Commits: https://bazaar.launchpad.net/~arcachofo/simulide/simulide_0.4.14/changes
This in the one you are using as far as I understand.
This version is the last one in the "old generation" simulide.
It reached "Final" state: No more new components and features will be added.
Stable version is sheduled to be released at July, after solving as many problems as possible.
It is intended to be an LTS with bug fixes for some time after "stable" is released.

trunk: https://launchpad.net/simulide/trunk
Commits: https://bazaar.launchpad.net/~arcachofo/simulide/trunk/changes
This is the development version where all new stuff is being done.
This version is the first one in the "new generation" simulide:
- New Simulation engine with time resolution of 1ps.
- New MCU Simulator that will replace external simulators (Gpsim and Simavr).
- Multi-MCU simulation.
- Logic Devices accurate propagation delay.
- Custom Compilers can be added.
- New dialogs for almost everything (including Component Properties).
- Many optimizations done across all the source code.


About 0.4.15 and your components:
I tried to integrate your sensors in the "Variable Resistor" class hierarchy along with other resistive sensors.
Also thinking in making them as generic as possible.
This simplifies a lot the source code but can be confusing as well.

But these components are not fully implemented.
For example Strain Gauge does not implement response time, it just jumps to the final value.
I didn't get into this as this need some more work, probably some intermediate class that handles response time for all these devices.

BenZr likes this post

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum