83935dda2d6feccda5844fac26bb900116c0dfc2
Board-dat/MSP/MSP1064-dat/MSP1064-dat.md
... | ... | @@ -14,4 +14,4 @@ https://www.electrodragon.com/w/IIC |
14 | 14 | |
15 | 15 | - [[GPIO-dat]] |
16 | 16 | |
17 | -- [[PCF8574-dat]] |
|
... | ... | \ No newline at end of file |
0 | +- [[PCF8574-dat]] - [[PCF8591-dat]] |
|
... | ... | \ No newline at end of file |
Board-dat/MSP/MSP1069-dat/MSP1069-dat.md
... | ... | @@ -1,6 +1,8 @@ |
1 | 1 | |
2 | 2 | # MSP1069-dat |
3 | 3 | |
4 | +- chip-hold |
|
5 | + |
|
4 | 6 | |
5 | 7 | ## ref |
6 | 8 |
Board-dat/MSP/MSP1072-dat/MSP1072-dat.md
... | ... | @@ -11,9 +11,9 @@ |
11 | 11 | |
12 | 12 | ## ref |
13 | 13 | |
14 | -- [[CH423-dat]] - [[WCH-dat]] |
|
14 | +- [[CH423-dat]] - [[WCH-dat]] |
|
15 | 15 | |
16 | -- [[GPIO-dat]] |
|
16 | +- [[GPIO-dat]] - [[I2C-dat]] |
|
17 | 17 | |
18 | 18 | |
19 | 19 | - [[MSP1072]] |
... | ... | \ No newline at end of file |
Chip-cn-dat/WCH-dat/CH423-dat/2024-12-04-17-36-12.png
... | ... | Binary files /dev/null and b/Chip-cn-dat/WCH-dat/CH423-dat/2024-12-04-17-36-12.png differ |
Chip-cn-dat/WCH-dat/CH423-dat/CH423-dat.md
... | ... | @@ -1,3 +1,15 @@ |
1 | 1 | |
2 | 2 | # CH423-dat |
3 | 3 | |
4 | +https://www.wch-ic.com/products/CH423.html |
|
5 | + |
|
6 | +![](2024-12-04-17-36-12.png) |
|
7 | + |
|
8 | +- [[CH423DS1.PDF]] |
|
9 | + |
|
10 | + |
|
11 | +## code refe |
|
12 | + |
|
13 | +- Linux driver for WCH CH423 - https://github.com/Edragon/ch423-gpio-expander |
|
14 | + |
|
15 | +- [[ch423-ard-demo-blink.ino]] - [[ch423-ard-demo-group.ino]] - [[ch423-ard-demo-input.ino]] - [[ch423-ard-demo-ioInterrupt.ino]] - [[ch423-ard-demo-pollInterrupt.ino]] - [[ch423-ard-demo-sleep.ino]] - [[ch423-ard-demo-waterLamp.ino]] |
|
... | ... | \ No newline at end of file |
Chip-cn-dat/WCH-dat/CH423-dat/CH423DS1.PDF
... | ... | Binary files /dev/null and b/Chip-cn-dat/WCH-dat/CH423-dat/CH423DS1.PDF differ |
Chip-cn-dat/WCH-dat/CH423-dat/ch423-ard-demo-blink.ino
... | ... | @@ -0,0 +1,112 @@ |
1 | + |
|
2 | +/*! |
|
3 | + * @file blink.ino |
|
4 | + * @brief Turns an LED on for one second, then off for one second, repeatedly. |
|
5 | + * @note This module implements the blink function in 2 ways: |
|
6 | + * @n 1. Set GPIO group pins to output mode and connect the LED lamp to one of the GPIO pins (GPIO0~GPIO7), and control the pin to output high and low levels; |
|
7 | + * @n 2. Set GPO group pins as push-pull output mode and connect the LED lamp to one of the GP0 pins (GPO0~GPO15), and control the pin to output high and low levels; |
|
8 | + * @n Hardware connection: connect the LED pin to the corresponding output pin |
|
9 | + * |
|
10 | + * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) |
|
11 | + * @license The MIT License (MIT) |
|
12 | + * @author [Arya](xue.peng@dfrobot.com) |
|
13 | + * @version V1.0 |
|
14 | + * @date 2022-03-09 |
|
15 | + * @url https://github.com/DFRobot/DFRobot_CH423 |
|
16 | + */ |
|
17 | +#include "DFRobot_CH423.h" |
|
18 | + |
|
19 | +//Disable the macro, and the blink function will shift to the pin GPO0 of GPO pins, otherwise, it will be implemented by the pin GPIO0 of GPIO pins |
|
20 | +#define GPIO_ENABLE |
|
21 | + |
|
22 | +DFRobot_CH423 ch423; |
|
23 | + |
|
24 | +void setup() { |
|
25 | + Serial.begin(115200); |
|
26 | + |
|
27 | + while(!Serial){ |
|
28 | + |
|
29 | + } |
|
30 | + ch423.begin(); |
|
31 | + /** |
|
32 | + * @fn pinMode |
|
33 | + * @brief Set the mode of the pin group, this module contains 2 groups of pins: GPIO(GPIO0~GPIO7) and GPO(GPO0~GPO15). |
|
34 | + * @note This module sets the mode by group, the pins in a group can only be set as one mode at the same time, and the pins in different groups can be set as different modes |
|
35 | + * @param group Pin group parameter, ePinGroup_t enum variable member |
|
36 | + * @n eGPIO Bi-directional I/O pin, GPIO0-GPIO7, which can be set as input(eINPUT) or output(eOUTPUT) mode, setting to other modes is invalid |
|
37 | + * @n eGPO/eGPO0_7/eGPO8_15 The three parameters indicate the same meaning, set the mode of GPO group pins, select the parameter and GPO pins can only be configured as open-drain(eOPEN_DRAIN) or push-pull(ePUSH_PULL) output mode, other modes are invalid |
|
38 | + * @param mode Group pin mode parameter, as member enum variable of eMode_t |
|
39 | + * @n eINPUT GPIO pin input mode, at high level when floating, this mode can only be used for eGPIO digital ports |
|
40 | + * @n eOUTPUT GPIO pin output mode, can output high and low levels, this mode can only be used for eGPIO digital ports |
|
41 | + * @n eOPEN_DRAIN GPO pin open-drain output mode, the GPO pins only output low level or don't output in this mode, it can only be used for eGPO group digital ports |
|
42 | + * @n ePUSH_PULL GPO pin push-pull output mode, the GPO pin can output high or low level in this mode, it can only be used for eGPO digital ports |
|
43 | + */ |
|
44 | +#ifdef GPIO_ENABLE |
|
45 | + ch423.pinMode(ch423.eGPIO, ch423.eOUTPUT); |
|
46 | +#else |
|
47 | + ch423.pinMode(ch423.eGPO, ch423.ePUSH_PULL); |
|
48 | +#endif |
|
49 | +} |
|
50 | + |
|
51 | +void loop() { |
|
52 | +#ifdef GPIO_ENABLE |
|
53 | + /** |
|
54 | + * @fn |
|
55 | + * @brief Set the pin outputting high or low level |
|
56 | + * @param gpioPin GPIO group pins, eGPIOPin_t enum variable member |
|
57 | + * @n eGPIO0 Bi-directional I/O pin, GPIO0, indicates setting the output value of pin GPIO0 |
|
58 | + * @n eGPIO1 Bi-directional I/O pin, GPIO1, indicates setting the output value of pin GPIO1 |
|
59 | + * @n eGPIO2 Bi-directional I/O pin, GPIO2, indicates setting the output value of pin GPIO2 |
|
60 | + * @n eGPIO3 Bi-directional I/O pin, GPIO3, indicates setting the output value of pin GPIO3 |
|
61 | + * @n eGPIO4 Bi-directional I/O pin, GPIO4, indicates setting the output value of pin GPIO4 |
|
62 | + * @n eGPIO5 Bi-directional I/O pin, GPIO5, indicates setting the output value of pin GPIO5 |
|
63 | + * @n eGPIO6 Bi-directional I/O pin, GPIO6, indicates setting the output value of pin GPIO6 |
|
64 | + * @n eGPIO7 Bi-directional I/O pin, GPIO7, indicates setting the output value of pin GPIO7 |
|
65 | + * @n eGPIOTotal sets the values of all GPIO group pins, when using this parameter, bit0~bit7 of parameter level are valid values, corresponding to the output values of pins GPIO0~GPIO7 respectively. |
|
66 | + * @param level Output level |
|
67 | + * @n HIGH or 1 Parameter level, bit0 in 8-bit data is valid, which indicates outputting high level |
|
68 | + * @n LOW or 0 Parameter level, bit0 in 8-bit data is valid, which indicates outputting low level |
|
69 | + * @n 0x00~0xFF If parameter gpioPin is GPIOTotal, bit0~bit7 of parameter level are valid data, corresponding to GPIO0~GPIO7 pins respectively. |
|
70 | + */ |
|
71 | + ch423.digitalWrite(/* gpio= */ch423.eGPIO0, /* level= */HIGH); // turn the LED on (HIGH is the voltage level) |
|
72 | + //ch423.digitalWrite(/* gpio= */ch423.eGPIOTotal, /* level= */0xFF); // set all pins in GPIO group(GPIO0~GPIO7) outputting high level |
|
73 | + delay(1000); // wait for a second |
|
74 | + ch423.digitalWrite(/* gpio= */ch423.eGPIO0, /* level= */LOW); // turn the LED off by making the voltage LOW |
|
75 | + //ch423.digitalWrite(/* gpio= */ch423.eGPIOTotal, /* level= */0x00); // set all pins in GPIO group(GPIO0~GPIO7) outputting low level |
|
76 | + delay(1000); // wait for a second |
|
77 | +#else |
|
78 | + /** |
|
79 | + * @fn digitalWrite |
|
80 | + * @brief Set the pin outputting high and low level, or control to output or stop (interrupt) low level |
|
81 | + * @param gpoPin eGPOPin_t enum variable member |
|
82 | + * @n eGPO0 GPO pin, GPO0, indicates setting the output value of pin GPO0 |
|
83 | + * @n eGPO1 GPO pin, GPO1, indicates setting the output value of pin GPO1 |
|
84 | + * @n eGPO2 GPO pin, GPO2, indicates setting the output value of pin GPO2 |
|
85 | + * @n eGPO3 GPO pin, GPO3, indicates setting the output value of pin GPO3 |
|
86 | + * @n eGPO4 GPO pin, GPO4, indicates setting the output value of pin GPO4 |
|
87 | + * @n eGPO5 GPO pin, GPO5, indicates setting the output value of pin GPO5 |
|
88 | + * @n eGPO6 GPO pin, GPO6, indicates setting the output value of pin GPO6 |
|
89 | + * @n eGPO7 GPO pin, GPO7, indicates setting the output value of pin GPO7 |
|
90 | + * @n eGPO8 GPO pin, GPO8, indicates setting the output value of pin GPO8 |
|
91 | + * @n eGPO9 GPO pin, GPO9, indicates setting the output value of pin GPO9 |
|
92 | + * @n eGPO10 GPO pin, GPO10, indicates setting the output value of pin GPO10 |
|
93 | + * @n eGPO11 GPO pin, GPO11, indicates setting the output value of pin GPO11 |
|
94 | + * @n eGPO12 GPO pin, GPO12, indicates setting the output value of pin GPO12 |
|
95 | + * @n eGPO13 GPO pin, GPO13, indicates setting the output value of pin GPO13 |
|
96 | + * @n eGPO14 GPO pin, GPO14, indicates setting the output value of pin GPO14 |
|
97 | + * @n eGPO15 GPO pin, GPO15, indicates setting the output value of pin GPO15 |
|
98 | + * @n eGPOTotal sets all the GPO pins of 0~15, when using this parameter, the bit0~bit7 of the parameter 8-bit data level correspond to the output value of GPO0~GPO7 or GPO8~GPO15 pins respectively |
|
99 | + * @param level Output level or output (stop) low level signal |
|
100 | + * @n HIGH or 1 When GPO pin group is set to push-pull output mode, output high; for open-drain mode, output low level |
|
101 | + * @n LOW or 0 When GPO pin group is set to push-pull output mode, output low, for open-drain mode, no signal output |
|
102 | + * @n 0x00~0xFF When gpoPin parameter is eGPOTotal, bit0~bit7 of level are all valid data, corresponding to pin GPO0~GPO7 or GPO8~GPO15 |
|
103 | + */ |
|
104 | + ch423.digitalWrite(/* gpo= */ch423.eGPO0, /* level= */HIGH); // turn the LED on (HIGH is the voltage level) |
|
105 | + //ch423.digitalWrite(/* gpo= */ch423.eGPOTotal, /* level= */0xFF); // set all pins in GPO group(GPO0~GPO15) outputting high level |
|
106 | + delay(1000); // wait for a second |
|
107 | + ch423.digitalWrite(/* gpio= */ch423.eGPO0, /* level= */LOW); // turn the LED off by making the voltage LOW |
|
108 | + //ch423.digitalWrite(/* gpo= */ch423.eGPOTotal, /* level= */0x00); // set all pins in GPO group(GPO0~GPO15) outputting low level |
|
109 | + delay(1000); // wait for a second |
|
110 | +#endif |
|
111 | + |
|
112 | +} |
|
... | ... | \ No newline at end of file |
Chip-cn-dat/WCH-dat/CH423-dat/ch423-ard-demo-group.ino
... | ... | @@ -0,0 +1,136 @@ |
1 | +/*! |
|
2 | + * @file group.ino |
|
3 | + * @brief This demo is mainly used to demonstrate how to operate the digital ports of a group at a time. This module has 2 groups of digital pins, GPIO group pins and GPO pins, and GPO pins are divided into GPO0_7 group pins and GPO8_15 group pins. |
|
4 | + * @n GPIO group pins: can be used as both input pins and output pins |
|
5 | + * @n GPO group pins: can only be used as output pins, there are 2 output modes, push-pull and open-drain output mode |
|
6 | + * @n Users can operate the pins by group according to the API function provided |
|
7 | + * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) |
|
8 | + * @license The MIT License (MIT) |
|
9 | + * @author [Arya](xue.peng@dfrobot.com) |
|
10 | + * @version V1.0 |
|
11 | + * @date 2022-03-14 |
|
12 | + * @url https://github.com/DFRobot/DFRobot_CH423 |
|
13 | + */ |
|
14 | +#include "DFRobot_CH423.h" |
|
15 | + |
|
16 | +#define GROUP_GPIO_INPUT 0 |
|
17 | +#define GROUP_GPIO_OUTPUT 1 |
|
18 | +#define GROUP_GPO 2 |
|
19 | + |
|
20 | +//Demo function switch |
|
21 | +#define DEMO_FUN_SWITCH GROUP_GPIO_INPUT |
|
22 | +//#define DEMO_FUN_SWITCH GROUP_GPIO_OUTPUT |
|
23 | +//#define DEMO_FUN_SWITCH GROUP_GPO |
|
24 | + |
|
25 | +DFRobot_CH423 ch423; |
|
26 | + |
|
27 | +void setup() { |
|
28 | + Serial.begin(115200); |
|
29 | + |
|
30 | + while(!Serial){ |
|
31 | + |
|
32 | + } |
|
33 | + ch423.begin(); |
|
34 | + /** |
|
35 | + * @fn pinMode |
|
36 | + * @brief Set the mode of the pin groups, this module contains 2 groups of pins: GPIO(GPIO0~GPIO7) and GPO(GPO0~GPO15). |
|
37 | + * @note This module sets the mode by group, the pins in a group can only be set as one mode at the same time, and the pins in different groups can be set as different modes |
|
38 | + * @param group Pin group parameter, ePinGroup_t enum variable member |
|
39 | + * @n eGPIO Bi-directional I/O pin, GPIO0~GPIO7, which can be set as input(eINPUT) or output(eOUTPUT) mode, setting to other modes is invalid |
|
40 | + * @n eGPO/eGPO0_7/eGPO8_15 The three parameters indicate the same meaning, set the mode of GPO group pins, select the parameter and GPO pins can only be configured as open-drain(eOPEN_DRAIN) or push-pull(ePUSH_PULL) output mode, other modes are invalid |
|
41 | + * @param mode Group pin mode parameter, enum variable member for eMode_t |
|
42 | + * @n eINPUT GPIO pin input mode, at high level when floating, this mode can only be used for eGPIO digital ports |
|
43 | + * @n eOUTPUT GPIO pin output mode, can output high and low levels, this mode can only be used for eGPIO digital ports |
|
44 | + * @n eOPEN_DRAIN GPO pin open-drain output mode, the GPO pins only output low level or don't output in this mode, it can only be used for eGPO group digital ports |
|
45 | + * @n ePUSH_PULL GPO pin push-pull output mode, the GPO pin can output high or low level in this mode, it can only be used for eGPO digital ports |
|
46 | + */ |
|
47 | +#if(DEMO_FUN_SWITCH == GROUP_GPIO_INPUT) |
|
48 | + ch423.pinMode(ch423.eGPIO, ch423.eINPUT); |
|
49 | +#elif(DEMO_FUN_SWITCH == GROUP_GPIO_OUTPUT) |
|
50 | + ch423.pinMode(ch423.eGPIO, ch423.eOUTPUT); |
|
51 | + |
|
52 | + //Set GPIO group pin outputting 0xF0, bit0~bit7 of 0xF0 correspond to GPIO0~GPIO7 of GPIO group respectively |
|
53 | + DFRobot_CH423::uGroupValue_t gpio; |
|
54 | + |
|
55 | + gpio.GPO0 = 0; //Set pin GPIO0 outputting 0 |
|
56 | + gpio.GPO1 = 0; //Set pin GPIO1 outputting 0 |
|
57 | + gpio.GPO2 = 0; //Set pin GPIO2 outputting 0 |
|
58 | + gpio.GPO3 = 0; //Set pin GPIO3 outputting 0 |
|
59 | + gpio.GPO4 = 1; //Set pin GPIO4 outputting 1 |
|
60 | + gpio.GPO5 = 1; //Set pin GPIO5 outputting 1 |
|
61 | + gpio.GPO6 = 1; //Set pin GPIO6 outputting 1 |
|
62 | + gpio.GPO7 = 1; //Set pin GPIO7 outputting 1 |
|
63 | + //gpio.GPIO = 0xF0 |
|
64 | + |
|
65 | + ch423.digitalWrite(ch423.eGPIO, gpio); //Set GPIO0~GPIO3 outputting 0, GPIO4~GPIO7 outputting 1 |
|
66 | + //ch423.digitalWrite(ch423.eGPIO, 0xF0); //Set GPIO0~GPIO3 outputting 0, GPIO4~GPIO7 outputting 1 |
|
67 | + //ch423.digitalWrite(ch423.eGPIOTotal, 0xF0); //Set GPIO0~GPIO3 outputting 0, GPIO4~GPIO7 outputting 1 |
|
68 | + |
|
69 | + Serial.print("GPIO0 OUPUT: ");Serial.println(gpio.GPIO0); |
|
70 | + Serial.print("GPIO1 OUPUT: ");Serial.println(gpio.GPIO1); |
|
71 | + Serial.print("GPIO2 OUPUT: ");Serial.println(gpio.GPIO2); |
|
72 | + Serial.print("GPIO3 OUPUT: ");Serial.println(gpio.GPIO3); |
|
73 | + Serial.print("GPIO4 OUPUT: ");Serial.println(gpio.GPIO4); |
|
74 | + Serial.print("GPIO5 OUPUT: ");Serial.println(gpio.GPIO5); |
|
75 | + Serial.print("GPIO6 OUPUT: ");Serial.println(gpio.GPIO6); |
|
76 | + Serial.print("GPIO7 OUPUT: ");Serial.println(gpio.GPIO7); |
|
77 | +#else |
|
78 | + ch423.pinMode(ch423.eGPO, ch423.ePUSH_PULL); |
|
79 | + |
|
80 | + //Set GPO group pins outputting 0x55F0, bit0~bit15 of 0x55F0 correspond to GPO0~GPIO15 of GPO group respectively |
|
81 | + DFRobot_CH423::uGroupValue_t gpo; |
|
82 | + |
|
83 | + gpo.GPO0 = 0; //Set pin GPO0 outputting 0 |
|
84 | + gpo.GPO1 = 0; //Set pin GPO1 outputting 0 |
|
85 | + gpo.GPO2 = 0; //Set pin GPO2 outputting 0 |
|
86 | + gpo.GPO3 = 0; //Set pin GPO3 outputting 0 |
|
87 | + gpo.GPO4 = 1; //Set pin GPO4 outputting 1 |
|
88 | + gpo.GPO5 = 1; //Set pin GPO5 outputting 1 |
|
89 | + gpo.GPO6 = 1; //Set pin GPO6 outputting 1 |
|
90 | + gpo.GPO7 = 1; //Set pin GPO7 outputting 1 |
|
91 | + gpo.GPO8 = 1; //Set pin GPO0 outputting 1 |
|
92 | + gpo.GPO9 = 0; //Set pin GPO1 outputting 0 |
|
93 | + gpo.GPO10 = 1; //Set pin GPO2 outputting 1 |
|
94 | + gpo.GPO11 = 0; //Set pin GPO3 outputting 0 |
|
95 | + gpo.GPO12 = 1; //Set pin GPO4 outputting 1 |
|
96 | + gpo.GPO13 = 0; //Set pin GPO5 outputting 0 |
|
97 | + gpo.GPO14 = 1; //Set pin GPO6 outputting 1 |
|
98 | + gpo.GPO15 = 0; //Set pin GPO7 outputting 0 |
|
99 | + //gpo.GPO0_7 = 0xF0; |
|
100 | + //gpo.GPO8_15 = 0x55; |
|
101 | + //gpo.GPO = 0x55F0; |
|
102 | + |
|
103 | + ch423.digitalWrite(ch423.eGPO0_7, 0xF0); //only set GPO0~GPO7 outputting 0xF0 |
|
104 | + ch423.digitalWrite(ch423.eGPO8_15, (0x55 << 8)); //only set GPO8~GPO15 outputting 0x55 |
|
105 | + //ch423.digitalWrite(ch423.eGPO, gpo); //set pin GPO15~GPO0 outputting 0x55F0 |
|
106 | + //ch423.digitalWrite(ch423.eGPO, 0x55F0); //set pin GPO15~GPO0 outputting 0x55F0 |
|
107 | + Serial.print("GPO0 OUPUT: ");Serial.println(gpo.GPO0); |
|
108 | + Serial.print("GPO1 OUPUT: ");Serial.println(gpo.GPO1); |
|
109 | + Serial.print("GPO2 OUPUT: ");Serial.println(gpo.GPO2); |
|
110 | + Serial.print("GPO3 OUPUT: ");Serial.println(gpo.GPO3); |
|
111 | + Serial.print("GPO4 OUPUT: ");Serial.println(gpo.GPO4); |
|
112 | + Serial.print("GPO5 OUPUT: ");Serial.println(gpo.GPO5); |
|
113 | + Serial.print("GPO6 OUPUT: ");Serial.println(gpo.GPO6); |
|
114 | + Serial.print("GPO7 OUPUT: ");Serial.println(gpo.GPO7); |
|
115 | + Serial.print("GPO8 OUPUT: ");Serial.println(gpo.GPO8); |
|
116 | + Serial.print("GPO9 OUPUT: ");Serial.println(gpo.GPO9); |
|
117 | + Serial.print("GPO10 OUPUT: ");Serial.println(gpo.GPO10); |
|
118 | + Serial.print("GPO11 OUPUT: ");Serial.println(gpo.GPO11); |
|
119 | + Serial.print("GPO12 OUPUT: ");Serial.println(gpo.GPO12); |
|
120 | + Serial.print("GPO13 OUPUT: ");Serial.println(gpo.GPO13); |
|
121 | + Serial.print("GPO14 OUPUT: ");Serial.println(gpo.GPO14); |
|
122 | + Serial.print("GPO15 OUPUT: ");Serial.println(gpo.GPO15); |
|
123 | +#endif |
|
124 | +} |
|
125 | + |
|
126 | +void loop() { |
|
127 | +#if(DEMO_FUN_SWITCH == GROUP_GPIO_INPUT) |
|
128 | + //Query the value of each GPIO input pin (GPIO0~GPIO7) once in 1s |
|
129 | + //0~7 bit of value correspond to the pin status of pins GPIO0~GPIO7 respectively |
|
130 | + uint8_t value = ch423.digitalRead(ch423.eGPIOTotal); |
|
131 | + Serial.print("The group of GPIO's pins state are 0x"); |
|
132 | + Serial.println(value, HEX); |
|
133 | + delay(1000); |
|
134 | +#endif |
|
135 | + |
|
136 | +} |
|
... | ... | \ No newline at end of file |
Chip-cn-dat/WCH-dat/CH423-dat/ch423-ard-demo-input.ino
... | ... | @@ -0,0 +1,64 @@ |
1 | +/*! |
|
2 | + * @file input.ino |
|
3 | + * @brief After pressing the button, the serial print button is pressed |
|
4 | + * @note Only the pins in GPIO group can be set to input mode for this module. |
|
5 | + * |
|
6 | + * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) |
|
7 | + * @license The MIT License (MIT) |
|
8 | + * @author [Arya](xue.peng@dfrobot.com) |
|
9 | + * @version V1.0 |
|
10 | + * @date 2022-03-09 |
|
11 | + * @url https://github.com/DFRobot/DFRobot_CH423 |
|
12 | + */ |
|
13 | +#include "DFRobot_CH423.h" |
|
14 | + |
|
15 | +DFRobot_CH423 ch423; |
|
16 | + |
|
17 | +void setup() { |
|
18 | + Serial.begin(115200); |
|
19 | + |
|
20 | + while(!Serial){ |
|
21 | + |
|
22 | + } |
|
23 | + ch423.begin(); |
|
24 | + /** |
|
25 | + * @fn pinMode |
|
26 | + * @brief Set the mode of the pin groups, this module contains 2 groups of pins: GPIO(GPIO0~GPIO7) and GPO(GPO0~GPO15). |
|
27 | + * @note This module sets the mode by group, the pins in a group can only be set as one mode at the same time, and the pins in different groups can be set as different modes. |
|
28 | + * @param group Pin group parameter, ePinGroup_t enum variable member |
|
29 | + * @n eGPIO Bi-directional I/O pin, GPIO0-GPIO7, which can be set as input(eINPUT) or output(eOUTPUT) mode, setting to other modes is invalid |
|
30 | + * @n eGPO/eGPO0_7/eGPO8_15 The three parameters indicate the same meaning, set the mode of GPO group pins, select the parameter and GPO pins can only be configured as open-drain(eOPEN_DRAIN) or push-pull(ePUSH_PULL) output mode, other modes are invalid |
|
31 | + * @param mode Group pin mode parameter, as member enum variable of eMode_t |
|
32 | + * @n eINPUT GPIO pin input mode, at high level when floating, this mode can only be used for eGPIO digital ports |
|
33 | + * @n eOUTPUT GPIO pin output mode, can output high and low levels, this mode can only be used for eGPIO digital ports |
|
34 | + * @n eOPEN_DRAIN GPO pin open-drain output mode, the GPO pins only output low level or don't output in this mode, it can only be used for eGPO group digital ports |
|
35 | + * @n ePUSH_PULL GPO pin push-pull output mode, the GPO pin can output high or low level in this mode, it can only be used for eGPO digital ports |
|
36 | + */ |
|
37 | + ch423.pinMode(ch423.eGPIO, ch423.eINPUT); |
|
38 | +} |
|
39 | + |
|
40 | +void loop() { |
|
41 | + /** |
|
42 | + * @fn digitalRead |
|
43 | + * @brief Read the level status values of GPIO group pins |
|
44 | + * @param pin GPIO group pins, eGPIOPin_t enum variable member |
|
45 | + * @n eGPIO0 Bi-directional I/O pin, GPIO0, indicates reading level status of pin GPIO0, 0 for low level, 1 for high level |
|
46 | + * @n eGPIO1 Bi-directional I/O pin, GPIO1, indicates reading level status of pin GPIO1, 0 for low level, 1 for high level |
|
47 | + * @n eGPIO2 Bi-directional I/O pin, GPIO2, indicates reading level status of pin GPIO2, 0 for low level, 1 for high level |
|
48 | + * @n eGPIO3 Bi-directional I/O pin, GPIO3, indicates reading level status of pin GPIO3, 0 for low level, 1 for high level |
|
49 | + * @n eGPIO4 Bi-directional I/O pin, GPIO4, indicates reading level status of pin GPIO4, 0 for low level, 1 for high level |
|
50 | + * @n eGPIO5 Bi-directional I/O pin, GPIO5, indicates reading level status of pin GPIO5, 0 for low level, 1 for high level |
|
51 | + * @n eGPIO6 Bi-directional I/O pin, GPIO6, indicates reading level status of pin GPIO6, 0 for low level, 1 for high level |
|
52 | + * @n eGPIO7 Bi-directional I/O pin, GPIO7, indicates reading level status of pin GPIO7, 0 for low level, 1 for high level |
|
53 | + * @n eGPIOTotal Bi-directional I/O pin, GPIO group pins GPIO0~GPIO7 indicate reading level status of all GPIO group pins, the returned value bit0~bit8 represents the level of GPIO0~GPIO7 pins respectively |
|
54 | + * @return Level status value |
|
55 | + */ |
|
56 | + uint8_t value = ch423.digitalRead(/*pin = */ch423.eGPIO0); |
|
57 | + if(value){ |
|
58 | + Serial.println("Button press!"); |
|
59 | + delay(200); |
|
60 | + }else{ |
|
61 | + //Serial.println("Button release!"); |
|
62 | + } |
|
63 | + |
|
64 | +} |
|
... | ... | \ No newline at end of file |
Chip-cn-dat/WCH-dat/CH423-dat/ch423-ard-demo-ioInterrupt.ino
... | ... | @@ -0,0 +1,123 @@ |
1 | +/*! |
|
2 | + * @file ioInterrupt.ino |
|
3 | + * @brief This demo is used to demonstrate the detection of rising edge, falling edge or double edge interrupt on the GPIO pin |
|
4 | + * @note When the module is configured as rising edge, falling edge or double edge interrupt, the MCU external interrupt should use falling edge interrupt to reduce errors |
|
5 | + * @n After burning this demo, pin GPO15 of the module needs to be connected to the corresponding external interrupt pin of MCU |
|
6 | + * @n Hardware connection |
|
7 | + * @n --------------------------------------------------------- |
|
8 | + * @n module |UNO |mega2560 |M0 |ESP32 |ESP8266 |microbit | |
|
9 | + * @n VCC |VCC |VCC |VCC |VCC |VCC |VCC | |
|
10 | + * @n GND |GND |GND |GND |GND |GND |GND | |
|
11 | + * @n SCL |SCL |SCL |SCL |SCL |SCL |SCL | |
|
12 | + * @n SDA |SDA |SDA |SDA |SDA |SDA |SDA | |
|
13 | + * @n GPO15 |2/D2 |2/D2 |2 |2 |12 |P9 | |
|
14 | + * @n --------------------------------------------------------- |
|
15 | + * @note If the level of any pin of GPIO0~GPIO7 changes, GPO15 will output a low level signal, and it outputs high level until the levels of GPIO0~GPIO7 pins return to the initial level. |
|
16 | + * @n Leonardo is not supported |
|
17 | + * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) |
|
18 | + * @license The MIT License (MIT) |
|
19 | + * @author [Arya](xue.peng@dfrobot.com) |
|
20 | + * @version V1.0 |
|
21 | + * @date 2022-03-11 |
|
22 | + * @url https://github.com/DFRobot/DFRobot_CH423 |
|
23 | + */ |
|
24 | +#include "DFRobot_CH423.h" |
|
25 | + |
|
26 | +DFRobot_CH423 ch423; |
|
27 | + |
|
28 | +#if defined(ARDUINO_BBC_MICROBIT) |
|
29 | +#define INT_PIN 9 //Connect pin GPO15 of the module to pin 9 of the MCU. For some MCUs, download the codes first and then connect hardware. |
|
30 | +#elif defined(ESP8266) |
|
31 | +#define INT_PIN 12 //Connect pin GPO15 of the module to pin 12 of the MCU. For some MCUs, download the codes first and then connect hardware. |
|
32 | +#else |
|
33 | +#define INT_PIN 2 //Connect pin GPO15 of the module to pin 2 of the MCU. For some MCUs, download the codes first and then connect hardware. |
|
34 | +#endif |
|
35 | + |
|
36 | +bool intFlag = false; //INT interrupt sign |
|
37 | + |
|
38 | +/*Interrupt service function, prototype void func(int index), index: the number of the pin that is interrupted*/ |
|
39 | +void func(int index){ |
|
40 | + String description = ch423.pinDescription(/*pin = */(DFRobot_CH423::eGPIOPin_t)index); |
|
41 | + Serial.print(description); |
|
42 | + Serial.println(" Interruption occurs!"); |
|
43 | +} |
|
44 | + |
|
45 | +void setup() { |
|
46 | + Serial.begin(115200); |
|
47 | + |
|
48 | + while(!Serial){ |
|
49 | + |
|
50 | + } |
|
51 | + ch423.begin(); |
|
52 | + /** |
|
53 | + * @fn pinMode |
|
54 | + * @brief Set the mode of the pin groups, this module contains 2 groups of pins: GPIO(GPIO0~GPIO7) and GPO(GPO0~GPO15). |
|
55 | + * @note This module sets the mode by group, the pins in a group can only be set as one mode at the same time, and the pins in different groups can be set as different modes |
|
56 | + * @param group Pin group parameter, ePinGroup_t enum variable member |
|
57 | + * @n eGPIO Bi-directional I/O pin, GPIO0~GPIO7, which can be set as input(eINPUT) or output(eOUTPUT) mode, setting to other modes is invalid |
|
58 | + * @n eGPO/eGPO0_7/eGPO8_15 The three parameters indicate the same meaning, set the mode of GPO group pins, select the parameter and GPO pins can only be configured as open-drain(eOPEN_DRAIN) or push-pull(ePUSH_PULL) output mode, other modes are invalid |
|
59 | + * @param mode Group pin mode parameter, as member enum variable of eMode_t |
|
60 | + * @n eINPUT GPIO pin input mode, at high level when floating, this mode can only be used for eGPIO digital ports |
|
61 | + * @n eOUTPUT GPIO pin output mode, can output high and low levels, this mode can only be used for eGPIO digital ports |
|
62 | + * @n eOPEN_DRAIN GPO pin open-drain output mode, the GPO pins only output low level or don't output in this mode, it can only be used for eGPO group digital ports |
|
63 | + * @n ePUSH_PULL GPO pin push-pull output mode, the GPO pin can output high or low level in this mode, it can only be used for eGPO digital ports |
|
64 | + */ |
|
65 | + ch423.pinMode(ch423.eGPIO, ch423.eINPUT); |
|
66 | + /** |
|
67 | + * @fn attachInterrupt |
|
68 | + * @brief Set the external interrupt mode and interrupt service function of GPIO pins |
|
69 | + * @note Pin GPO15 of CH423 module is used to indicate whether an interrupt occurs on GPIO0~GPIO7 in interrupt mode, if an interrupt occurs on a pin, GPO15 will output a low level continuously, otherwise it will output a high level. |
|
70 | + * @n When an interrupt occurs on a pin, trigger continuously, if there is interrupt occurring on other pins, level of pin GPO15 keeps low without changing |
|
71 | + * @param gpioPin GPIO group pins, eGPIOPin_t enum variable member |
|
72 | + * @n eGPIO0 Bi-directional I/O pin, GPIO0, indicates setting the external interrupt mode and interrupt service function of pin GPIO0 |
|
73 | + * @n eGPIO1 Bi-directional I/O pin, GPIO1, indicates setting the external interrupt mode and interrupt service function of pin GPIO1 |
|
74 | + * @n eGPIO2 Bi-directional I/O pin, GPIO2, indicates setting the external interrupt mode and interrupt service function of pin GPIO2 |
|
75 | + * @n eGPIO3 Bi-directional I/O pin, GPIO3, indicates setting the external interrupt mode and interrupt service function of pin GPIO3 |
|
76 | + * @n eGPIO4 Bi-directional I/O pin, GPIO4, indicates setting the external interrupt mode and interrupt service function of pin GPIO4 |
|
77 | + * @n eGPIO5 Bi-directional I/O pin, GPIO5, indicates setting the external interrupt mode and interrupt service function of pin GPIO5 |
|
78 | + * @n eGPIO6 Bi-directional I/O pin, GPIO6, indicates setting the external interrupt mode and interrupt service function of pin GPIO6 |
|
79 | + * @n eGPIO7 Bi-directional I/O pin, GPIO7, indicates setting the external interrupt mode and interrupt service function of pin GPIO7 |
|
80 | + * @n eGPIOTotal Set the values of all GPIO group pins, which indicates setting GPIO0~GPIO7 to the same interrupt mode and interrupt service function |
|
81 | + * @param mode Interrupt mode |
|
82 | + * @n eLOW Low level interrupt, initial level of the GPIO pin is high, if the GPIO pin detect a low level, pin GPO15 will output a low level signal |
|
83 | + * @n eHIGH High level interrupt, initial level of the GPIO pin is low, if the GPIO pin detect a high level, pin GPO15 will output a low level signal |
|
84 | + * @n eRISING Rising edge interrupt, initial level of the GPIO pin is low, if the GPIO pin detect a rising edge, pin GPO15 will output a high-to-low level signal (falling edge) |
|
85 | + * @n eFALLING Falling edge interrupt, initial level of the GPIO pin is high, if the GPIO pin detect a falling edge, pin GPO15 will output a high-to-low level signal (falling edge) |
|
86 | + * @n eCHANGE Double edge interrupt, initial level of the GPIO pin is high, and the initial level switches once for each interrupt that occurs. If the GPIO pin detect falling edge or rising edge, pin GPO15 will output a high-to-low level signal (falling edge) |
|
87 | + * @note If the level of any pin of GPIO0-GPIO7 changes, GPO15 will output a low level signal, and it outputs high level until the levels of GPIO0~GPIO7 pins return to the initial level |
|
88 | + * @param cb Point to interrupt service function |
|
89 | + */ |
|
90 | + ch423.attachInterrupt(/* gpioPin= */ch423.eGPIO0, /* mode= */ch423.eFALLING, /* cb= */func); |
|
91 | + ch423.enableInterrupt(); |
|
92 | + /** |
|
93 | + * @brief Enable the external interrupt pin of MCU. |
|
94 | + * @param pin: The external pin of MCU. |
|
95 | + * @n UNO: The external pin is 2, 3, |
|
96 | + * @n Leonardoļ¼ (Not support)The external pin is 0(RX), 1(TX), 2(SCL), 3(SDA), but 0, 1, 2, 3 can't use in this demo |
|
97 | + * @n Mega2560: The external pin is 2, 3, 21, 20, 19, 18. |
|
98 | + * @n microbit: The external pin is 0~20(P0-P20) |
|
99 | + * @n ESP32, ESP8266, M0: The external pin is all digital Pin and analog pin. |
|
100 | + * @param fun: Pointer to guide interrupt service function. |
|
101 | + * @param mode: Interrupt trigger mode. |
|
102 | + * @n UNO/Leonardo/Mega2560: Interrupt Modes: RISING(0x03), FALLING(0x02), CHANGE(0x01), LOW(0x00) |
|
103 | + * @n 8266/esp32: Interrupt Modes: RISING(0x01), FALLING(0x02), CHANGE(0x03), ONLOW(0x04), ONHIGH(0x05), |
|
104 | + * @n M0: Interrupt Modes: RISING(0x04), FALLING(0x03), CHANGE(0x02), HIGH(0x01), LOW(0x00) |
|
105 | + * @n microbit: Interrupt Modes: RISING(0x04), FALLING(0x03), CHANGE(0x02) |
|
106 | + */ |
|
107 | + pinMode(INT_PIN, INPUT_PULLUP); |
|
108 | + attachInterrupt(/*pin=*/digitalPinToInterrupt(INT_PIN),/*fun=*/notify,/*mode =*/FALLING); |
|
109 | + Serial.println("Set done!"); |
|
110 | +} |
|
111 | + |
|
112 | +/*Interrupt service function*/ |
|
113 | +void notify(){ |
|
114 | + intFlag = true; |
|
115 | +} |
|
116 | + |
|
117 | +void loop() { |
|
118 | + if(intFlag){ |
|
119 | + intFlag = false; |
|
120 | + ch423.pollInterrupts(); |
|
121 | + } |
|
122 | + yield(); |
|
123 | +} |
|
... | ... | \ No newline at end of file |
Chip-cn-dat/WCH-dat/CH423-dat/ch423-ard-demo-pollInterrupt.ino
... | ... | @@ -0,0 +1,123 @@ |
1 | +/*! |
|
2 | + * @file ioInterrupt.ino |
|
3 | + * @brief This demo is used to demonstrate the detection of rising edge, falling edge or double edge interrupt on the GPIO pin |
|
4 | + * @note When the module is configured as rising edge, falling edge or double edge interrupt, the MCU external interrupt should use falling edge interrupt to reduce errors |
|
5 | + * @n After burning this demo, pin GPO15 of the module needs to be connected to the corresponding external interrupt pin of MCU |
|
6 | + * @n Hardware connection |
|
7 | + * @n --------------------------------------------------------- |
|
8 | + * @n module |UNO |mega2560 |M0 |ESP32 |ESP8266 |microbit | |
|
9 | + * @n VCC |VCC |VCC |VCC |VCC |VCC |VCC | |
|
10 | + * @n GND |GND |GND |GND |GND |GND |GND | |
|
11 | + * @n SCL |SCL |SCL |SCL |SCL |SCL |SCL | |
|
12 | + * @n SDA |SDA |SDA |SDA |SDA |SDA |SDA | |
|
13 | + * @n GPO15 |2/D2 |2/D2 |2 |2 |12 |P9 | |
|
14 | + * @n --------------------------------------------------------- |
|
15 | + * @note If the level of any pin of GPIO0~GPIO7 changes, GPO15 will output a low level signal, and it outputs high level until the levels of GPIO0~GPIO7 pins return to the initial level. |
|
16 | + * @n Leonardo is not supported |
|
17 | + * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) |
|
18 | + * @license The MIT License (MIT) |
|
19 | + * @author [Arya](xue.peng@dfrobot.com) |
|
20 | + * @version V1.0 |
|
21 | + * @date 2022-03-11 |
|
22 | + * @url https://github.com/DFRobot/DFRobot_CH423 |
|
23 | + */ |
|
24 | +#include "DFRobot_CH423.h" |
|
25 | + |
|
26 | +DFRobot_CH423 ch423; |
|
27 | + |
|
28 | +#if defined(ARDUINO_BBC_MICROBIT) |
|
29 | +#define INT_PIN 9 //Connect pin GPO15 of the module to pin 9 of the MCU. For some MCUs, download the codes first and then connect hardware. |
|
30 | +#elif defined(ESP8266) |
|
31 | +#define INT_PIN 12 //Connect pin GPO15 of the module to pin 12 of the MCU. For some MCUs, download the codes first and then connect hardware. |
|
32 | +#else |
|
33 | +#define INT_PIN 2 //Connect pin GPO15 of the module to pin 2 of the MCU. For some MCUs, download the codes first and then connect hardware. |
|
34 | +#endif |
|
35 | + |
|
36 | +bool intFlag = false; //INT interrupt sign |
|
37 | + |
|
38 | +/*Interrupt service function, prototype void func(int index), index: the number of the pin that is interrupted*/ |
|
39 | +void func(int index){ |
|
40 | + String description = ch423.pinDescription(/*pin = */(DFRobot_CH423::eGPIOPin_t)index); |
|
41 | + Serial.print(description); |
|
42 | + Serial.println(" Interruption occurs!"); |
|
43 | +} |
|
44 | + |
|
45 | +void setup() { |
|
46 | + Serial.begin(115200); |
|
47 | + |
|
48 | + while(!Serial){ |
|
49 | + |
|
50 | + } |
|
51 | + ch423.begin(); |
|
52 | + /** |
|
53 | + * @fn pinMode |
|
54 | + * @brief Set the mode of the pin groups, this module contains 2 groups of pins: GPIO(GPIO0~GPIO7) and GPO(GPO0~GPO15). |
|
55 | + * @note This module sets the mode by group, the pins in a group can only be set as one mode at the same time, and the pins in different groups can be set as different modes |
|
56 | + * @param group Pin group parameter, ePinGroup_t enum variable member |
|
57 | + * @n eGPIO Bi-directional I/O pin, GPIO0~GPIO7, which can be set as input(eINPUT) or output(eOUTPUT) mode, setting to other modes is invalid |
|
58 | + * @n eGPO/eGPO0_7/eGPO8_15 The three parameters indicate the same meaning, set the mode of GPO group pins, select the parameter and GPO pins can only be configured as open-drain(eOPEN_DRAIN) or push-pull(ePUSH_PULL) output mode, other modes are invalid |
|
59 | + * @param mode Group pin mode parameter, as member enum variable of eMode_t |
|
60 | + * @n eINPUT GPIO pin input mode, at high level when floating, this mode can only be used for eGPIO digital ports |
|
61 | + * @n eOUTPUT GPIO pin output mode, can output high and low levels, this mode can only be used for eGPIO digital ports |
|
62 | + * @n eOPEN_DRAIN GPO pin open-drain output mode, the GPO pins only output low level or don't output in this mode, it can only be used for eGPO group digital ports |
|
63 | + * @n ePUSH_PULL GPO pin push-pull output mode, the GPO pin can output high or low level in this mode, it can only be used for eGPO digital ports |
|
64 | + */ |
|
65 | + ch423.pinMode(ch423.eGPIO, ch423.eINPUT); |
|
66 | + /** |
|
67 | + * @fn attachInterrupt |
|
68 | + * @brief Set the external interrupt mode and interrupt service function of GPIO pins |
|
69 | + * @note Pin GPO15 of CH423 module is used to indicate whether an interrupt occurs on GPIO0~GPIO7 in interrupt mode, if an interrupt occurs on a pin, GPO15 will output a low level continuously, otherwise it will output a high level. |
|
70 | + * @n When an interrupt occurs on a pin, trigger continuously, if there is interrupt occurring on other pins, level of pin GPO15 keeps low without changing |
|
71 | + * @param gpioPin GPIO group pins, eGPIOPin_t enum variable member |
|
72 | + * @n eGPIO0 Bi-directional I/O pin, GPIO0, indicates setting the external interrupt mode and interrupt service function of pin GPIO0 |
|
73 | + * @n eGPIO1 Bi-directional I/O pin, GPIO1, indicates setting the external interrupt mode and interrupt service function of pin GPIO1 |
|
74 | + * @n eGPIO2 Bi-directional I/O pin, GPIO2, indicates setting the external interrupt mode and interrupt service function of pin GPIO2 |
|
75 | + * @n eGPIO3 Bi-directional I/O pin, GPIO3, indicates setting the external interrupt mode and interrupt service function of pin GPIO3 |
|
76 | + * @n eGPIO4 Bi-directional I/O pin, GPIO4, indicates setting the external interrupt mode and interrupt service function of pin GPIO4 |
|
77 | + * @n eGPIO5 Bi-directional I/O pin, GPIO5, indicates setting the external interrupt mode and interrupt service function of pin GPIO5 |
|
78 | + * @n eGPIO6 Bi-directional I/O pin, GPIO6, indicates setting the external interrupt mode and interrupt service function of pin GPIO6 |
|
79 | + * @n eGPIO7 Bi-directional I/O pin, GPIO7, indicates setting the external interrupt mode and interrupt service function of pin GPIO7 |
|
80 | + * @n eGPIOTotal Set the values of all GPIO group pins, which indicates setting GPIO0~GPIO7 to the same interrupt mode and interrupt service function |
|
81 | + * @param mode Interrupt mode |
|
82 | + * @n eLOW Low level interrupt, initial level of the GPIO pin is high, if the GPIO pin detect a low level, pin GPO15 will output a low level signal |
|
83 | + * @n eHIGH High level interrupt, initial level of the GPIO pin is low, if the GPIO pin detect a high level, pin GPO15 will output a low level signal |
|
84 | + * @n eRISING Rising edge interrupt, initial level of the GPIO pin is low, if the GPIO pin detect a rising edge, pin GPO15 will output a high-to-low level signal (falling edge) |
|
85 | + * @n eFALLING Falling edge interrupt, initial level of the GPIO pin is high, if the GPIO pin detect a falling edge, pin GPO15 will output a high-to-low level signal (falling edge) |
|
86 | + * @n eCHANGE Double edge interrupt, initial level of the GPIO pin is high, and the initial level switches once for each interrupt that occurs. If the GPIO pin detect falling edge or rising edge, pin GPO15 will output a high-to-low level signal (falling edge) |
|
87 | + * @note If the level of any pin of GPIO0-GPIO7 changes, GPO15 will output a low level signal, and it outputs high level until the levels of GPIO0~GPIO7 pins return to the initial level |
|
88 | + * @param cb Point to interrupt service function |
|
89 | + */ |
|
90 | + ch423.attachInterrupt(/* gpioPin= */ch423.eGPIO0, /* mode= */ch423.eFALLING, /* cb= */func); |
|
91 | + ch423.enableInterrupt(); |
|
92 | + /** |
|
93 | + * @brief Enable the external interrupt pin of MCU. |
|
94 | + * @param pin: The external pin of MCU. |
|
95 | + * @n UNO: The external pin is 2, 3, |
|
96 | + * @n Leonardoļ¼ (Not support)The external pin is 0(RX), 1(TX), 2(SCL), 3(SDA), but 0, 1, 2, 3 can't use in this demo |
|
97 | + * @n Mega2560: The external pin is 2, 3, 21, 20, 19, 18. |
|
98 | + * @n microbit: The external pin is 0~20(P0-P20) |
|
99 | + * @n ESP32, ESP8266, M0: The external pin is all digital Pin and analog pin. |
|
100 | + * @param fun: Pointer to guide interrupt service function. |
|
101 | + * @param mode: Interrupt trigger mode. |
|
102 | + * @n UNO/Leonardo/Mega2560: Interrupt Modes: RISING(0x03), FALLING(0x02), CHANGE(0x01), LOW(0x00) |
|
103 | + * @n 8266/esp32: Interrupt Modes: RISING(0x01), FALLING(0x02), CHANGE(0x03), ONLOW(0x04), ONHIGH(0x05), |
|
104 | + * @n M0: Interrupt Modes: RISING(0x04), FALLING(0x03), CHANGE(0x02), HIGH(0x01), LOW(0x00) |
|
105 | + * @n microbit: Interrupt Modes: RISING(0x04), FALLING(0x03), CHANGE(0x02) |
|
106 | + */ |
|
107 | + pinMode(INT_PIN, INPUT_PULLUP); |
|
108 | + attachInterrupt(/*pin=*/digitalPinToInterrupt(INT_PIN),/*fun=*/notify,/*mode =*/FALLING); |
|
109 | + Serial.println("Set done!"); |
|
110 | +} |
|
111 | + |
|
112 | +/*Interrupt service function*/ |
|
113 | +void notify(){ |
|
114 | + intFlag = true; |
|
115 | +} |
|
116 | + |
|
117 | +void loop() { |
|
118 | + if(intFlag){ |
|
119 | + intFlag = false; |
|
120 | + ch423.pollInterrupts(); |
|
121 | + } |
|
122 | + yield(); |
|
123 | +} |
|
... | ... | \ No newline at end of file |
Chip-cn-dat/WCH-dat/CH423-dat/ch423-ard-demo-sleep.ino
... | ... | @@ -0,0 +1,123 @@ |
1 | +/*! |
|
2 | + * @file ioInterrupt.ino |
|
3 | + * @brief This demo is used to demonstrate the detection of rising edge, falling edge or double edge interrupt on the GPIO pin |
|
4 | + * @note When the module is configured as rising edge, falling edge or double edge interrupt, the MCU external interrupt should use falling edge interrupt to reduce errors |
|
5 | + * @n After burning this demo, pin GPO15 of the module needs to be connected to the corresponding external interrupt pin of MCU |
|
6 | + * @n Hardware connection |
|
7 | + * @n --------------------------------------------------------- |
|
8 | + * @n module |UNO |mega2560 |M0 |ESP32 |ESP8266 |microbit | |
|
9 | + * @n VCC |VCC |VCC |VCC |VCC |VCC |VCC | |
|
10 | + * @n GND |GND |GND |GND |GND |GND |GND | |
|
11 | + * @n SCL |SCL |SCL |SCL |SCL |SCL |SCL | |
|
12 | + * @n SDA |SDA |SDA |SDA |SDA |SDA |SDA | |
|
13 | + * @n GPO15 |2/D2 |2/D2 |2 |2 |12 |P9 | |
|
14 | + * @n --------------------------------------------------------- |
|
15 | + * @note If the level of any pin of GPIO0~GPIO7 changes, GPO15 will output a low level signal, and it outputs high level until the levels of GPIO0~GPIO7 pins return to the initial level. |
|
16 | + * @n Leonardo is not supported |
|
17 | + * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) |
|
18 | + * @license The MIT License (MIT) |
|
19 | + * @author [Arya](xue.peng@dfrobot.com) |
|
20 | + * @version V1.0 |
|
21 | + * @date 2022-03-11 |
|
22 | + * @url https://github.com/DFRobot/DFRobot_CH423 |
|
23 | + */ |
|
24 | +#include "DFRobot_CH423.h" |
|
25 | + |
|
26 | +DFRobot_CH423 ch423; |
|
27 | + |
|
28 | +#if defined(ARDUINO_BBC_MICROBIT) |
|
29 | +#define INT_PIN 9 //Connect pin GPO15 of the module to pin 9 of the MCU. For some MCUs, download the codes first and then connect hardware. |
|
30 | +#elif defined(ESP8266) |
|
31 | +#define INT_PIN 12 //Connect pin GPO15 of the module to pin 12 of the MCU. For some MCUs, download the codes first and then connect hardware. |
|
32 | +#else |
|
33 | +#define INT_PIN 2 //Connect pin GPO15 of the module to pin 2 of the MCU. For some MCUs, download the codes first and then connect hardware. |
|
34 | +#endif |
|
35 | + |
|
36 | +bool intFlag = false; //INT interrupt sign |
|
37 | + |
|
38 | +/*Interrupt service function, prototype void func(int index), index: the number of the pin that is interrupted*/ |
|
39 | +void func(int index){ |
|
40 | + String description = ch423.pinDescription(/*pin = */(DFRobot_CH423::eGPIOPin_t)index); |
|
41 | + Serial.print(description); |
|
42 | + Serial.println(" Interruption occurs!"); |
|
43 | +} |
|
44 | + |
|
45 | +void setup() { |
|
46 | + Serial.begin(115200); |
|
47 | + |
|
48 | + while(!Serial){ |
|
49 | + |
|
50 | + } |
|
51 | + ch423.begin(); |
|
52 | + /** |
|
53 | + * @fn pinMode |
|
54 | + * @brief Set the mode of the pin groups, this module contains 2 groups of pins: GPIO(GPIO0~GPIO7) and GPO(GPO0~GPO15). |
|
55 | + * @note This module sets the mode by group, the pins in a group can only be set as one mode at the same time, and the pins in different groups can be set as different modes |
|
56 | + * @param group Pin group parameter, ePinGroup_t enum variable member |
|
57 | + * @n eGPIO Bi-directional I/O pin, GPIO0~GPIO7, which can be set as input(eINPUT) or output(eOUTPUT) mode, setting to other modes is invalid |
|
58 | + * @n eGPO/eGPO0_7/eGPO8_15 The three parameters indicate the same meaning, set the mode of GPO group pins, select the parameter and GPO pins can only be configured as open-drain(eOPEN_DRAIN) or push-pull(ePUSH_PULL) output mode, other modes are invalid |
|
59 | + * @param mode Group pin mode parameter, as member enum variable of eMode_t |
|
60 | + * @n eINPUT GPIO pin input mode, at high level when floating, this mode can only be used for eGPIO digital ports |
|
61 | + * @n eOUTPUT GPIO pin output mode, can output high and low levels, this mode can only be used for eGPIO digital ports |
|
62 | + * @n eOPEN_DRAIN GPO pin open-drain output mode, the GPO pins only output low level or don't output in this mode, it can only be used for eGPO group digital ports |
|
63 | + * @n ePUSH_PULL GPO pin push-pull output mode, the GPO pin can output high or low level in this mode, it can only be used for eGPO digital ports |
|
64 | + */ |
|
65 | + ch423.pinMode(ch423.eGPIO, ch423.eINPUT); |
|
66 | + /** |
|
67 | + * @fn attachInterrupt |
|
68 | + * @brief Set the external interrupt mode and interrupt service function of GPIO pins |
|
69 | + * @note Pin GPO15 of CH423 module is used to indicate whether an interrupt occurs on GPIO0~GPIO7 in interrupt mode, if an interrupt occurs on a pin, GPO15 will output a low level continuously, otherwise it will output a high level. |
|
70 | + * @n When an interrupt occurs on a pin, trigger continuously, if there is interrupt occurring on other pins, level of pin GPO15 keeps low without changing |
|
71 | + * @param gpioPin GPIO group pins, eGPIOPin_t enum variable member |
|
72 | + * @n eGPIO0 Bi-directional I/O pin, GPIO0, indicates setting the external interrupt mode and interrupt service function of pin GPIO0 |
|
73 | + * @n eGPIO1 Bi-directional I/O pin, GPIO1, indicates setting the external interrupt mode and interrupt service function of pin GPIO1 |
|
74 | + * @n eGPIO2 Bi-directional I/O pin, GPIO2, indicates setting the external interrupt mode and interrupt service function of pin GPIO2 |
|
75 | + * @n eGPIO3 Bi-directional I/O pin, GPIO3, indicates setting the external interrupt mode and interrupt service function of pin GPIO3 |
|
76 | + * @n eGPIO4 Bi-directional I/O pin, GPIO4, indicates setting the external interrupt mode and interrupt service function of pin GPIO4 |
|
77 | + * @n eGPIO5 Bi-directional I/O pin, GPIO5, indicates setting the external interrupt mode and interrupt service function of pin GPIO5 |
|
78 | + * @n eGPIO6 Bi-directional I/O pin, GPIO6, indicates setting the external interrupt mode and interrupt service function of pin GPIO6 |
|
79 | + * @n eGPIO7 Bi-directional I/O pin, GPIO7, indicates setting the external interrupt mode and interrupt service function of pin GPIO7 |
|
80 | + * @n eGPIOTotal Set the values of all GPIO group pins, which indicates setting GPIO0~GPIO7 to the same interrupt mode and interrupt service function |
|
81 | + * @param mode Interrupt mode |
|
82 | + * @n eLOW Low level interrupt, initial level of the GPIO pin is high, if the GPIO pin detect a low level, pin GPO15 will output a low level signal |
|
83 | + * @n eHIGH High level interrupt, initial level of the GPIO pin is low, if the GPIO pin detect a high level, pin GPO15 will output a low level signal |
|
84 | + * @n eRISING Rising edge interrupt, initial level of the GPIO pin is low, if the GPIO pin detect a rising edge, pin GPO15 will output a high-to-low level signal (falling edge) |
|
85 | + * @n eFALLING Falling edge interrupt, initial level of the GPIO pin is high, if the GPIO pin detect a falling edge, pin GPO15 will output a high-to-low level signal (falling edge) |
|
86 | + * @n eCHANGE Double edge interrupt, initial level of the GPIO pin is high, and the initial level switches once for each interrupt that occurs. If the GPIO pin detect falling edge or rising edge, pin GPO15 will output a high-to-low level signal (falling edge) |
|
87 | + * @note If the level of any pin of GPIO0-GPIO7 changes, GPO15 will output a low level signal, and it outputs high level until the levels of GPIO0~GPIO7 pins return to the initial level |
|
88 | + * @param cb Point to interrupt service function |
|
89 | + */ |
|
90 | + ch423.attachInterrupt(/* gpioPin= */ch423.eGPIO0, /* mode= */ch423.eFALLING, /* cb= */func); |
|
91 | + ch423.enableInterrupt(); |
|
92 | + /** |
|
93 | + * @brief Enable the external interrupt pin of MCU. |
|
94 | + * @param pin: The external pin of MCU. |
|
95 | + * @n UNO: The external pin is 2, 3, |
|
96 | + * @n Leonardoļ¼ (Not support)The external pin is 0(RX), 1(TX), 2(SCL), 3(SDA), but 0, 1, 2, 3 can't use in this demo |
|
97 | + * @n Mega2560: The external pin is 2, 3, 21, 20, 19, 18. |
|
98 | + * @n microbit: The external pin is 0~20(P0-P20) |
|
99 | + * @n ESP32, ESP8266, M0: The external pin is all digital Pin and analog pin. |
|
100 | + * @param fun: Pointer to guide interrupt service function. |
|
101 | + * @param mode: Interrupt trigger mode. |
|
102 | + * @n UNO/Leonardo/Mega2560: Interrupt Modes: RISING(0x03), FALLING(0x02), CHANGE(0x01), LOW(0x00) |
|
103 | + * @n 8266/esp32: Interrupt Modes: RISING(0x01), FALLING(0x02), CHANGE(0x03), ONLOW(0x04), ONHIGH(0x05), |
|
104 | + * @n M0: Interrupt Modes: RISING(0x04), FALLING(0x03), CHANGE(0x02), HIGH(0x01), LOW(0x00) |
|
105 | + * @n microbit: Interrupt Modes: RISING(0x04), FALLING(0x03), CHANGE(0x02) |
|
106 | + */ |
|
107 | + pinMode(INT_PIN, INPUT_PULLUP); |
|
108 | + attachInterrupt(/*pin=*/digitalPinToInterrupt(INT_PIN),/*fun=*/notify,/*mode =*/FALLING); |
|
109 | + Serial.println("Set done!"); |
|
110 | +} |
|
111 | + |
|
112 | +/*Interrupt service function*/ |
|
113 | +void notify(){ |
|
114 | + intFlag = true; |
|
115 | +} |
|
116 | + |
|
117 | +void loop() { |
|
118 | + if(intFlag){ |
|
119 | + intFlag = false; |
|
120 | + ch423.pollInterrupts(); |
|
121 | + } |
|
122 | + yield(); |
|
123 | +} |
|
... | ... | \ No newline at end of file |
Chip-cn-dat/WCH-dat/CH423-dat/ch423-ard-demo-waterLamp.ino
... | ... | @@ -0,0 +1,90 @@ |
1 | +/*! |
|
2 | + * @file waterLamp.ino |
|
3 | + * @brief This demo is used to make RGB LED realize the effect of the water flowing effect |
|
4 | + * @note 8 LEDs need to be connected to GPIO group pins, GPO0~7 group pins, or GPO8~15 group pins, you can switch GROUP_FLAG to achieve the effect of connecting to the IO port of different groups |
|
5 | + * |
|
6 | + * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) |
|
7 | + * @license The MIT License (MIT) |
|
8 | + * @author [Arya](xue.peng@dfrobot.com) |
|
9 | + * @version V1.0 |
|
10 | + * @date 2022-03-11 |
|
11 | + * @url https://github.com/DFRobot/DFRobot_CH423 |
|
12 | + */ |
|
13 | +#include "DFRobot_CH423.h" |
|
14 | + |
|
15 | +#define GROUP_GPIO 0 |
|
16 | +#define GROUP_GPO0_7 1 |
|
17 | +#define GROUP_GPO8_15 2 |
|
18 | + |
|
19 | +//Control macro GROUP_FLAG to realize the connecting of the LED to the pin group of the module |
|
20 | +#define GROUP_FLAG GROUP_GPIO |
|
21 | +//#define GROUP_FLAG GROUP_GPO0_7 |
|
22 | +//#define GROUP_FLAG GROUP_GPO8_15 |
|
23 | + |
|
24 | +DFRobot_CH423 ch423; |
|
25 | + |
|
26 | +void setup() { |
|
27 | + Serial.begin(115200); |
|
28 | + |
|
29 | + while(!Serial){ |
|
30 | + |
|
31 | + } |
|
32 | + ch423.begin(); |
|
33 | + /** |
|
34 | + * @fn pinMode |
|
35 | + * @brief Set the mode of the pin groups, this module contains 2 groups of pins: GPIO(GPIO0~GPIO7) and GPO(GPO0~GPO15). |
|
36 | + * @note This module sets the mode by group, the pins in a group can only be set as one mode at the same time, and the pins in different groups can be set as different modes |
|
37 | + * @param group Pin group parameter, ePinGroup_t enum variable member |
|
38 | + * @n eGPIO Bi-directional I/O pins, GPIO0~GPIO7, which can be set as input(eINPUT) or output(eOUTPUT) mode, invalid when set to other modes |
|
39 | + * @n eGPO/eGPO0_7/eGPO8_15 The three parameters indicate the same meaning, set the mode of GPO group pins, select the parameter and GPO pins can only be configured as open-drain(eOPEN_DRAIN) or push-pull(ePUSH_PULL) output mode, other modes are invalid |
|
40 | + * @param mode Group pin mode parameter, as member enum variable of eMode_t |
|
41 | + * @n eINPUT GPIO pin input mode, at high level when floating, this mode can only be used for eGPIO digital ports |
|
42 | + * @n eOUTPUT GPIO pin output mode, can output high and low levels, this mode can only be used for eGPIO digital ports |
|
43 | + * @n eOPEN_DRAIN GPO pin open-drain output mode, the GPO pins only output low level or don't output in this mode, it can only be used for eGPO group digital ports |
|
44 | + * @n ePUSH_PULL GPO pin push-pull output mode, the GPO pin can output high or low level in this mode, it can only be used for eGPO digital ports |
|
45 | + */ |
|
46 | +#if (GROUP_FLAG == GROUP_GPIO) |
|
47 | + ch423.pinMode(ch423.eGPIO, ch423.eOUTPUT); |
|
48 | +#else |
|
49 | + ch423.pinMode(ch423.eGPO, ch423.ePUSH_PULL); |
|
50 | +#endif |
|
51 | +} |
|
52 | + |
|
53 | +void loop() { |
|
54 | +#if (GROUP_FLAG == GROUP_GPIO) |
|
55 | + |
|
56 | + DFRobot_CH423::eGPIOPin_t gpioBuf[]= {ch423.eGPIO0, ch423.eGPIO1, ch423.eGPIO2, ch423.eGPIO3, ch423.eGPIO4, ch423.eGPIO5, ch423.eGPIO6, ch423.eGPIO7}; |
|
57 | + int on = 0, off; |
|
58 | + ch423.digitalWrite(gpioBuf[on], HIGH); |
|
59 | + for(on = 1, off = 0; on < sizeof(gpioBuf)/sizeof(DFRobot_CH423::eGPIOPin_t); on++, off++){ |
|
60 | + ch423.digitalWrite(gpioBuf[on], HIGH); |
|
61 | + ch423.digitalWrite(gpioBuf[off], LOW); |
|
62 | + delay(200); |
|
63 | + } |
|
64 | + ch423.digitalWrite(gpioBuf[off], LOW); |
|
65 | + |
|
66 | +#elif (GROUP_FLAG == GROUP_GPO0_7) |
|
67 | + DFRobot_CH423::eGPOPin_t gpoBuf[]= {ch423.eGPO0, ch423.eGPO1, ch423.eGPO2, ch423.eGPO3, ch423.eGPO4, ch423.eGPO5, ch423.eGPO6, ch423.eGPO7}; |
|
68 | + int on = 0, off; |
|
69 | + ch423.digitalWrite(gpoBuf[on], HIGH); |
|
70 | + for(on = 1, off = 0; on < sizeof(gpoBuf)/sizeof(DFRobot_CH423::eGPOPin_t); on++, off++){ |
|
71 | + ch423.digitalWrite(gpoBuf[on], HIGH); |
|
72 | + ch423.digitalWrite(gpoBuf[off], LOW); |
|
73 | + delay(200); |
|
74 | + } |
|
75 | + ch423.digitalWrite(gpoBuf[off], LOW); |
|
76 | +#else |
|
77 | + DFRobot_CH423::eGPOPin_t gpoBuf[]= {ch423.eGPO8, ch423.eGPO9, ch423.eGPO10, ch423.eGPO11, ch423.eGPO12, ch423.eGPO13, ch423.eGPO14, ch423.eGPO15}; |
|
78 | + int on = 0, off; |
|
79 | + ch423.digitalWrite(gpoBuf[on], HIGH); |
|
80 | + for(on = 1, off = 0; on < sizeof(gpoBuf)/sizeof(DFRobot_CH423::eGPOPin_t); on++, off++){ |
|
81 | + ch423.digitalWrite(gpoBuf[on], HIGH); |
|
82 | + ch423.digitalWrite(gpoBuf[off], LOW); |
|
83 | + delay(200); |
|
84 | + } |
|
85 | + ch423.digitalWrite(gpoBuf[off], LOW); |
|
86 | +#endif |
|
87 | + delay(200); |
|
88 | +} |
|
89 | + |
|
90 | + |
Chip-cn-dat/WCH-dat/CH432-dat/CH432DS1.PDF
... | ... | Binary files /dev/null and b/Chip-cn-dat/WCH-dat/CH432-dat/CH432DS1.PDF differ |