X
Xenon02
Guest
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 :
And here is only the part of STM code I am using
Here is also the info from Logic Analyzer :
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.
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 :
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.