convert raw reading from GPIO39 to voltage would result in crash
Posted: Fri Apr 12, 2019 2:39 pm
<r>I could not understanding why ESP-IDF voltage calculation if apply to convert the raw reading from GPIO39 would result in crash
<br/>
uint32_t voltage = esp_adc_cal_raw_to_voltage(read_raw, adc_chars);<br/>
<br/>
Below is the simple source code<br/>
<br/>
<br/>
uint32_t voltage = esp_adc_cal_raw_to_voltage(read_raw, adc_chars);<br/>
<br/>
Below is the simple source code<br/>
<br/>
- #include <stdio.h><br/>
- #include <stdlib.h><br/>
- #include "freertos/FreeRTOS.h"<br/>
- #include "freertos/task.h"<br/>
- #include "freertos/queue.h"<br/>
- #include "driver/gpio.h"<br/>
- #include "driver/adc.h"<br/>
- #include "driver/dac.h"<br/>
- #include "esp_system.h"<br/>
- #include "esp_adc_cal.h"<br/>
- #define BLINK_GPIO 2
- <br/>
- <br/>
- static void Read_GPIO39() {<br/>
- int read_raw = 0;<br/>
- adc1_config_width(ADC_WIDTH_BIT_12);<br/>
- adc1_config_channel_atten(ADC1_CHANNEL_3, ADC_ATTEN_DB_11);<br/>
- read_raw=adc1_get_raw(ADC1_CHANNEL_3);<br/>
- **//uint32_t voltage = esp_adc_cal_raw_to_voltage(read_raw, adc_chars);**<br/>
- printf("Intensity : %d\n", read_raw);<br/>
- <br/>
- //printf("Voltage: %d\n", voltage);<br/>
- gpio_pad_select_gpio(BLINK_GPIO);<br/>
- gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);<br/>
- gpio_set_level(BLINK_GPIO, 1);<br/>
- }<br/>
- <br/>
- <br/>
- void app_main() {<br/>
- ESP_ERROR_CHECK(nvs_flash_init());<br/>
- // initialise_wifi();<br/>
- while (1) {<br/>
- Read_GPIO39();<br/>
- <br/>
- vTaskDelay(3000 / portTICK_PERIOD_MS);<br/>
- gpio_set_level(BLINK_GPIO, 0);<br/>
- }<br/>
- }