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

I2C >> Bit Error when compiling for 160 MHz #6497

Closed
5 tasks done
detamend opened this issue Sep 9, 2019 · 9 comments
Closed
5 tasks done

I2C >> Bit Error when compiling for 160 MHz #6497

detamend opened this issue Sep 9, 2019 · 9 comments

Comments

@detamend
Copy link

detamend commented Sep 9, 2019

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • I have filled out all fields below.

Platform

  • Hardware: Wemos D1 mini pro (ESP8266)
  • Core Version: 2.5.2
  • Development Env: Arduino IDE
  • Operating System: Windows 10 x64

Settings in IDE

  • Module: Wemos D1 mini pro
  • Flash Mode: not sure (using IDE)
  • Flash Size: 4MB
  • lwip Variant: v2 Higher Bandwidth
  • Reset Method: not sure
  • Flash Frequency: not sure (IDE)
  • CPU Frequency: 80Mhz AND 160MHz
  • Upload Using: SERIAL
  • Upload Speed: 115200

Problem Description

Trying to let two ESPs talk to each other via I2C - easy, right? Obviosly not, when boths CPUs running at 160 MHZ.

SENDER SKETCH

#include <Wire.h>

#define SDA_PIN 4
#define SCL_PIN 5

#define sender 0x42
#define reciver 0x08

void setup(){
  Serial.begin(115200);
  Wire.begin(SDA_PIN,SCL_PIN,sender);
}

void loop(){
  Wire.beginTransmission(reciver);
  Wire.write("aaAA");
  Wire.endTransmission();
  delay(1000);
}

RECIVER SKETCH

#include <Wire.h>

#define SDA_PIN 4
#define SCL_PIN 5

#define sender 0x42
#define reciver 0x08

void setup(){
  Serial.begin(115200);
  Wire.begin(SDA_PIN,SCL_PIN,reciver);
  Wire.onReceive(receiveEvent);
}

void receiveEvent(size_t bytesRecived){
  (void) bytesRecived;
  String command;
  byte c;

  while(Wire.available()){
    c=Wire.read();
    Serial.print(c);
    Serial.print("\t");
    Serial.println(c,BIN);
    command+=(char)c;
  }
  Serial.println(command);
  Serial.println("---------");
}

void loop(){
  delay(1);
}

Compiled with both CPUs are running at 80 MHz, the reciver gets "aaAA" from the sender.

If I compile both scripts at 160 MHz CPU speed, the reciver gets

?aAA

instead.

To get an idea, whats been send/recived, I dumped every recived by in the reciver script:

225	11100001
97	1100001
65	1000001
65	1000001
?aAA

So the first bit of the data should have been 0 - but gets recived as 1. This sets the MSB of the first byte to 1, changing the expected 97 to a 225.

I use two 2k2 resistors as pullups on the SCL/SDA lines. Sadly no logic analyzer around, so I can't pinpoint the sender or reciver as the culprit.

The boards are connected via a triple base board, only two CPU Modules are plugged in.

Any help would be greatly appreciated! I know: simply go back to 80 MHz... but I really like to get this setup working.

@detamend
Copy link
Author

detamend commented Sep 10, 2019

Got my trusty Oscilloscope going and compared the signals for CPU@80MHz and CPU@160MHz. I'm sending to Adress 0x08 and transmitting a single Character: "S". S in binary reads 01010011.

On 80MHz I recive 01010011 (as expected).
On 160MHz I recive 11010011 (fist bit should be 0).

Besides the error, the timing is quite different. Running 80MHz, one cycle is roughly 23us. @160MHz a typical cycle is 17us.

On the screenshots of the oscilloscope it' s pretty obvious, that the first bit of 01010011 is not low when the CPU is running at 160MHz.

i2cProb

@Jason2866
Copy link
Contributor

Maybe the same issue as #5762

@detamend
Copy link
Author

Maybe the same issue as #5762

I read that issue - definitly related.

@Jason2866
Copy link
Contributor

Can you try this?
arendst/Tasmota#6360 (comment)

@detamend
Copy link
Author

detamend commented Sep 12, 2019

Removing those two interrupts breaks the reciver completely even at 80 MHz (the script outputs nothing).

Sadly, that's not it, but thanks a lot, @Jason2866 !

@TD-er
Copy link
Contributor

TD-er commented Oct 3, 2019

Maybe this one is related?
#6592

The PR description has a lot of links referring to the original issue and a detailed readme page describing what the original author tries to fix.

@detamend
Copy link
Author

detamend commented Oct 14, 2019

@TD-er - definitly related. Just replaced the core_esp8266_si2c.cpp with the one from the PR - now works like a charm (even at 160MHz).

Great Job, guys!

@devyte
Copy link
Collaborator

devyte commented Nov 9, 2019

#6592 is merged and released.
Closing.

@devyte devyte closed this as completed Nov 9, 2019
@laercionit
Copy link
Contributor

I am using CORE 2.7.2 I have the same problem, anyone else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants