Skip to content

Using ledcWriteTone cause I2C memory fail #3555

Closed
@tatarmiki

Description

@tatarmiki

Hardware:

Board: ESP32 DevKitV1
Core Installation version: 1.0.4
IDE name: Arduino IDE 1.8.10
Flash Frequency: 80Mhz
PSRAM enabled: no
Upload Speed: 921600
Computer OS: Windows 10

Description:

I try to make a counting device with a 4 Digit 7-Segment HT16K33 I2C Digital Led Display Module, and a beep sound every second count. My problem is with the ledcWriteTone function. When i use it to generate the beep sound with buzzer, after a certain of time it's aprox 165 min, the I2C communication fail with MEMORY error. If i not use the ledcWriteTone, everething is fine. Every 10 min count the below sketch print the free heap, and the I2C last error state. Anyone can tell me what's wrong with my code?

Sketch:

#include <Wire.h>
#include <Adafruit_LEDBackpack.h>
#include <Adafruit_GFX.h>
#include <SPI.h>

Adafruit_7segment seven_segment_display = Adafruit_7segment();
int counter = 0;
int freq = 2000;
int channel = 0;
int resolution = 8;
int cycle = 0;

void setup() {
	Wire.begin();
	ledcSetup(channel, freq, resolution);
	ledcAttachPin(26, channel);
	Serial.begin(115200);
	seven_segment_display.begin(0x70);
}

void loop() {

	// Print the free heap every minute

	if (counter == 600) {
		counter = 0;
		Serial.printf("Cycle: %d\n", cycle++);
		Serial.printf("FreeHeap/min: %i bytes\n", ESP.getFreeHeap());
		Serial.printf("I2C status = %d - (%s)\n", Wire.lastError(), Wire.getErrorText(Wire.lastError()));
	}

	// create sample for the 7 segment to display

	int seconds = counter % 60;
	int minutes = counter / 60;

	int min_first_digit = minutes / 10;
	int min_second_digit = minutes % 10;

	int sec_first_digit = seconds / 10;
	int sec_second_digit = seconds % 10;

	// write to 7 segment

	seven_segment_display.drawColon(true);
	seven_segment_display.writeDigitNum(0, min_first_digit);
	seven_segment_display.writeDigitNum(1, min_second_digit);
	seven_segment_display.writeDigitNum(3, sec_first_digit);
	seven_segment_display.writeDigitNum(4, sec_second_digit);
	seven_segment_display.writeDisplay();

	// generate beep sound for buzzer

	ledcWriteTone(channel, freq);

	// beep sound length is 50 ms
	//delay(50);

	// stop beep
	ledcWriteTone(channel, 0);

	//delay(950);

	counter++;
}

Debug Messages:

Opening port
Port open
Cycle: 0
FreeHeap/min: 342260 bytes
I2C status = 0 - (OK)
Cycle: 1
FreeHeap/min: 325472 bytes
I2C status = 0 - (OK)
Cycle: 2
FreeHeap/min: 308672 bytes
I2C status = 0 - (OK)
Cycle: 3
FreeHeap/min: 291872 bytes
I2C status = 0 - (OK)
Cycle: 4
FreeHeap/min: 275072 bytes
I2C status = 0 - (OK)
Cycle: 5
FreeHeap/min: 258272 bytes
I2C status = 0 - (OK)
Cycle: 6
FreeHeap/min: 241472 bytes
I2C status = 0 - (OK)
Cycle: 7
FreeHeap/min: 224672 bytes
I2C status = 0 - (OK)
Cycle: 8
FreeHeap/min: 207872 bytes
I2C status = 0 - (OK)
Cycle: 9
FreeHeap/min: 191084 bytes
I2C status = 0 - (OK)
Cycle: 10
FreeHeap/min: 174296 bytes
I2C status = 0 - (OK)
Cycle: 11
FreeHeap/min: 157496 bytes
I2C status = 0 - (OK)
Cycle: 12
FreeHeap/min: 140696 bytes
I2C status = 0 - (OK)
Cycle: 13
FreeHeap/min: 123896 bytes
I2C status = 0 - (OK)
Cycle: 14
FreeHeap/min: 107096 bytes
I2C status = 0 - (OK)
Cycle: 15
FreeHeap/min: 90296 bytes
I2C status = 0 - (OK)
Cycle: 16
FreeHeap/min: 73496 bytes
I2C status = 0 - (OK)
Cycle: 17
FreeHeap/min: 70584 bytes
I2C status = 6 - (MEMORY)
Cycle: 18
FreeHeap/min: 70584 bytes
I2C status = 6 - (MEMORY) 

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions