mavishak / cnss-embedded

1 stars 0 forks source link

Diving in to ESP8266 ESP-01 Wi-Fi Module #12

Open mavishak opened 3 years ago

mavishak commented 3 years ago

References:

ESP8266 - WiFi Module (COMPONENTS 101) - This site was used in order to understand the HC-SR501 PIR Sensor. turning out to be very helpful (so keep note...). Contains pin mapping and normal configuration (along with some other useful information).

The ESP8266 module works with 3.3V only, anything more than 3.7V would kill the module hence be cautious with your circuits.

Can be programmed using Arduino IDE or AT-commands or Lua Script

Note: the image and quats above were taken from the site listed above.

ESP8266 AT Instruction Set (pdf) - _This document provides AT commands list based on ESP8266_NONOSSDK.

mavishak commented 3 years ago

Recognizing Head from Tail

After vigorous research, we reached the following conclusions:

ESP8266 can be used as a Web Client or Server:

  1. It seems that one way to send commands from the application to the STM is by implementing an ESP Web Server. But before we go in that direction we need to check more thoroughly if Firebase can trigger an event:

(see the following links)

Using Firestore with IoT Core for device configuration

Using Firestore with Cloud IoT Core for Device Configuration - LAB

In this lab you will learn how to configure Cloud Functions for Firebase to relay document changes in Cloud Firestore as configuration updates for Cloud IoT Core Devices.

  1. In order to send data from the STM to Firebase we want our ESP to act as a Web Client. There are ALOT of examples for doing this with ArduinoIDE but as of now, we haven't found out how to use this information as we are writing in C with STM32CubeIDE.

  2. It seems that either way the other way to set up the communication is by using AT-Commands using USART between the STM device and the ESP. We found out that a simple way to test this connection is to send a <AT+ENTER> command to the ESP device and see that we receive an answer (OK).

  3. These are links that might help us: STM32 IoT with ESP8266 - (Youtube With HAL) ELECTRONICS HUB - ESP8266 - (there are a lot of examples most in Arduino but it might help) ESP8266-STM32F103 (GitHub) - (This is a link to a repository that uses stm32f10x.h - seems to be doing exactly what we are aiming for might be helpful )

mavishak commented 3 years ago

STM32-ESP8266 USART Connection - Trial and Error

14/01/2021: We connected the STM32 device with the Wi-Fi module (pictures are attached below). We started a test project, where we used a repository: ESP8266-STM32F103 (which uses the STM32F10x Standard Peripherals Library) Attempte to send AT command failed. Need to keep working on it.

(click to enlarge)

mavishak commented 3 years ago

ESP8266-Firebase-AVR-ThingSpeak - An example (it seems that Arduino is used with C). Data is sent using ThingSpeak which we already have an account to. Firebase-ESP8266 - (Same as above - seems very clear) ThingSpeak - We created an acount

mavishak commented 3 years ago

22.01.2021: Setting the baselines for USART1 for communication with ESP8266 MADE A FEW SMALL CHANGES TO USART2 init:

  1. commented out RCC->APB2ENR |= 0x00000001;
  2. changed static USART_2 usart2; //changed from buff need to check that it is still working...

    23.01.2021: Writing code for USART1 - communication with ESP8266 NOTE: Code not tested yet. Questions:

  3. How to know Rx is complete/receive? assumption: "\r\n" or "\r\n\r\n"
  4. When disabling Rx should we disable Rx interrupts as well?
  5. Maybe it will be smarter to call the set functions from the init?
  6. What to do in case of buffer overflow in Receive interrupt?
  7. Is it correct to have USART1_IRQHandler do all that it is doing now? Our idea is that only when \r\n is found and the command is read handler will be set in the queue to avoid overrunning response
mavishak commented 3 years ago

24.01.2021: We haven't succeeded to create a connection with ESP8266. the interrupt is not accessed. (We accessed it by mistake after touching the pins)

What we tried and didn't work:

  1. We tried clearing USART1-SR (TC - transmit complete) by resetting its value
  2. input_floating instead of a pull-up
    1. waiting
  3. Enable RCC for Alternate function for PINs - Highly unlikely... we don't think it should be enabled at all.

    On another subject - The init_usart1() test prints are printed twice even though they are supposed to print once. We are pretty sure that the BRR is set correctly (but it might be worth the review...)

mavishak commented 3 years ago

25.01.2021: We are managing to get input from ESP8266 but not the correct one:

  1. It might not actually be input - maybe the \0 is printed again and again hard to believe- because the input grows each time.
  2. There is probably a problem of a buffer overflow or another programmable problem that is not being taken care of since the computer is 'bling-ing'. bling-s - every time there is a \r\n on screen.
  3. Maybe we are entering the ISR repeatedly because the interrupt flag is not being cleared. WHY ARE WE ENTERING THE ISR SO MANY TIMES WE ONLY WANT TO GET OK??
    1. BRR problem with USART1 - maybe it shouldn't be similar to USART2.
    2. problem with jumper attachments - very likely. The ISR is entered only after connecting CH_PD (EN) to 3.3v powering it, playing, and then reconnecting the USB.
  4. Tx in STM32 is using 5V - should be 3.3V. Use a logic level shifter or voltage divider between it??

After a meeting with our instructor:

mavishak commented 3 years ago

This might be a Break Through

I am not completely sure but it seemed I managed to create a connection between STM32 and ESP8266 using the code from ESP8266-STM32F103. This is my main:

#include <stm32f10x.h>
#include <stm32f10x_rcc.h>
#include <stm32f10x_usart.h>
#include "USART.h"
#include "common.h"
#include "ESP8266WIFI.h"

int main(void)
{

    USART2_Configuration(); // for PC
    USART1_Configuration(); // for ESP2866
    //sysTickInit();

    //delay(10000); //1sec

    while(1){
        //usartSendArrar(USART2, (uint8_t*)"hello_stich\r\n");
        //delay(1000); //1sec
        bool test_passed = esp8266Test();
        if(test_passed){
            usartSendArrar(USART2, (uint8_t*)"Test Passed\r\n");
        }
        else{
            usartSendArrar(USART2, (uint8_t*)"Test Failed\r\n");
        }
        //delay(2000); //2sec

    }
}

One small change: in USART.c _void USART1Configuration() I changed the baud rate to 115200 instead of 9600. And of course, I connected the (EN) CH_PD to 3.3V

Note (27.01.2021):

After printing USART1 content of esp8266RxBuffer to the screen we saw the 'OK\r\n' So unless something is going on in the code that we are not aware of the code does indeed enable communication between STM32 and ESP8266.

We also saw that when printing that similar to our program there are two printouts instead of one.

mavishak commented 3 years ago

IT'S ALIIIIIVE!

28.01.2021: ESP8266 is communicating with STM32 The 2 main things we changed:

  1. We added NVIC_SetPriorityGrouping(7) to init_usart1() function
  2. We allowed Rx and Tx to be enabled all the time

    One strange thing, it seems the ESP8266 Response is AT\r\n\r\nOK\r\n"