I am currently stuck trying to understand what is happening with my code in ULP.
I am using an IRLED and phototransistor combo to detect entry events using the ULP.
I originally used this example:
https://github.com/espressif/esp-idf/tr ... riscv/gpio
Which puts the ULP processor into an infinite while loop until the wakeup function is called.
I have now begun utilising the ULP without the infinite while loop like this new example:
https://github.com/espressif/esp-idf/tr ... 20_onewire
However, now that I turn the ULP off and on every 300ms, it appears that the pin config is incorrect after the first reset (assumption, unlikely true, the real change is explained below).
Example:
- [code]
- for(int i = 13; i < 17; ++i){ //cycle through GPIO's 13 to 16
- wait(2000); //Keep LED's off for 1000 cycles
- example_ulp_gpio_init(i); //Init LED Pin
- example_ulp_gpio_output_enable(i); //Set LED pin as input/drain
- example_ulp_gpio_set_output_mode(i, 1); //Set LED output to high
- wait(2000); //Keep LED on for 2000 cycles
- gpio_level = (bool)example_ulp_gpio_get_level(GPIO_NUM_21); //Check level of Phototransistor
- if((bool)example_ulp_gpio_get_level(GPIO_NUM_21))
- { //If phototransistor level is 1 - an LED is being blocked
- yellow_heartbeat();
- }
- wait(6000); //Keep LED on for 6000 cycles
- example_ulp_gpio_output_disable(i);
- example_ulp_gpio_deinit(i);
- }
- [/code]
However without the infinite while loop it works the first time the gpio_level is changed and then never again.
It seems as though I need setup the GPIO lines at the beginning of the main loop, I have tried this:
Code: Select all
[Codebox=c file=Untitled.c]
example_ulp_gpio_init(GPIO_NUM_21);
example_ulp_gpio_input_enable(GPIO_NUM_21);
example_ulp_gpio_pulldown_disable(GPIO_NUM_21);
example_ulp_gpio_pullup_disable(GPIO_NUM_21);
[/Codebox]
I hope I've explained this issue well enough.
I have searched the forums and the datasheet to understand how to configure the pins in ULP but I'm falling short of a solution.
Using the get_level function in ULP seems like a pretty straight forward process, so I'm not understanding where I could be going wrong, hopefully it's something simple that I've missed...
Any help is greatly appreciated,
Cheers