Author Topic: ESP8266 and Atmega8 I2C Not Working  (Read 225 times)

0 Members and 1 Guest are viewing this topic.

Offline Swaroop 21Topic starter

  • Contributor
  • Posts: 47
  • Country: in
ESP8266 and Atmega8 I2C Not Working
« on: August 27, 2024, 01:33:30 pm »
I am trying to establish a connection between a ESP12F and a Atmega8 uC. The Atmega8 is running at 8Mhz. I tried this I2C communication between two normal Arduino Nanos and it worked. Then I tried with another Arduino Nano which I put 8Mhz Bootloader and it worked too. But when I try to use the ESP it doesn't work. I tried both Normal Nano with 16Mhz and at 8Mhz but it doesn't work, I tried pull-up resistors to 3.3V and still doesn't work. Is there any compatibility issue with ESP12 ?

This is the Master Side:
Code: [Select]

#include <Wire.h>
byte x = 0;                       

void setup()
{
  Wire.begin();                       
}

void loop()
{
  Wire.beginTransmission(4);
  Wire.write("x is ");
  Wire.write(x);
  Wire.endTransmission();

  x++;
  delay(500);
}



This is the Slave Side:


Code: [Select]
#include <Wire.h>


void setup()
{
  Wire.begin(4);
  Wire.onReceive(receiveEvent);
  Serial.begin(9600);
}


void loop()
{
  delay(100);
}


void receiveEvent(int howMany)     
{
  while(1 < Wire.available())       
  {
    char c = Wire.read();         
    Serial.print(c);             
  }
  int x = Wire.read();
  Serial.println(x);
}


on the slave side it will print the value of 'x'
Code: [Select]
19:04:10.611 -> x is 51
19:04:11.146 -> x is 52
19:04:11.640 -> x is 53
19:04:12.136 -> x is 54
19:04:12.635 -> x is 55
19:04:13.121 -> x is 56
 

Offline Gadjet

  • Contributor
  • Posts: 28
  • Country: gb
    • My Blog
Re: ESP8266 and Atmega8 I2C Not Working
« Reply #1 on: August 28, 2024, 10:33:48 am »
I've never done it myself but this link makes it seem doable
https://github.com/cunchem/I2C_esp8266ToArduinoUno

Online Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3822
  • Country: nl
Re: ESP8266 and Atmega8 I2C Not Working
« Reply #2 on: August 30, 2024, 02:30:31 pm »
Start with buying one of those Saleaeae clone logic anaysers for EUR 10. (8 ch 24MHz). and use it with Sigrok / Pulseview. It lets you see what is actually happening on the I2C bus, and this determines whether the sender or the receiver has unexpected behavior.

You can use the extra channels to output a debug signal, for example toggle a bit every time an ISR is triggered. This lets you correlate what happens on the I2C bus with what firmware of the uC is doing at that same time.

Another option is something wrong (or even omitting) the I2C pullup resistors (or even the wiring). If the pullup resistors are not strong enough compared to your bus capacitance and bitrate, then you will never get reliable communication.
Beginners also do not always realize both circuits need a common GND for communication to work reliably.


on the slave side it will print the value of 'x'
Code: [Select]
19:04:10.611 -> x is 51
19:04:11.146 -> x is 52
19:04:11.640 -> x is 53
19:04:12.136 -> x is 54
19:04:12.635 -> x is 55
19:04:13.121 -> x is 56

What do you mean with "does not work"?

« Last Edit: August 30, 2024, 02:39:05 pm by Doctorandus_P »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf