Implementation of Interrupt Allocation

usulrasolas
Posts: 26
Joined: Tue Jun 09, 2020 5:27 pm

Implementation of Interrupt Allocation

Postby usulrasolas » Mon Jul 06, 2020 11:12 pm

Hello! I'm looking to use the IRQ line for an ADC to trigger the next read in a scan mode and recently had my programming help quit and I am unsure what I should do from where I am.
I have the adc working well in single shot and continuous mode and behaving within the operating parameters of the datasheet.

They were attempting to use the following code to config the interrupt
  1. void config_interrupt(){
  2. gpio_config_t io_conf;
  3. io_conf.itr_type = GPIO_PIN_INTR_NEGEDGE;
  4. io_conf.pin_bit_mask = GPIO_INPUT_PIN_SEL;
  5. io.conf.mode = GPIO_MODE_INPUT;
  6. gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
  7.  
  8. }
and the following code to attempt to wait for read:
[Codebox]
void start_scan(){
fast_command(FAST_ADC_START);
// vTalkDelay(50 / portTICK_PERIOD_MS); // delay then read works
gpio_isr_handler_add(GPIO_IRQ, gpio_isr_handler, (void*) GPIO_IRQ);
read_from_register(REG_ADCDATA,4);
}[/Codebox]

this results in crash of the esp32s2 I am using. I am trying to solve the issue myself but part of what appears to be going on is that there is https://docs.espressif.com/projects/esp ... alloc.html and I am unsure of what parts to use for this as others. Everything is working very well in single shot and continuous mode but scan mode needs the irq that I haven't have the knowledge of how to implement.

any advice on how to setup this interrupt so that when the irq goes low again, it will trigger the read?

User avatar
WardMas
Posts: 72
Joined: Fri Jun 19, 2020 9:09 am

Re: Implementation of Interrupt Allocation

Postby WardMas » Tue Jul 07, 2020 5:12 am

hi usulrasolas,
First of all it is always good to do full configuraion of GPIO interrupt before addong the GPI ISR handler in your config you are missing pull_down_en and pull_up_en. To do the configuration you must use gpio_config() to pass the address of io_conf then you install the ISR by selecting its priority ex. gpio_install_isr_service(ESP_INTR_FLAG_LEVEL2); and then you add the handler gpio_isr_handler_add(). The handler is added only once. Your interrupt routine should have (void *para) which will contain the pin responsible for the interrupt. if that doesn't work try to add the type IRAM_ATTR to your routine to make the interrupt happens inside the instruction RAM (very fast) so you interrupt routine will be something like (void IRAM_ATTR GPIO_ISR(void *para))
let me know if that was useful :).
You can always visit my YouTube channel for embedded systems related tutorials
https://youtube.com/user/wardzx1

usulrasolas
Posts: 26
Joined: Tue Jun 09, 2020 5:27 pm

Re: Implementation of Interrupt Allocation

Postby usulrasolas » Tue Jul 07, 2020 2:43 pm

New Code:
  1.  
  2. static void IRAM_ATTR gpio_isr_handler(void* arg)
  3. {
  4.     read_from_register(REG_ADCDATA,4);
  5.     printf("ADC Interrupt Reading %d,%d,%d,%d,%d\n",recvbuf[0],recvbuf[1],recvbuf[2],recvbuf[3],recvbuf[4]);
  6. }
  7.  
  8. void config_interrupt(){
  9.    
  10.     gpio_config_t io_conf;
  11.     io_conf.intr_type = GPIO_PIN_INTR_ANYEDGE;
  12.     io_conf.pin_bit_mask = GPIO_INPUT_PIN_SEL;
  13.     io_conf.mode = GPIO_MODE_INPUT;
  14.     io_conf.pull_down_en = 0;
  15.     io_conf.pull_up_en = 0;
  16.     gpio_config(&io_conf);
  17.     gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
  18.  
  19. }
  20.  
I am unsure if this is what you mean by using a para?

but then I "activate" the interrupt process by

gpio_isr_handler_add(GPIO_IRQ, gpio_isr_handler, (void*) GPIO_IRQ);

at the end of my otherwise functioning begin scan read function?
I am going to test the changes and see what I learn.

usulrasolas
Posts: 26
Joined: Tue Jun 09, 2020 5:27 pm

Re: Implementation of Interrupt Allocation

Postby usulrasolas » Tue Jul 07, 2020 2:53 pm

EDIT: Forgot to mention I'm on IDF/master programming for esp32s2

Here is a copy of the crash, it's just a panic from cpu timeout on irq… the delay between it starting conversion and irq going low to say ready is only about 50ms.

Code: Select all


…
Config IRQ done 6
Reply 23
I (353) gpio: GPIO[13]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:3
FASTCOMMAND: 112
Config 3 done 48
Reply 23
FASTCOMMAND: 104
Guru Meditation Error: Core  0 panic'ed (Interrupt wdt timeout on CPU0).

Core  0 register dump:
PC      : 0x40029ba0  PS      : 0x00060a34  A0      : 0x80028f85  A1      : 0x3ffbea50
0x40029ba0: vListInsert at C:/Users/mcp3461/Desktop/esp-idf/components/freertos/list.c:189 (discriminator 1)

A2      : 0x3ffc491c  A3      : 0x3ffc3aa4  A4      : 0x00060a21  A5      : 0x3ffc48f4
A6      : 0x3ffc0988  A7      : 0x3ffc0990  A8      : 0x3ffc3aa4  A9      : 0x3ffc3aa4
A10     : 0x00000019  A11     : 0x00000019  A12     : 0x0000000c  A13     : 0x400284d0
0x400284d0: _frxt_int_enter at C:/Users/mcp3461/Desktop/esp-idf/components/freertos/xtensa/portasm.S:119

A14     : 0x00000000  A15     : 0x00000001  SAR     : 0x00000020  EXCCAUSE: 0x00000005
EXCVADDR: 0x00000000  LBEG    : 0x0000000c  LEND    : 0x400284d0  LCOUNT  : 0x40024f74
0x400284d0: _frxt_int_enter at C:/Users/mcp3461/Desktop/esp-idf/components/freertos/xtensa/portasm.S:119

0x40024f74: xt_highint4 at C:/Users/mcp3461/Desktop/esp-idf/components/esp_system/port/esp32s2/dport_panic_highint_hdl.S:58

Core  0 was running in ISR context:
EPC1    : 0x40096227  EPC2    : 0x00000000  EPC3    : 0x00000000  EPC4    : 0x40029ba0
0x40096227: uart_hal_write_txfifo at C:/Users/mcp3461/Desktop/esp-idf/components/soc/src/hal/uart_hal_iram.c:35

0x40029ba0: vListInsert at C:/Users/mcp3461/Desktop/esp-idf/components/freertos/list.c:189 (discriminator 1)


Backtrace:0x40029b9d:0x3ffbea50 0x40028f82:0x3ffbea70 0x4002a37c:0x3ffbea90 0x40086f59:0x3ffbead0 0x40086f88:0x3ffbeb10 0x40083379:0x3ffbeb40 0x40026189:0x3ffbeb60 0x40026bf9:0x3ffbeb80 0x40025d9a:0x3ffbeba0 0x40095517:0x3ffc3a00 0x40082c7b:0x3ffc3a20 0x400289fe:0x3ffc3a40 0x4002834d:0x3ffc3a60
0x40029b9d: vListInsert at C:/Users/mcp3461/Desktop/esp-idf/components/freertos/list.c:189

0x40028f82: vTaskPlaceOnEventList at C:/Users/mcp3461/Desktop/esp-idf/components/freertos/tasks.c:2904 (discriminator 2)

0x4002a37c: xQueueGenericReceive at C:/Users/mcp3461/Desktop/esp-idf/components/freertos/queue.c:1595

0x40086f59: spi_device_get_trans_result at C:/Users/mcp3461/Desktop/esp-idf/components/driver/spi_master.c:809 (discriminator 2)

0x40086f88: spi_device_transmit at C:/Users/mcp3461/Desktop/esp-idf/components/driver/spi_master.c:832

0x40083379: read_from_register at c:\users\mcp3461\desktop\esp-idf\mcp\build/../main/mcp3x6x_spi.h:203

0x40026189: gpio_isr_handler at c:\users\mcp3461\desktop\esp-idf\mcp\build/../main/mcp3x6x_spi.h:1145

0x40026bf9: gpio_isr_loop at C:/Users/mcp3461/Desktop/esp-idf/components/driver/gpio.c:405
 (inlined by) gpio_intr_service at C:/Users/mcp3461/Desktop/esp-idf/components/driver/gpio.c:422

0x40025d9a: _xt_lowint1 at C:/Users/mcp3461/Desktop/esp-idf/components/freertos/xtensa/xtensa_vectors.S:1105

0x40095517: esp_pm_impl_waiti at C:/Users/mcp3461/Desktop/esp-idf/components/esp32s2/pm_esp32s2.c:479

0x40082c7b: esp_vApplicationIdleHook at C:/Users/mcp3461/Desktop/esp-idf/components/esp_common/src/freertos_hooks.c:63

0x400289fe: prvIdleTask at C:/Users/mcp3461/Desktop/esp-idf/components/freertos/tasks.c:3385 (discriminator 1)

0x4002834d: vPortTaskWrapper at C:/Users/mcp3461/Desktop/esp-idf/components/freertos/xtensa/port.c:143



ELF file SHA256: 8256737c2612f518

Rebooting...
ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x3 (RTC_SW_SYS_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
… 

usulrasolas
Posts: 26
Joined: Tue Jun 09, 2020 5:27 pm

Re: Implementation of Interrupt Allocation

Postby usulrasolas » Tue Jul 07, 2020 5:32 pm

I can manually access the first value of scan mode with a delay, but I am curious about how to get irq to trigger, I can make a system that uses fixed delay count for known number of scan, but irq trigger would be flexible based on time values.
I have tried various edge flags, but nothing triggers and I can achieve other reads even but eventually it still going into panic cause too long of a interrupt period after the read window already elapsed

User avatar
WardMas
Posts: 72
Joined: Fri Jun 19, 2020 9:09 am

Re: Implementation of Interrupt Allocation

Postby WardMas » Wed Jul 08, 2020 9:18 am

Hi,
Could you try io_conf.pin_bit_mask = 1 << GPIO_INPUT_PIN_SEL; in the interrupt config function
You can always visit my YouTube channel for embedded systems related tutorials
https://youtube.com/user/wardzx1

usulrasolas
Posts: 26
Joined: Tue Jun 09, 2020 5:27 pm

Re: Implementation of Interrupt Allocation

Postby usulrasolas » Wed Jul 08, 2020 10:24 am

Thanks! It fixes the crash but I can't seem to get it to trigger from there... :lol:

Currently I have a delay read loop that works, but the code for that should run doesn't get triggered?

I call the adding of the handler in the following code:

void start_scan(){

fast_command(FAST_ADC_START);
vTaskDelay( 35 / portTICK_PERIOD_MS); //50ms for delay read 35ms for irq trigger
gpio_irs_handler_add(GPIO_IRQ, gpio_irs_handler, (void*) GPIO_IRQ);

}

am I missing some further commands to make it work? I am using the example as a guide

User avatar
WardMas
Posts: 72
Joined: Fri Jun 19, 2020 9:09 am

Re: Implementation of Interrupt Allocation

Postby WardMas » Wed Jul 08, 2020 10:47 am

Hi,
The first this I can spot is that gpio_irs_handler_add(GPIO_IRQ, gpio_irs_handler, (void*) GPIO_IRQ); must be called inside the interrupt configuration function and it is called only once as long as you don't delete your ISR handler.
Also I recommend you to used freeRTOS and execute the scan function once interrupt is triggered using semaphore. It may seem complicated if you are coming from STM32 like me but your program will be much more stable and you will have control over 2 cores.
You can always visit my YouTube channel for embedded systems related tutorials
https://youtube.com/user/wardzx1

usulrasolas
Posts: 26
Joined: Tue Jun 09, 2020 5:27 pm

Re: Implementation of Interrupt Allocation

Postby usulrasolas » Wed Jul 08, 2020 11:08 am

I have made sure nothing loops to call it any addtional times. I have also moved the handler add to the config_interrupt function. Still no trigger yet

here's a picture of my timed delay read, you see how irq goes low when it is ready for read?
newnewnew.jpg
newnewnew.jpg (155.46 KiB) Viewed 7798 times
the esp32-s2 is single core, would semaphore help with the issue of not triggering?

Thanks for all this advice and help!

User avatar
WardMas
Posts: 72
Joined: Fri Jun 19, 2020 9:09 am

Re: Implementation of Interrupt Allocation

Postby WardMas » Wed Jul 08, 2020 11:48 am

Hi,
semaphore can be used to force a FreeRTOS task to run immediately once an event takes place.
For the time being why don't you test the GPIO interrupt with a push button first ?
You can always visit my YouTube channel for embedded systems related tutorials
https://youtube.com/user/wardzx1

Who is online

Users browsing this forum: No registered users and 140 guests