当前位置:网站首页>Qiming cloud sharing: tips on esp32c3 simple IO and serial port
Qiming cloud sharing: tips on esp32c3 simple IO and serial port
2022-06-24 04:40:00 【Qiming cloud】
1. Specify chip
Pay attention to setting the target chip before compiling Set command :
idf.py set-target esp32c3
Be careful , This will clear and initialize the compilation and configuration before the project ( if there be )
Otherwise, an error will be reported as follows :
Default configuration is ESP32 If you are using ESP32 You don't need this sentence
idf.py set-target esp32c3
2. Burn in the generated file
compile , idf.py -p COM5 flash Burn in
3. Hardware Connect
connection : 18 Foot joint rgb Of a lamp G The segment is green 19 Pick up rgb Of a lamp B paragraph
Displayed in cyan , there 18 You can talk to 19 Exchange , Because the lighting time is consistent with the intensity
4. GPIO initialization
Then the simplest and most important IO Initialization and output
gpio_config_t io_conf; // establish io Configuration structure
io_conf.intr_type = GPIO_INTR_DISABLE; // Disable interrupt
io_conf.mode = GPIO_MODE_OUTPUT; // Set to output mode
io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;
//io Pin mask , Use bitwise operations Move left to the bit that needs to be changed
//#define GPIO_OUTPUT_PIN_SEL ((1ULL<<GPIO_OUTPUT_IO_0/*18*/) | \
//(1ULL<<GPIO_OUTPUT_IO_1/*19*/))
// The macro is to first set 1 The strong conversion type is unsigned long integer, and the left shift or operation makes 18,19 Configured together as output
io_conf.pull_down_en = 0; // Pull down mode enable close
io_conf.pull_up_en = 0; // Pull up mode enable open
gpio_config(&io_conf); //gpio To configure
5. Output control
The output is already configured
gpio_set_level(GPIO_OUTPUT_IO_0, 0); //18 The pin is set to low level
gpio_set_level(GPIO_OUTPUT_IO_1, 1); //19 The pin is set to high level
6. Receive initialization
At this time, the output is ready , Then there is reception
//interrupt of rising edge
io_conf.intr_type = GPIO_INTR_POSEDGE; // Set rising edge interrupt
//bit mask of the pins, use GPIO4/5 here
io_conf.pin_bit_mask = GPIO_INPUT_PIN_SEL; //io Pin mask , Use bitwise operations Move left to the bit that needs to be changed
//set as input mode
io_conf.mode = GPIO_MODE_INPUT; // Set to input mode
//enable pull-up mode
io_conf.pull_up_en = 1; // Pull up mode enable open
gpio_config(&io_conf);
Receiving includes interrupt receiving and reading IO Voltage reception
Advantages of interrupt reception : Compared with real-time reading
Read IO advantage : Easy to operate
7. Get the input level
Read IO :
Int IO0_level = gpio_get_level( GPIO_INPUT_IO_0); /* The return value is read IO_0 High and low levels of */
Interrupt plus thread :
//change gpio intrrupt type for one pin
gpio_set_intr_type(GPIO_INPUT_IO_0, GPIO_INTR_ANYEDGE);
// Change one pin Of Interrupt type
//create a queue to handle gpio event from isr
gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t)); // Create a new queue
//start gpio task
xTaskCreate(gpio_task_example, "gpio_task_example", 2048, NULL, 10, NULL); // Open the thread and run the function gpio_task_example
//install gpio isr service
gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT); // For the corresponding GPIO Pin add ISR The handler
//hook isr handler for specific gpio pin
gpio_isr_handler_add(GPIO_INPUT_IO_0, gpio_isr_handler, (void*) GPIO_INPUT_IO_0); // For the corresponding GPIO add to ISR The handler
//hook isr handler for specific gpio pin
gpio_isr_handler_add(GPIO_INPUT_IO_1, gpio_isr_handler, (void*) GPIO_INPUT_IO_1); // For the corresponding GPIO add to ISR The handler
//remove isr handler for gpio number.
gpio_isr_handler_remove(GPIO_INPUT_IO_0); // Delete the corresponding ISR Program Here, test the corresponding function
//hook isr handler for specific gpio pin again
gpio_isr_handler_add(GPIO_INPUT_IO_0, gpio_isr_handler, (void*) GPIO_INPUT_IO_0); // Add again
static void IRAM_ATTR gpio_isr_handler(void* arg)
{
uint32_t gpio_num = (uint32_t) arg;
xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
}
static void gpio_task_example(void* arg)
{
uint32_t io_num;
for(;;)
{
if(xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY))
{
printf("GPIO[%d] intr, val: %d\n", io_num, gpio_get_level(io_num));
}
}
}
Concrete demo In the downloaded esp-idf\examples\peripherals\gpio\gpio\generic_gpio
边栏推荐
- Abnova peptide design and synthesis solutions
- Brief introduction: how much do you know about supply chain attacks
- Huawei cloud gaussdb (for redis) unveiling issue 19: gaussdb (for redis) comprehensive comparison with CODIS
- How does ECS build websites? Is it troublesome for ECs to build websites?
- Digital transformation practice of Zheshang Bank
- ServiceStack. Source code analysis of redis (connection and connection pool)
- 编译器是如何将芯片执行的第一个指令放到芯片起始地址的?
- How to build a website for ECS is the price of ECS very expensive
- An interface testing software that supports offline document sharing in the Intranet
- What is etcd and its application scenarios
猜你喜欢

Introduction to gradient descent method - black horse programmer machine learning handout

Introduction à la méthode de descente par Gradient - document d'apprentissage automatique pour les programmeurs de chevaux noirs

SAP MTS/ATO/MTO/ETO专题之十:ETO模式 Q+空模式 未估价库存 策略自定义

Facebook内部通告:将重新整合即时通讯功能

Training course of mixed accuracy from simple to deep

2022年二级造价工程师备考攻略,你准备好了吗?

外网访问svn服务器(外网访问部署在云上的svn服务器)

Introduction to C language custom types (structure, enumeration, union, bit segment)
Advanced authentication of uni app [Day12]

编译器是如何将芯片执行的第一个指令放到芯片起始地址的?
随机推荐
DP summary of ACM in recent two weeks
ribbon
Specificity and correlation of Worthington deoxyribonuclease I
[2021 "shadow seeking" medical artificial intelligence algorithm competition] frequently asked questions related to Ti-One products
阿里云新一代云计算体系架构 CIPU 到底是啥?
Chemical properties and specificity of Worthington Papain
How does the compiler put the first instruction executed by the chip at the start address of the chip?
How to install software on ECs is it expensive to rent ECS
Library management backstage
Collagenase -- four types of crude collagenase from Worthington
Multi task video recommendation scheme, baidu engineers' actual combat experience sharing
ribbon
How to change the IP address of ECS? What are the precautions for changing the IP address
An interface testing software that supports offline document sharing in the Intranet
Clang code coverage detection (pile insertion technology)
mysql中表的命名
How does ECS build websites? Is it troublesome for ECs to build websites?
How does ECS select bandwidth? What types of servers do you usually have?
博士申请 | 香港科技大学(广州)刘浩老师招收数据挖掘方向全奖博士/硕士
After purchasing Tencent ECs, how to solve packet loss in Internet access?