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

Problem with esp32-wroom in idle board is reloaded. #8374

Closed
1 task done
brightproject opened this issue Jul 1, 2023 · 5 comments
Closed
1 task done

Problem with esp32-wroom in idle board is reloaded. #8374

brightproject opened this issue Jul 1, 2023 · 5 comments

Comments

@brightproject
Copy link

brightproject commented Jul 1, 2023

Board

ESP32-D0WD-V3 (revision 3)

Device Description

Dev board ESP32-WROOM

Hardware Configuration

// ESP32 pins used
#define TFT_CS   33  
#define TFT_DC   15  
#define TFT_RST  32 

#define TFT_WR    4 
#define TFT_RD    2

#define TFT_D0   12 
#define TFT_D1   13 
#define TFT_D2   26
#define TFT_D3   25
#define TFT_D4   17
#define TFT_D5   16
#define TFT_D6   27
#define TFT_D7   14
#define TFT_BL   21
// #define TFT_BL   5

#define BUTTON_A_PIN 39  
#define BUTTON_B_PIN 36  

Version

v2.0.9

IDE Name

Notepad ++ and arduino-cli

Operating System

Windows 10 Pro

Flash frequency

40 Mhz

PSRAM enabled

no

Upload speed

921600

Description

I use a debug board to connect the display, using an 8-bit parallel interface(TFTe_SPI library), I connect two buttons and adjust the backlight at the display using PWM.
When I set TFT_BL like GPIO21, the backlight is adjusted smoothly, my code first “lights” it smoothly, by means of a cycle for, and then after a short delay it reduces the backlight, also in the for cycle.
When I specify the backlight pin GPIO5, then the backlight simply turns on to the maximum and then just turns off without smooth.
At the beginning, I thought that GPIO5 was not designed to work with PWM, but the pinout picture says that it should work fine in PWM mode.
40106876871_ba099961c1_o

What could be the problem?

Sketch

//This is certainly not all the code and not all the functions, just a small excerpt from the code.

#define BLK_PWM_CHANNEL 7  // LEDC_CHANNEL_7	
#define TFT_BL   21
// #define TFT_BL   5	

// Init the back-light LED PWM
ledcSetup(BLK_PWM_CHANNEL, 44100, 8);
ledcAttachPin(TFT_BL, BLK_PWM_CHANNEL);
ledcWrite(BLK_PWM_CHANNEL, 80);

  for (float i = 1.0f; i <= Brightness; i += (float)Brightness / 500.0f)
  {
    Backlight(i);
    delay (3);
  }

  delay (150);
  for (float i = 1.0f; i <= Brightness; i += (float)Brightness / 500.0f)
  {
    Backlight(Brightness - i);
    delay (3);
  }

Debug Message

No messages

Other Steps to Reproduce

Nope

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@brightproject brightproject added the Status: Awaiting triage Issue is waiting for triage label Jul 1, 2023
@brightproject
Copy link
Author

brightproject commented Jul 3, 2023

@espressif I will slightly change the description of the problem, since the module is being rebooted.
Pin 5 actually works as PWM and adjusts the backlight smoothly.
The point is the constant reloading of the module, when loading the sketch.

#include <TFT_eSPI.h>

TFT_eSPI tft = TFT_eSPI();// create an object to work with the screen
TFT_eSprite sprite = TFT_eSprite(&tft); // create an object to work with the buffer

const int ledPin = 1; // LED buildin pin number
const int LED_PIN = 5; // pin number on which the display backlight is connected
const int LED_CHANNEL = 7; // PWM channel number for LED control
const int FREQ = 1000; // PWM frequency in Hz

const int BUTTON_1_PIN = 36; // botton DN
const int BUTTON_2_PIN = 39; // buttom UP

// rectangle where text is displayed
const int RECT_X = (360 / 2) - 75  ; 
const int RECT_Y = (240 / 2) - 30; 
const int RECT_WIDTH = 100; 
const int RECT_HEIGHT = 60; //

int brightness = 0; // initial LED brightness
int delayTime = map(brightness, 0, 255, 1000, 100); // calculation of delay time depending on brightness
unsigned long previousMillis = 0; // variable to store the previous millisecond value

void setup() {
  // PWM channel initialization
  ledcSetup(LED_CHANNEL, FREQ, 8); 
  // binding a PWM channel to a pin
  ledcAttachPin(LED_PIN, LED_CHANNEL);

  pinMode(BUTTON_1_PIN, INPUT);
  pinMode(BUTTON_2_PIN, INPUT);
  pinMode(ledPin, OUTPUT); 
  
  // screen initialization
  tft.init();
  tft.setRotation(1); // screen rotation 90 degrees
  tft.fillScreen(TFT_BLACK); // screen cleaning
  tft.setTextSize(3); // text size 3
  tft.setTextColor(TFT_WHITE); 

  // creating a sprite to work with the buffer
  sprite.setColorDepth(8); 
  sprite.createSprite(RECT_WIDTH-2, RECT_HEIGHT-2); // creating a sprite with the dimensions of a rectangle
  sprite.fillSprite(TFT_BLACK); // sprite cleaning
  sprite.setTextSize(5); 
  sprite.setTextColor(TFT_WHITE);
}


void loop() {
  // decrease in brightness when pressing the first button
  if (digitalRead(BUTTON_1_PIN) == LOW) {
    brightness = max(brightness - 10, 0); 
    ledcWrite(LED_CHANNEL, brightness);
    delayTime = map(brightness, 0, 255, 1000, 100); // recalculate the delay time depending on the brightness
    delay(50); 
  }

  // increase brightness by pressing the second button
  if (digitalRead(BUTTON_2_PIN) == LOW) {
    brightness = min(brightness + 10, 255); 
    ledcWrite(LED_CHANNEL, brightness);
    delayTime = map(brightness, 0, 255, 1000, 100); 
    delay(50); 
  }

  // displaying the current brightness on the screen through a sprite
  sprite.fillRect(0, 0, sprite.width(), sprite.height(), TFT_BLACK); 
  tft.setTextSize(5); 
  tft.setCursor(0, 0); // placing the cursor in the upper left corner of the screen
  tft.println("Brightness"); 
  sprite.setCursor(5, 10); // set the cursor to the top of the sprite
  sprite.println(brightness); 
  sprite.pushSprite(RECT_X+1, RECT_Y+1); 

  unsigned long currentMillis = millis(); // current value of milliseconds

  if (currentMillis - previousMillis >= delayTime) { // if enough time has passed
    previousMillis = currentMillis; // save the current value of milliseconds
    digitalWrite(ledPin, !digitalRead(ledPin)); // invert the state of the LED
  }
  
}

What is the strangeness of the following, if I use 2 buttons to give LOW signals to pins 39 and 36, then the code works, the display shows an inscription with brightness numbers, the PWM signal on pin 5 changes, the LED built into the board (on pin 1) also changes the glow periods, depending on the brightness value 0-255.
But as soon as I stop pressing the buttons, after 4-5 seconds the module will reboot, with the output of the following information in the com port.

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1184
load:0x40078000,len:13220
ho 0 tail 12 room 4
load:0x40080400,len:3028
entry 0x400805e4

My board got a little warm, and I decided to replace the AMS3.3 converter
ams1117-3v-2
Soldered it on the board, but nothing has changed.
Then I powered the board, directly, from a good power source - 3.3. volt.
photo1688388238 (1)
But the reboots also continued.
With other sketches(examples from (TFTe_SPI folder), the board does not reboot like this.
What could be the reason?
Strange "solution" in here doesn't help.
The idle board is reloaded.
Yes, and the reboot itself is strange, the code, in theory, should set a low PWM level on leg 5 at the start of the MK, but after such a "strange" reboot, the display remains lit, i.e. on leg 5, the PWM level is 255, although it is 0 in the code.
The Internet indicates that with an error (rst:0xc (SW_CPU_RESET)), the problem is usually a bad USB cable or poor-quality soldering of the connector.
photo1688390303
But I, as I wrote above, connected a good power supply 3.3. volts - directly to the pins of the board.
P.S. Also, I will add more information, maybe it will be important.
I use an arduino cli.
And when I open the port monitor with the command
arduino-cli monitor -p COM9 -c baudrate=115200
Then the microcontroller reboots.
But test is port another

rst:0x1 (POWERON_RESET),boot:0x12 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1184
load:0x40078000,len:13220
ho 0 tail 12 room 4
load:0x40080400,len:3028
entry 0x400805e4

Скриншот 03-07-2023 16 49 00
In principle, it doesn’t matter, you can also open the port monitor, as you are used to, from the arduino IDE menu.
Скриншот 03-07-2023 16 58 51
I just don't understand, is this reboot when starting the port monitor a standard feature, or is it a bug?

@brightproject brightproject changed the title Problem with PWM on GPIO5 Problem with esp32-wroom in idle board is reloaded. Jul 3, 2023
@brightproject
Copy link
Author

brightproject commented Jul 3, 2023

Continuing the search for the reasons for the reboot, I saw in the drop-down menu of the arduino IDE the items tangent to the processor cores - core 0 and core 1.
More precisely, the item is called - Arduino Runs On:
I had core 0 selected, and the code compiled without errors, loading occurred without errors and exceptions.
Arduino Runs On: in FQBN - Fully Qualified Board Name format called - LoopCore
esp32:esp32:esp32:JTAGAdapter=default,PSRAM=disabled,PartitionScheme=default,CPUFreq=240,FlashMode=dio,FlashFreq=80,FlashSize=4M,UploadSpeed=921600,LoopCore=0,EventsCore=1,DebugLevel=none
But when idle - the microcontroller rebooted - about which I wrote many many lines of text above.
When I chose - core 1, and also loaded the code into the microcontroller without any problems - a miracle happened, the microcontroller stopped rebooting.
Скриншот 03-07-2023 18 36 41
What is this joke or not?
Also, I have not yet fully understood why, when I chose the Quad I/O flash mode, I still write Dual I/O to the console?
Скриншот 03-07-2023 18 37 30

For information - for those who may not understand, Flash Frequency 40/80 MHz is devider on 2 and devider on 1, respectively.

mode:DIO, clock div:1
mode:DIO, clock div:2

From the article, I realized that by default the arduino IDE is configured to use core 1, apparently I reconfigured something and only on one single code example - I received an error in the form of a module restart in idle mode.
Thus, as far as I understand, ESP32 works without additional settings, only in single core mode, and core 1 functions normally.
If core 0 is selected, the microcontroller will spontaneously reboot when not performing tasks.
The choice of core 1 or core 0 in paragraph Events Run On: does not affect the microcontroller in any way - it has been verified empirically.
Problem with power not confirmed.

@sebi-rf
Copy link

sebi-rf commented Sep 13, 2023

II had the same problem! At mine "brown reset" did it. So, I disabled brownout detector in setup function:

WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);
Serial.println("Brownout detector disabled");

Firstly, include library:

#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"

@brightproject
Copy link
Author

II had the same problem! At mine "brown reset" did it. So, I disabled brownout detector in setup function:

WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); Serial.println("Brownout detector disabled");

Firstly, include library:

#include "soc/soc.h" #include "soc/rtc_cntl_reg.h"

Thank you for your concern about my problem.
I work in the Arduino ecosystem, I don’t use the ESP-IDF core explicitly.
I catch the Brown detector for various reasons, the pins are not assigned correctly, or there are other conflicts.
Esp32 is a very unique microcontroller, but it makes up for it with its power.

@Parsaabasi
Copy link

Hello,

Due to the overwhelming volume of issues currently being addressed, we have decided to close the previously received tickets. If you still require assistance or if the issue persists, please don't hesitate to reopen the ticket.

Thanks.

@Parsaabasi Parsaabasi removed the Status: Awaiting triage Issue is waiting for triage label Jan 16, 2025
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

3 participants