Implementation of Interrupt Allocation
-
- Posts: 26
- Joined: Tue Jun 09, 2020 5:27 pm
Re: Implementation of Interrupt Allocation
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
the example gpio irq code does run, but not my implementation of the interrupt
-
- Posts: 26
- Joined: Tue Jun 09, 2020 5:27 pm
Re: Implementation of Interrupt Allocation
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...
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...
-
- Posts: 9766
- Joined: Thu Nov 26, 2015 4:08 am
Re: Implementation of Interrupt Allocation
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.
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.
-
- Posts: 26
- Joined: Tue Jun 09, 2020 5:27 pm
Re: Implementation of Interrupt Allocation
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.
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.
- static void IRAM_ATTR gpio_isr_handler(void* arg)
- {
- //read_adc_wchid();
- printf("ADC Interrupt Reading %d,%d,%d,%d,%d\n",recvbuf[0],recvbuf[1],recvbuf[2],recvbuf[3],recvbuf[4]);
- }
- void config_interrupt(){
- gpio_config_t io_conf;
- io_conf.intr_type = GPIO_INTR_NEGEDGE;
- io_conf.pin_bit_mask = 1<<GPIO_INPUT_PIN_SEL;
- io_conf.mode = GPIO_MODE_INPUT;
- io_conf.pull_down_en = 0;
- io_conf.pull_up_en = 0;
- gpio_config(&io_conf);
- gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
- gpio_isr_handler_add(GPIO_IRQ, gpio_isr_handler, (void*) GPIO_IRQ);
- }
- void start_scan(){
- fast_command(FAST_ADC_START);
- vTaskDelay(50 / portTICK_PERIOD_MS); //read first value
- //begin read loop
- read_adc_wchid();
- //int l;
- // for( l = 0; l < 14; l = l + 1){
- //vTaskDelay(40 / portTICK_PERIOD_MS); //read next value
- //read_adc_wchid();
- // }
- }
- void app_main(void)
- {
- init_adc(EXT_CLK);
- enter_scan_mode();
- start_scan();
- config_interrupt();
- while(1) {
- start_scan();
- vTaskDelay(1000 / portTICK_PERIOD_MS);
- 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]);
- }
- }
-
- Posts: 26
- Joined: Tue Jun 09, 2020 5:27 pm
Re: Implementation of Interrupt Allocation
I can see I need to move tje printf function, but should I also include the code for the read_adc_wchid?
-
- Posts: 26
- Joined: Tue Jun 09, 2020 5:27 pm
Re: Implementation of Interrupt Allocation
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)
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?
(with added sections)
- #define GPIO_IRQ 13
- #define ESP_INTR_FLAG_DEFAULT 0
- #define GPIO_INPUT_PIN_SEL GPIO_IRQ
- void read_from_register(char register_id,unsigned int byte_count){
- register_id <<= 2;
- sendbuf[0] = register_id | STATIC_READ;
- //Data bytes
- sendbuf[1] = 0x0;
- sendbuf[2] = 0x0;
- sendbuf[3] = 0x0;
- sendbuf[4] = 0x0;
- t.rxlength=(byte_count+1)*8;
- t.length=(byte_count+1)*8;
- ret=spi_device_transmit(handle, &t);
- }
- int32_t IRAM_ATTR read_adc_wchid(){
- int32_t adc_reading = 0;
- char adc_sign = 0x0;
- char adc_channel = 0x0;
- read_from_register(REG_ADCDATA,4);
- adc_sign = recvbuf[1] & 0b00001111;
- adc_channel = recvbuf[1] & 0b11110000;
- adc_channel = adc_channel >> 4;
- if (MCP_MODEL == 3461 || MCP_MODEL == 3462 || MCP_MODEL == 3464){
- adc_reading = recvbuf[3];
- adc_reading = adc_reading<<8;
- adc_reading = adc_reading | recvbuf[4];
- if(adc_sign!=0x0){//In case of a negative value, convert to negative
- adc_reading = -65536 + adc_reading;
- }
- }
- else if (MCP_MODEL == 3561 || MCP_MODEL == 3562 || MCP_MODEL == 3564){
- adc_reading = recvbuf[2];
- adc_reading = adc_reading << 8;
- adc_reading = adc_reading | recvbuf[3];
- adc_reading = adc_reading << 8;
- adc_reading = adc_reading | recvbuf[4];
- if(adc_sign!=0x0){//In case of a negative value, convert to negative
- adc_reading = -16777216 + adc_reading;
- }
- }
- int adc_intch = adc_channel;
- adc_results[adc_intch] = adc_reading;
- return adc_reading;
- }
- void config_interrupt(){
- gpio_config_t io_conf;
- io_conf.intr_type = GPIO_INTR_NEGEDGE;
- io_conf.pin_bit_mask = 1<<GPIO_INPUT_PIN_SEL;
- io_conf.mode = GPIO_MODE_INPUT;
- io_conf.pull_down_en = 0;
- io_conf.pull_up_en = 0;
- gpio_config(&io_conf);
- gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
- gpio_isr_handler_add(GPIO_IRQ, gpio_isr_handler, (void*) GPIO_IRQ);
- gpio_intr_disable(GPIO_IRQ);
- }
- void start_scan(){
- fast_command(FAST_ADC_START);
- vTaskDelay(50 / portTICK_PERIOD_MS); //read first value
- //begin read loop
- read_adc_wchid();
- gpio_intr_enable(GPIO_IRQ);
- //int l;
- // for( l = 0; l < 14; l = l + 1){
- //vTaskDelay(40 / portTICK_PERIOD_MS); //read second value
- //read_adc_wchid();
- // }
- }
- void app_main(void)
- {
- init_adc(EXT_CLK);
- enter_scan_mode();
- start_scan();
- config_interrupt();
- while(1) {
- start_scan();
- vTaskDelay(1000 / portTICK_PERIOD_MS);
- 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]);
- }
- };
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)
-
- Posts: 9766
- Joined: Thu Nov 26, 2015 4:08 am
Re: Implementation of Interrupt Allocation
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.
-
- Posts: 26
- Joined: Tue Jun 09, 2020 5:27 pm
Re: Implementation of Interrupt Allocation
I am trying to implement a binary semaphore like in example spi_slave/sender. Will see how it goes
-
- Posts: 26
- Joined: Tue Jun 09, 2020 5:27 pm
Re: Implementation of Interrupt Allocation
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?
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?
-
- Posts: 26
- Joined: Tue Jun 09, 2020 5:27 pm
Re: Implementation of Interrupt Allocation
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
Will continue iterating but am unsure what would cause this
Who is online
Users browsing this forum: Baidu [Spider] and 180 guests