Esp32c3 errors ledc

Hello,

I get theses traces:

22:04:15.537 -> ESP-ROM:esp32c3-api1-20210207
22:04:15.537 -> Build:Feb  7 2021
22:04:15.537 -> rst:0x1 (POWERON),boot:0xe (SPI_FAST_FLASH_BOOT)
22:04:15.570 -> SPIWP:0xee
22:04:15.570 -> mode:DIO, clock div:1
22:04:15.570 -> load:0x3fcd6100,len:0x420
22:04:15.570 -> load:0x403ce000,len:0x90c
22:04:15.570 -> load:0x403d0000,len:0x236c
22:04:15.570 -> entry 0x403ce000
22:04:15.770 -> setup---begin
22:04:15.770 -> This chip has 1 cores
22:04:21.248 -> E (5769) ledc: ledc_get_duty(501): LEDC is not initialized
22:04:21.414 -> E (5911) ledc: ledc_set_duty(481): LEDC is not initialized
22:04:21.414 -> E (5911) ledc: ledc_update_duty(409): LEDC is not initialized
22:04:21.414 -> E (5911) ledc: ledc_get_duty(501): LEDC is not initialized
22:04:21.547 -> E (6058) ledc: ledc_set_duty(481): LEDC is not initialized
22:04:21.547 -> E (6058) ledc: ledc_update_duty(409): LEDC is not initialized
22:04:21.547 -> E (6058) ledc: ledc_get_duty(501): LEDC is not initialized
22:04:21.679 -> E (6205) ledc: ledc_set_duty(481): LEDC is not initialized
22:04:21.679 -> E (6205) ledc: ledc_update_duty(409): LEDC is not initialized
22:04:21.713 -> E (6205) ledc: ledc_get_duty(501): LEDC is not initialized
22:04:21.846 -> E (6352) ledc: ledc_set_duty(481): LEDC is not initialized
22:04:21.846 -> E (6352) ledc: ledc_update_duty(409): LEDC is not initialized
22:04:21.846 -> E (6352) ledc: ledc_get_duty(501): LEDC is not initialized
22:04:21.912 -> E (6428) ledc: ledc_set_duty(481): LEDC is not initialized
22:04:21.912 -> E (6428) ledc: ledc_update_duty(409): LEDC is not initialized
22:04:21.912 -> E (6428) ledc: ledc_get_duty(501): LEDC is not initialized
22:04:22.144 -> E (6646) ledc: ledc_set_duty(481): LEDC is not initialized
22:04:22.144 -> E (6646) ledc: ledc_update_duty(409): LEDC is not initialized
22:04:22.144 -> E (6646) ledc: ledc_get_duty(501): LEDC is not initialized
22:04:22.410 -> E (6936) ledc: ledc_set_duty(481): LEDC is not initialized
22:04:22.443 -> E (6936) ledc: ledc_update_duty(409): LEDC is not initialized
22:04:22.443 -> E (6936) ledc: ledc_get_duty(501): LEDC is not initialized
22:04:22.576 -> E (7083) ledc: ledc_set_duty(481): LEDC is not initialized
22:04:22.576 -> E (7083) ledc: ledc_update_duty(409): LEDC is not initialized

uint8_t buzzerPin=1;
pinMode(buzzerPin, OUTPUT);
delay(500);
for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) {

    // calculates the duration of each note
    divider = melody[thisNote + 1];
    if (divider > 0) {
      // regular note, just proceed
      noteDuration = (wholenote) / divider;
    } else if (divider < 0) {
      // dotted notes are represented with negative durations!!
      noteDuration = (wholenote) / abs(divider);
      noteDuration *= 1.5; // increases the duration in half for dotted notes
    }

    // we only play the note for 90% of the duration, leaving 10% as a pause
    tone(buzzerPin, melody[thisNote], noteDuration*0.9, BUZZER_CHANNEL);

    // Wait for the specief duration before playing the next note.
    delay(noteDuration);
    
    // stop the waveform generation before the next note.
    noTone(buzzerPin,BUZZER_CHANNEL);
  } 

I don't why, before my buzzer works, now i get theses traces and buzzer not works. I don't change my code.

Have you an idea?

Thank you.

Please post a complete sketch that illustrates the problem rather than just a code snippet

Of the posted code line 2,455 has a hidden character. Delete that line and your code should work, or post the whole code so we don't have to guess. The ESp32's ledc API should have code in setup(), right?

What do you mean by 2,455 ? Zj7sbFb5nc | SourceBin

You might want to consider using a ESP32 tone library instead of an Arduino tone library.

Redstoned/esp32_tone: A library for the ESP32 that adds the Arduino tone()-functions and much more! (github.com)

What I mean is you did NOT post the entire code and code snippets are just plain poo!.

That's strange a ESP32 C3 having only one core. I know the ESP32S was the single core with the FPU. I have many C3's with dual cores.

One likely thing is, if the code worked for some time but now, when revisited it does not work, a library got updated during the down time and the old code is no longer compatible with the new library.

Any library have updated. ESP32c3 are single core.

I found the solution:

 ledcAttachPin(pin, channel);
    ledcSetup(channel, frequency, bits);

I need to use ledcSetup. I don't know before its works without.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.