Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ESP8266 Wemos D1 mini I2C problem.

Xenon02

Full Member level 3
Joined
Nov 12, 2022
Messages
157
Helped
0
Reputation
0
Reaction score
0
Trophy points
16
Activity points
2,205
Hello !

I've been having problem with I2C with ESP8266. I send the address from my STM32L073RZ, but I don't get ACK bit from ESP8266, I've checked the pins and I think they are okey.

Here is the code for ESP8266 :
Code:
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <NTPClient.h>
#include <Wire.h>

// Zastąp poniższe wartości danymi Twojej sieci WiFi
const char* ssid = ":>>>>>>>>>>>";
const char* password = "NOPE";

#define Status D4

WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000);

void setup(){
  pinMode(D4, OUTPUT); //Pin odpowiedzialny za gotowość urządzenia do komunikacji przez I2C
  digitalWrite(D4, LOW); //Ustawiamy go na początku na "0".

  Serial.begin(9600);
  WiFi.begin(ssid, password);

  while ( WiFi.status() != WL_CONNECTED ) {
    delay ( 500 );
    Serial.print ( "." );
  }

  timeClient.begin();

  Wire.begin(8); // Odpala D2 jako SDA i D1 jako SCL jako slave
  Wire.onRequest(sendTime); //Rejestracja funkcji zwrotnej, która zostanie wywołana, gdy urządzenie nadrzędne zażąda danych

  digitalWrite(D4, HIGH); //Tutaj konfiguracja z siecią jak i też konfiguracja z pinami i ustawienie I2C jest zakończone
                          //i sygnalizowane stanem wysokim na D4
}

void loop() {
  timeClient.update();
  Serial.println(timeClient.getFormattedTime());
  delay(1000);
}

void sendTime() {
  String time = timeClient.getFormattedTime();
  Wire.write(time.c_str()); // Wysłanie czasu do urządzenia nadrzędnego będzie to razem 8 bajtów bo jeszcze znaki oddzielające.
}

And here is only the part of STM code I am using
Code:
      xD = HAL_I2C_Master_Receive(&hi2c2, 0x08<<1, czas, 8, 1000);
      HAL_Delay(1000);

static void MX_I2C2_Init(void)
{

  /* USER CODE BEGIN I2C2_Init 0 */

  /* USER CODE END I2C2_Init 0 */

  /* USER CODE BEGIN I2C2_Init 1 */

  /* USER CODE END I2C2_Init 1 */
  hi2c2.Instance = I2C2;
  hi2c2.Init.Timing = 0x00303D5B;
  hi2c2.Init.OwnAddress1 = 0;
  hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  hi2c2.Init.OwnAddress2 = 0;
  hi2c2.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
  hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
  if (HAL_I2C_Init(&hi2c2) != HAL_OK)
  {
    Error_Handler();
  }

  /** Configure Analogue filter
  */
  if (HAL_I2CEx_ConfigAnalogFilter(&hi2c2, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
  {
    Error_Handler();
  }

  /** Configure Digital filter
  */
  if (HAL_I2CEx_ConfigDigitalFilter(&hi2c2, 0) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN I2C2_Init 2 */

  /* USER CODE END I2C2_Init 2 */

}

Here is also the info from Logic Analyzer :

obraz_2024-01-17_013221406.png


I've also checked if I connected it correctly and I did, SDA to D2 and SCL to D1.
There are also pull ups turned on in STM32 ... I don't know where is the problem. I've also changed the pins speed ? And it also didn't work.
 
Hi,

your ESP code says address of 8 (which I would write as 0x08)
but in the timing diagram it shows an address of 0x11.

So maybe it´s the old I2C problem how the address is defined.
Some define it as 0x08 to be shifted 1 bit left: addr_out = (I2C_addr << 1) | RW
the other define it as is not shifting: addr_out = (I2C_addr & 0xFE) | RW
(RW is the RW bit, sent out as LSB of the address byte)

Thus try to use address of 0x04 on your ESP code. With unmodified STM code

Again: I did non check all of your code.

Klaus
 
Found out what was the problem.
It happened that ESP8266 Wemos D1 mini, doesn't work on Slave mode. Only on Master mode.
 
It happened that ESP8266 Wemos D1 mini, doesn't work on Slave mode. Only on Master mode.
many internet sources say it works. On the other hand I see a lot of problems, too.

So, if some made it work, it should be not impossible. I personally don´t see a technical reason why it should ot work.

Klaus
 
From some sources I read that communication by I2C with Esp to Esp might work as Slave but other than that it won't. Or perhaps wemos doesn't have this ability. Because it physically/hardware doesn't have the slave.
I tried literally everything. It doesn't work.Simply he doesn't recognize the first byte that says either the master sends or receives.

There were also do theoretical problems which I did not understand and may ask in the near future the theoretical problem here but only theory.
 
Hi,

What I´d do to narrow the problem:
* use a scope to check voltage levles and timing, rise/fall times. Cross check them against datasheets.
* use a relaxed setup (low speed) on both M and S
* be sure to set up the one in slave mode, the other in Master mode
* be sure to both M and S set up in 7 bit address mode
* then run a loop on a Master to access slaves with address from 0b0000 000r to 0b1111 111r and check ACK.
* find out if and at which addresses there is response.

Klaus
 
use a scope to check voltage levles and timing, rise/fall times. Cross check them against datasheets.

Here is a problem because I don't have the oscilloscope and I don't understand fully the timings. I read something that it was a stupid idea to use I2C because the clock is 100kHz and the slave clock is 80MHz which he has a tiny space of 5us. This topic I wanted to leave as a theory I don't understand and where these calculations come from. Or rather I wanted to learn how to understand timings here but in a different topic.

* use a relaxed setup (low speed) on both M and S
* be sure to set up the one in slave mode, the other in Master mode
* be sure to both M and S set up in 7 bit address mode
* then run a loop on a Master to access slaves with address from 0b0000 000r to 0b1111 111r and check ACK.
* find out if and at which addresses there is response

I've tried it as well ;> I gave up on I2C and used UART

PS here is the link https://arduino.stackexchange.com/q...espond/95322?noredirect=1#comment221051_95322
 
it was a stupid idea to use I2C because the clock is 100kHz and the slave clock is 80MHz which he has a tiny space of 5us.
I don´t see any stupid here. It´s quite a ususal setup.

I mean: almost every microcontroller (even tiny) has an internal I2C perifieral. There is no need for the microcontroller to react in 5us of time at all, since the hardware supports this.

****
In the end I agree with you that the use of an async interface like UART is easier to use for master - slave communication.
But in detail it depends on your application.

Klaus
 
I don´t see any stupid here. It´s quite a ususal setup.

I mean: almost every microcontroller (even tiny) has an internal I2C perifieral. There is no need for the microcontroller to react in 5us of time at all, since the hardware supports this

I mean I also didn't understand it so that's why I sent a link.

Maybe it is a time to read a code ? Dunno. I just assumed that the time the code is read and interpreted takes time. I just leave it as a theoretical question to another post to not waste your time because I needed to elaborate more on this topic or ask more simple question. Like I said I still am not that skilled yet in that field.

In the end I agree with you that the use of an async interface like UART is easier to use for master - slave communication.
But in detail it depends on your application.

Rather than application because it didn't matter to me which one to use is rather the frustration and the fact that I've toasted by accident the eps so yea ... Got to wait for new one.
 
I've toasted by accident the eps
How? Why?

If you are not experineced .. and doing tests: I can recommend to use a current limitng resistor on every critical IO. Usually 100 Ohms don´t hurt the signal, but limit the current to 33mA worst case (@ 3.3V).

Especially when two IOs of different microcontrollers are connected .. where the one maybe did not switch to "input" in time .. or wrong firmware, or firmware not loaded yet, or firmware stalls .... and so on.

Klaus
 
How? Why?

Just accidently connected 5V to GND. I was just changing the connection and from tiredness it happened. Just accident. Nothing more.

And by not experienced I mean something like timing how the speeds are calculated or time it has to do something etc. But like I said. In another topic
 
Hi,

5V to GND --> then I guess it´s just a killed diode. You may even short circuit it - as long as you don´t use a second power source.
It just protects the USB against reverse power.

******

And yes, I recommend to buy / lend something to validate voltage levels and timing.
I personally find the ADALM2000 rather useful. Especially because of it´s ability to be controlled with external (your own written) software.
It´s not the cheapest, though. But it includes voltmeter, oscilloscope, logic analyzer (with I2C decoder) and much more. Rather useful, but not for very high frequency.

Cheaper devices for sure are available.

Klaus
 

LaTeX Commands Quick-Menu:

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top