logo elektroda
logo elektroda
X
logo elektroda

[Solved] [RTOS][esp-idf] ESP32 interrupts and shuffles some basic questions

NIXIE_123 3162 56
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #31 19550902
    khoam
    Level 42  
    What is the variable type event_buttons.event ?
  • ADVERTISEMENT
  • #32 19550949
    NIXIE_123
    Level 34  
    [RTOS][esp-idf] ESP32 interrupts and shuffles some basic questions .
    this is the library
    https://github.com/craftmetrics/esp32-button

    I have repeated the definitions
    #define BUTTON_DOWN (1)
    #define BUTTON_UP (2)
    #define BUTTON_HELD (3)


    in button.c and main.c
    eclipse did not throw a multiple definition error just the underscores disappeared.
    The program uploaded, it restarts again.
    I had a new eclipse uploaded when I upgraded, and it's the one with these actions on it. I think I will try it with what I had before.

    Project settings. There seems to be something missing here
    [RTOS][esp-idf] ESP32 interrupts and shuffles some basic questions .

    Added after 18 [minutes]:

    Everything installed from scratch including c:/esp-idf and still the same (on new eclipse)
  • #33 19551324
    khoam
    Level 42  
    And if you had Visual Studio Code installed with PlatformIO you would have saved so much time :) It took me about 30 seconds to import the code you sent me into the PIO environment.
  • #34 19551683
    NIXIE_123
    Level 34  
    I went back to esp-idf v4.2
    Eclipse continued to underline but after uploading the program works as before.

    I went back to eclipse 2020-12
    It no longer underlines anything and everything works as it should.
  • #35 19551748
    khoam
    Level 42  
    I really stop to understand this. I didn't expect that the IDE version could affect the performance of the code in ESP :) .

    NIXIE_123 wrote:
    Nothing is highlighted anymore and everything works as expected.

    But in which version of the callback function?
  • #36 19551762
    NIXIE_123
    Level 34  
    khoam wrote:
    IDE can affect the operation of the code in ESP
    .
    Well, not exactly.
    On the new eclipse it underlined but it depended on the idf version whether it worked or not.
    Because on the new eclipse but old idf it underlined but the programme worked.

    khoam wrote:
    But in which version of the callback function?
    .
    Everything works I mean I am back to square one. That is, a working clock without wifi and with interrupts the old way. I am now going to play around with converting just the callback.

    Added after 4 [hours] 38 [minutes]: .

    Just to be sure, I still tried on the old eclipse (2020-12) and idf v4.3
    It does not highlight errors the program loads and does not work. Something messed up in the new idf version
    [RTOS][esp-idf] ESP32 interrupts and shuffles some basic questions .
    [RTOS][esp-idf] ESP32 interrupts and shuffles some basic questions
  • #37 19552245
    khoam
    Level 42  
    NIXIE_123 wrote:
    Something was messed up in the new idf version
    .
    :) Of course there are changes between versions 4.3 and 4.2. You can track them here: Link .
    To start with, however, I would resolve an obvious bug in the programme:

    [RTOS][esp-idf] ESP32 interrupts and shuffles some basic questions .
  • #38 19552251
    NIXIE_123
    Level 34  
    Code: C / C++
    Log in, to see the code
    .

    Compiles the same project all the time. 4.2 works 4.3 does not work

    EDIT:
    Problem solved. Need to add
    conf.clk_flags = 0;
    .

    Now I can get on with the actual problem i.e. interrupts. I will let you know when I have sculpted something.

    I am running on esp-idf v4.3 and eclipse 2020-12
  • ADVERTISEMENT
  • #39 19552286
    khoam
    Level 42  
    Try adding an additional field initialization for the variable conf :
    Code: C / C++
    Log in, to see the code
    .

    EDIT: Well, you've already managed :) .
  • ADVERTISEMENT
  • #40 19556736
    NIXIE_123
    Level 34  
    In order to assign a function handler to a core, it must be initialised in the shuffle assigned to that core.
    So I want to handle an interrupt on core 1.
    I create a task assigned to it and in it I initiate an interrupt from the timer
    The interrupt does not start, the rest is running
    It does not even start on core 0
    I moved the gpio initialisation to the task, no change

    Code: C / C++
    Log in, to see the code
    .
  • ADVERTISEMENT
  • #41 19556976
    khoam
    Level 42  
    With me this code works, with the exception that I increased the priority of the task to 4, because with 1 it can wait a long time for its turn to be called.
    I tested with an "empty" calkback function interrupt_from_timer_mux().
    I did not make any other changes to the code.
    The vTaskDelay in the task() function can be very long - basically the idea is to make this task execute once.
  • #42 19558056
    NIXIE_123
    Level 34  
    It worked for me too, through these combinations I removed the IRAM_ATTR before the function name
    It didn't do anything so I tried it:
    khoam wrote:
    directly manipulate GPIO W1TS registers once GPIO W1TC8923e5bb6 .

    And it works! I have no panic. I've made myself 4 "map" arrays in RAM and in the interrupt just writes values from them to w1ts
    I removed the set_catode() function entirely

    It normally connects to the wifi even at 35µs. There is only one side effect
    Solution as above without wifi:
    -everything works I have no comments
    Solution as above with wifi:
    -no adc works when code from wifi starts. Clock works normally just doesn't dim (well, because there is no adc)

    So I paste in the code the diagnostics(last line):
    Code: C / C++
    Log in, to see the code
    .
    And the processor has a panic exactly when the last line is called. I remove it it works without a working adc
    [RTOS][esp-idf] ESP32 interrupts and shuffles some basic questions

    Initialisation of adc:
    Code: C / C++
    Log in, to see the code
    .

    https://www.esp32.com/viewtopic.php?t=9972

    Solution:
    you need to disable wifi by
    Code: C / C++
    Log in, to see the code
    .

    Only RMT(led_strip) does not work, not sure why
    Oh, it's working now. Apparently it was still trying to connect in the background and delayed calling esp_wifi_stop()
  • #43 19558136
    khoam
    Level 42  
    Do you really need a 10-channel ADC? An ADC1 to measure illuminance is not enough?
  • #44 19558199
    NIXIE_123
    Level 34  
    I use one channel but it is connected to gpio14
    [RTOS][esp-idf] ESP32 interrupts and shuffles some basic questions
  • #45 19558242
    khoam
    Level 42  
    For the ADC it is in my opinion better to "sacrifice" any of the "Input only" GPIOs, i.e. 34-39.
  • #46 19558263
    NIXIE_123
    Level 34  
    Of course, the problem here is that I can't change the pcb. Adc won't work for a few seconds every half hour. Don't bother
  • #47 19560875
    NIXIE_123
    Level 34  
    I download the time elegantly via sntp example.
    However, it only uses seconds timestamp and in ntp there are still microseconds.
    As a result, I have an accuracy of 1 second.
    I would also like to download microseconds, i.e. the whole timeval structure (seconds + microseconds)
  • Helpful post
    #48 19560898
    khoam
    Level 42  
    I don't know which example you're referring to, but in this one it's shown that you can use all the fields of the timeval structure: Link
  • #49 19561136
    NIXIE_123
    Level 34  
    However, the example uses microseconds and the internal time is accurate
    such a code:
    Code: C / C++
    Log in, to see the code
    and we have the exact time to the second in ds3231 : )
  • #50 19563512
    khoam
    Level 42  
    There is another and simpler method of calling a function on a given core: esp_ipc_call () or esp_ipc_call_blocking ().
    Link .
  • #51 19566175
    NIXIE_123
    Level 34  
    There is one last thing left to do. Setting a few variables from the browser.
    What I want to achieve:
    I plug in the device without holding the button - in the old way, my code executes

    I power on the device while holding the button - my code does not execute.
    The Esp32 is in AP mode. I connect to its wifi by typing 192.168.4.1 into the browser. I see a simple page where I can enter ssid password and 2 variables. All this is written into non-volatile memory

    There is already a topic about this Link but those libraries are on arduino :| .
    There is also Link but you can only set what network it should connect to and it supervises that connection and I'm not interested in that. I just want a simple entry of 4 variables into memory and that's all

    How do I achieve this? There are some libraries or maybe do the AP mode server and nvs support myself just why break down an open door. Having learnt from experience that esp can be capricious and requires tricks I prefer something ready made rather than sitting on a simple thing for half a year

    Smart config is also out
  • #52 19566232
    khoam
    Level 42  
    Since you have such sublime expectations, use BLE to configure WiFi :) .
    Link .
    There are even ready-made apps for Android and iOS.
  • #53 19571581
    Nagus
    Level 27  
    On the ESP32, the ADC2 is used by the WiFi module. So, you either use WiFi or you use ADC2. Never both at the same time. The documentation states. ADC1 is always available.
    The minimum HW timer interrupt is 50us, but this gyrates the CPU a lot. You could try using the rmt module i.e., in this case, let the 0 and 1 sequence go hard. This will definitely put less load on the CPU.
    Hardware timer interrupts should be in RAM. And it usually quickly turns out that some function called in an interrupt does not have a RAM version.
  • #54 19571752
    NIXIE_123
    Level 34  
    I already have everything running even on 35us.
    I am now doing AP + http server and html page with settings.
    I already have the page and by pressing send in the browser I can see the input data in the console.
    Now I just split them up save them to nvs and I have what I want.
  • #55 19571973
    khoam
    Level 42  
    NIXIE_123 wrote:
    I already have everything running even on 35us.
    .
    And how long does it take to execute the ISR callback?
  • #56 19576769
    NIXIE_123
    Level 34  
    khoam wrote:
    And how long does it take to execute an ISR callback?
    .

    I repeated the test from post #9 the result is 4-5µs

    I did my own way from scratch and got what I wanted I am satisfied
    [RTOS][esp-idf] ESP32 interrupts and shuffles some basic questions

Topic summary

The discussion revolves around the use of interrupts in the ESP32 with the ESP-IDF RTOS. Key points include best practices for handling interrupts, such as using them to wake tasks rather than performing extensive operations within ISRs. The participants explore methods for waking tasks from interrupts, with queues being a recommended approach. Concerns about the system tick rate limiting task execution frequency to 1ms are addressed, along with issues related to WiFi interference when using timer interrupts. The conversation also touches on the importance of managing execution time within ISRs to avoid conflicts with other processes, particularly WiFi operations. Solutions include using direct GPIO manipulation for efficiency and the potential of using the RMT module to reduce CPU load. The discussion concludes with successful implementations of timer interrupts and HTTP server setups for configuration via a web interface.
Summary generated by the language model.
ADVERTISEMENT