Implementation of Interrupt Allocation

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

Re: Implementation of Interrupt Allocation

Postby usulrasolas » Wed Jul 08, 2020 2:15 pm

I will look into how to implement semaphore for this to see if it helps, both switch and manually jumping the wire high/low doesn't trigger.
the example gpio irq code does run, but not my implementation of the interrupt

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

Re: Implementation of Interrupt Allocation

Postby usulrasolas » Fri Jul 10, 2020 12:45 am

I shouldn't HAVE to make a semaphore or do task management to trigger the irq? I haven't had any progress and myself and another programmer are really wracking our brains over it....
We totally get the example program to run but not be able to trigger it while the spi is engaged in our program.
I wonder if the functions of esp_intr_alloc.h are more suited for function when spi is in operation?
does spi controlling gpio stop me from accurately reading the pin?
I have more answers than questions still...

ESP_Sprite
Posts: 9020
Joined: Thu Nov 26, 2015 4:08 am

Re: Implementation of Interrupt Allocation

Postby ESP_Sprite » Fri Jul 10, 2020 7:38 am

What is your current code now? I kind-of lost track during the thread...

In general, the idea of a semaphore is to only trigger the semaphore during the IRQ (as you're not allowed to do much more, as blocking functions like printf() won't work in an interrupt context) and then have a task waiting on that semaphore to do whatever else is needed when the interrupt triggers.

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

Re: Implementation of Interrupt Allocation

Postby usulrasolas » Fri Jul 10, 2020 2:20 pm

I currently don't have a semaphore in place, as it didn't seem to advance the code ever as the interrupt never triggered...

Currently there hasn't been any real functional progress on this, let me show all relevant code blocks here:
there's commented code that I've been playing with but no variations work for interrupt, the fixed read cycle with the delay does work however when enabled. I have confirmed with scope and signal analyzer that irq behaves as expected.
  1.  static void IRAM_ATTR gpio_isr_handler(void* arg)
  2. {
  3.     //read_adc_wchid();
  4.     printf("ADC Interrupt Reading %d,%d,%d,%d,%d\n",recvbuf[0],recvbuf[1],recvbuf[2],recvbuf[3],recvbuf[4]);
  5. }
  6.  
  7. void config_interrupt(){
  8.  
  9.     gpio_config_t io_conf;
  10.     io_conf.intr_type = GPIO_INTR_NEGEDGE;
  11.     io_conf.pin_bit_mask = 1<<GPIO_INPUT_PIN_SEL;
  12.     io_conf.mode = GPIO_MODE_INPUT;
  13.     io_conf.pull_down_en = 0;
  14.     io_conf.pull_up_en = 0;
  15.     gpio_config(&io_conf);
  16.     gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
  17.     gpio_isr_handler_add(GPIO_IRQ, gpio_isr_handler, (void*) GPIO_IRQ);
  18.  
  19. }
  20.  
  21. void start_scan(){
  22.  
  23.     fast_command(FAST_ADC_START);
  24.     vTaskDelay(50 / portTICK_PERIOD_MS); //read first value
  25. //begin read loop
  26.     read_adc_wchid();
  27.     //int l;
  28.    // for( l = 0; l < 14; l = l + 1){
  29.    //vTaskDelay(40 / portTICK_PERIOD_MS); //read next value
  30.     //read_adc_wchid();
  31.    // }
  32. }
  33.  
  34. void app_main(void)
  35. {
  36.  
  37.     init_adc(EXT_CLK);
  38.     enter_scan_mode();
  39.     start_scan();
  40.     config_interrupt();
  41.     while(1) {
  42.         start_scan();
  43.         vTaskDelay(1000 / portTICK_PERIOD_MS);
  44.         printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",adc_results[0],adc_results[1],adc_results[2],adc_results[3],adc_results[4],adc_results[5],adc_results[6],adc_results[7],adc_results[8],adc_results[9],adc_results[10],adc_results[11],adc_results[12],adc_results[13],adc_results[14],adc_results[15]);
  45.     }
  46.  
  47. }

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

Re: Implementation of Interrupt Allocation

Postby usulrasolas » Fri Jul 10, 2020 8:05 pm

I can see I need to move tje printf function, but should I also include the code for the read_adc_wchid?

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

Re: Implementation of Interrupt Allocation

Postby usulrasolas » Fri Jul 10, 2020 8:34 pm

I found that I had been seeing gpio 14 not 13 on the gpio reply on the terminal so I fixed it and now code is
(with added sections)
  1. #define GPIO_IRQ 13
  2. #define ESP_INTR_FLAG_DEFAULT 0
  3. #define GPIO_INPUT_PIN_SEL  GPIO_IRQ
  4.  
  5. void read_from_register(char register_id,unsigned int byte_count){
  6.  
  7.     register_id <<= 2;
  8.     sendbuf[0] = register_id | STATIC_READ;
  9.     //Data bytes
  10.     sendbuf[1] = 0x0;
  11.     sendbuf[2] = 0x0;
  12.     sendbuf[3] = 0x0;
  13.     sendbuf[4] = 0x0;
  14.  
  15.     t.rxlength=(byte_count+1)*8;
  16.     t.length=(byte_count+1)*8;
  17.     ret=spi_device_transmit(handle, &t);
  18.  
  19. }
  20.  
  21. int32_t IRAM_ATTR read_adc_wchid(){
  22.  
  23.      int32_t adc_reading = 0;
  24.      char adc_sign = 0x0;
  25.      char adc_channel = 0x0;
  26.  
  27.     read_from_register(REG_ADCDATA,4);
  28.  
  29.     adc_sign = recvbuf[1] & 0b00001111;
  30.     adc_channel = recvbuf[1] & 0b11110000;
  31.     adc_channel = adc_channel >> 4;
  32.     if (MCP_MODEL == 3461 || MCP_MODEL == 3462 || MCP_MODEL == 3464){
  33.         adc_reading = recvbuf[3];
  34.         adc_reading = adc_reading<<8;
  35.         adc_reading = adc_reading | recvbuf[4];
  36.         if(adc_sign!=0x0){//In case of a negative value, convert to negative
  37.             adc_reading = -65536 + adc_reading;
  38.         }
  39.     }
  40.  
  41.     else if (MCP_MODEL == 3561 || MCP_MODEL == 3562 || MCP_MODEL == 3564){
  42.         adc_reading = recvbuf[2];
  43.         adc_reading = adc_reading << 8;
  44.         adc_reading = adc_reading | recvbuf[3];
  45.         adc_reading = adc_reading << 8;
  46.         adc_reading = adc_reading | recvbuf[4];
  47.         if(adc_sign!=0x0){//In case of a negative value, convert to negative
  48.             adc_reading = -16777216 + adc_reading;
  49.         }
  50.     }
  51.     int adc_intch = adc_channel;
  52.     adc_results[adc_intch] = adc_reading;
  53.  return adc_reading;
  54. }
  55.  
  56. void config_interrupt(){
  57.  
  58.     gpio_config_t io_conf;
  59.     io_conf.intr_type = GPIO_INTR_NEGEDGE;
  60.     io_conf.pin_bit_mask = 1<<GPIO_INPUT_PIN_SEL;
  61.     io_conf.mode = GPIO_MODE_INPUT;
  62.     io_conf.pull_down_en = 0;
  63.     io_conf.pull_up_en = 0;
  64.     gpio_config(&io_conf);
  65.     gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
  66.     gpio_isr_handler_add(GPIO_IRQ, gpio_isr_handler, (void*) GPIO_IRQ);
  67.     gpio_intr_disable(GPIO_IRQ);
  68.    
  69. }
  70.  
  71. void start_scan(){
  72.  
  73.     fast_command(FAST_ADC_START);
  74.     vTaskDelay(50 / portTICK_PERIOD_MS); //read first value
  75. //begin read loop
  76.     read_adc_wchid();
  77.     gpio_intr_enable(GPIO_IRQ);
  78.     //int l;
  79.    // for( l = 0; l < 14; l = l + 1){
  80.    //vTaskDelay(40 / portTICK_PERIOD_MS); //read second value
  81.     //read_adc_wchid();
  82.    // }
  83.    
  84. }
  85.  
  86. void app_main(void)
  87. {
  88.  
  89.     init_adc(EXT_CLK);
  90.     enter_scan_mode();
  91.     start_scan();
  92.     config_interrupt();
  93.     while(1) {
  94.         start_scan();
  95.         vTaskDelay(1000 / portTICK_PERIOD_MS);
  96.         printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",adc_results[0],adc_results[1],adc_results[2],adc_results[3],adc_results[4],adc_results[5],adc_results[6],adc_results[7],adc_results[8],adc_results[9],adc_results[10],adc_results[11],adc_results[12],adc_results[13],adc_results[14],adc_results[15]);
  97.     }
  98.  
  99. };
and I thought I was getting closer cause one minor variation made a single extra read trigger...
but now I'm back to crashing again?

Code: Select all


I (509) gpio: GPIO[13]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:2
Guru Meditation Error: Core  0 panic'ed (Interrupt wdt timeout on CPU0).

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

A2      : 0x3ffc497c  A3      : 0x3ffc3b04  A4      : 0x00060c21  A5      : 0x3ffc4954
A6      : 0x3ffc09a8  A7      : 0x3ffc09b0  A8      : 0x3ffc3b04  A9      : 0x3ffc3b04
A10     : 0x00000019  A11     : 0x00000019  A12     : 0x0000000c  A13     : 0x3ffc3a10
A14     : 0x3ffbe598  A15     : 0x3ffc3a30  SAR     : 0x00000020  EXCCAUSE: 0x00000005
EXCVADDR: 0x00000000  LBEG    : 0x0000000c  LEND    : 0x3ffc3a10  LCOUNT  : 0x40024f78
0x40024f78: 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    : 0x4009622f  EPC2    : 0x00000000  EPC3    : 0x00000000  EPC4    : 0x40029bca
0x4009622f: uart_hal_write_txfifo at C:/Users/mcp3461/Desktop/esp-idf/components/soc/src/hal/uart_hal_iram.c:35

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


Backtrace:0x40029bc7:0x3ffbea50 0x40028faa:0x3ffbea70 0x4002a3a4:0x3ffbea90 0x40086f41:0x3ffbead0 0x40086f70:0x3ffbeb10 0x400833b5:0x3ffbeb40 0x4002618d:0x3ffbeb60 0x400261cb:0x3ffbeb80 0x40026c21:0x3ffbeba0 0x40025d9e:0x3ffbebc0 0x4009551f:0x3ffc3a60 0x40082c77:0x3ffc3a80 0x40028a26:0x3ffc3aa0 0x40028375:0x3ffc3ac0
0x40029bc7: vListInsert at C:/Users/mcp3461/Desktop/esp-idf/components/freertos/list.c:189

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

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

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

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

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

0x4002618d: read_adc_wchid at c:\users\mcp3461\desktop\esp-idf\mcp\build/../main/mcp3x6x_spi.h:1140

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

0x40026c21: 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

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

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

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

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

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



ELF file SHA256: 5effa2e0a79cdbc5

Rebooting...
ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x3 (RTC_SW_SYS_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x40024fe9
0x40024fe9: esp_restart_noos_dig at C:/Users/mcp3461/Desktop/esp-idf/components/esp_system/system_api.c:60 (discriminator 1)

ESP_Sprite
Posts: 9020
Joined: Thu Nov 26, 2015 4:08 am

Re: Implementation of Interrupt Allocation

Postby ESP_Sprite » Sat Jul 11, 2020 1:19 pm

Don't do any blocking operations, like starting up SPI transfers, in an interrupt. Set up a semaphore and have a task wait on that and set up the SPi transfer there.

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

Re: Implementation of Interrupt Allocation

Postby usulrasolas » Sat Jul 11, 2020 3:59 pm

I am trying to implement a binary semaphore like in example spi_slave/sender. Will see how it goes

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

Re: Implementation of Interrupt Allocation

Postby usulrasolas » Sat Jul 11, 2020 6:40 pm

It's odd, I'm missing reads here without having any sort of delay codes, out of 4 read events that should be triggered, i'm missing #1 and #3.
It shouldn't take over 80ms to setup irq event to respond to negative edge right?
I can post code again if helpful, but it seems odd that I would be able to read some events and miss others when both events in the loop are the same in all cases.
Even if I only set it to trigger once without any form of loop, it reads the 2nd event, which is technically the 2nd negative edge and 3rd any edge via scope and signal analyzer?

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

Re: Implementation of Interrupt Allocation

Postby usulrasolas » Sat Jul 11, 2020 10:46 pm

Haven't whipped this yet, it appears that every time it comes to the scan mode event (which is what is looping the interrupt to read and back again) it will read the FIRST returned value the first time it goes through, and then only the LAST value every other time but that, it doesn't matter if I loop the expected amount of returns or the maximum, I always get the same results...
Will continue iterating but am unsure what would cause this

Who is online

Users browsing this forum: Baidu [Spider], Majestic-12 [Bot] and 140 guests