{"id":141,"date":"2025-08-06T15:50:11","date_gmt":"2025-08-06T07:50:11","guid":{"rendered":"https:\/\/www.taotao01.fun\/?p=141"},"modified":"2025-08-06T15:50:11","modified_gmt":"2025-08-06T07:50:11","slug":"stm32-study-note","status":"publish","type":"post","link":"https:\/\/www.taotao01.fun\/wordpress\/index.php\/2025\/08\/06\/stm32-study-note\/","title":{"rendered":"STM32 Study Note"},"content":{"rendered":"\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u5c42\u7ea7<\/th><th>\u65b9\u5f0f<\/th><th>\u793a\u4f8b<\/th><th>\u96be\u5ea6<\/th><th>\u9002\u5408\u4eba\u7fa4<\/th><\/tr><\/thead><tbody><tr><td>\u9ad8\u7ea7<\/td><td>HAL \u5e93\uff08CubeMX \u9ed8\u8ba4\uff09<\/td><td><code>HAL_GPIO_WritePin()<\/code><\/td><td>\u2b50<\/td><td>\u65b0\u624b\u5165\u95e8<\/td><\/tr><tr><td>\u4e2d\u7ea7<\/td><td>LL \u5e93\uff08Low Layer\uff09<\/td><td><code>LL_GPIO_SetOutputPin()<\/code><\/td><td>\u2b50\u2b50<\/td><td>\u8fdb\u9636\u8005<\/td><\/tr><tr><td>\u5e95\u5c42<\/td><td>\u76f4\u63a5\u5bc4\u5b58\u5668<\/td><td>`GPIOA-&gt;ODR<\/td><td>= (1 &lt;&lt; 5);`<\/td><td>\u2b50\u2b50\u2b50<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u540d\u79f0<\/th><th>\u542b\u4e49<\/th><\/tr><\/thead><tbody><tr><td><code>GPIOA<\/code><\/td><td>\u4ee3\u8868 GPIOA \u7aef\u53e3<\/td><\/tr><tr><td><code>ODR<\/code><\/td><td>Output Data Register\uff0c\u8f93\u51fa\u6570\u636e\u5bc4\u5b58\u5668<\/td><\/tr><tr><td><code>1 &lt;&lt; 5<\/code><\/td><td>\u628a\u7b2c 5 \u4f4d\uff08PA5\uff09\u7f6e 1<\/td><\/tr><tr><td>`<\/td><td>=`<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>HAL_Init();\nSystemClock_Config();   \/\/ \u5df2\u7531 CubeMX \u81ea\u52a8\u751f\u6210 72MHz \u914d\u7f6e\nMX_GPIO_Init();\nwhile (1)\n{\n  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET);   \/\/ \u8bbe\u7f6e\u9ad8\u7535\u5e73\n  HAL_Delay(500);\n  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET); \/\/ \u8bbe\u7f6e\u4f4e\u7535\u5e73\n  HAL_Delay(500);\n}<\/code><\/pre>\n\n\n\n<p>GPIO \u521d\u59cb\u5316MX_GPIO_Init()<\/p>\n\n\n\n<p>\u7cfb\u7edf\u65f6\u949fSystemClock_Config()<\/p>\n\n\n\n<p>CubeMX \u4e2d\u914d\u7f6e\u5916\u90e8\u65f6\u949f + GPIO \u6b65\u9aa4<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/www.taotao01.fun\/wordpress\/wp-content\/uploads\/2025\/08\/image-2.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" class=\"wp-image-145\"\/><\/figure >\n<noscript><img decoding=\"async\" src=\"https:\/\/www.taotao01.fun\/wordpress\/wp-content\/uploads\/2025\/08\/image-2.png\" alt=\"\" class=\"wp-image-145\"\/><\/figure><\/noscript>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u9879\u76ee<\/th><th>\u5f53\u524d\u8bbe\u7f6e\u503c<\/th><th>\u542b\u4e49 &amp; \u4f5c\u7528<\/th><\/tr><\/thead><tbody><tr><td><strong>GPIO output level<\/strong><\/td><td>High<\/td><td>\u521d\u59cb\u5316\u65f6\u7684\u9ed8\u8ba4\u8f93\u51fa\u7535\u5e73,\u4e0a\u7535\u65f6\u9ed8\u8ba4\u8f93\u51fa\u9ad8\u7535\u5e73\uff08VDD\uff09<\/td><\/tr><tr><td><strong>GPIO mode<\/strong><\/td><td>Output Push Pull<\/td><td>\u8f93\u51fa\u63a8\u633d\u6a21\u5f0f\uff08\u6807\u51c6\u8f93\u51fa\uff09\u2705<\/td><\/tr><tr><td><strong>GPIO Pull-up\/Pull-down<\/strong><\/td><td>Pull-up<\/td><td><strong>\u5185\u90e8\u4e0a\u62c9\u7535\u963b<\/strong>\u4f7f\u5f15\u811a\u5728\u60ac\u7a7a\u65f6\u4e3a\u9ad8\u7535\u5e73\uff08\u5bf9\u8f93\u51fa\u53e3\u5176\u5b9e\u4e0d\u8d77\u4f5c\u7528\uff09<\/td><\/tr><tr><td><strong>Maximum output speed<\/strong><\/td><td>Medium<\/td><td>GPIO \u5207\u6362\u901f\u5ea6\u4e3a\u4e2d\u7b49\uff0810 MHz \u5de6\u53f3\uff09<\/td><\/tr><tr><td><strong>User Label<\/strong><\/td><td>LED<\/td><td>\u7ed9\u8fd9\u4e2a\u5f15\u811a\u8bbe\u7f6e\u6807\u7b7e\uff08\u53ef\u8bfb\u6027\u63d0\u5347\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b98\u65b9\u5b9a\u4e49\u8bf4\u660e\uff08STM32 HAL \u4e2d\uff09\uff1a<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>#define GPIO_PIN_0                 ((uint16_t)0x0001)  \/\/ 1 &lt;&lt; 0<br>#define GPIO_PIN_1                 ((uint16_t)0x0002)  \/\/ 1 &lt;&lt; 1<br>...<br>#define GPIO_PIN_15                ((uint16_t)0x8000)  \/\/ 1 &lt;&lt; 15<\/code><\/pre>\n\n\n\n<p>\u6ce8\u610f\u8fd9\u4e9b\u5b8f\u662f <code>uint16_t<\/code> \u7c7b\u578b\uff0c\u6240\u4ee5\u6700\u591a\u53ea\u80fd\u8868\u8fbe 16 \u4f4d\uff08\u5373 PIN_0~15\uff09\u3002<\/p>\n\n\n\n<p><code>GPIOA-&gt;ODR |= (1 &lt;&lt; pin)<\/code> \u7f6e\u9ad8\uff0c\u6216 <code>GPIOA-&gt;ODR &amp;= ~(1 &lt;&lt; pin)<\/code> \u7f6e\u4f4e<\/p>\n\n\n\n<p>| 31 \u2026 16 | 15 \u2026 0 |<br>| \u590d\u4f4d\u4f4d Reset Bits | \u8bbe\u7f6e\u4f4d Set Bits |<br>\u4f4e 16 \u4f4d\uff080~15 bit\uff09\uff1a\u5c06\u5bf9\u5e94\u5f15\u811a \u7f6e\u9ad8\u7535\u5e73\uff08\u5199 1 \u6709\u6548\uff09<\/p>\n\n\n\n<p>\u9ad8 16 \u4f4d\uff0816~31 bit\uff09\uff1a\u5c06\u5bf9\u5e94\u5f15\u811a \u7f6e\u4f4e\u7535\u5e73\uff08\u5199 1 \u6709\u6548\uff09<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u64cd\u4f5c<\/th><th>\u5199\u5165\u503c<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td>\u8bbe\u7f6e PA5 \u4e3a\u9ad8\u7535\u5e73<\/td><td><code>GPIOA-&gt;BSRR = (1&lt;&lt;5)<\/code><\/td><td>\u4f4e 16 \u4f4d Bit5 \u5199 1<\/td><\/tr><tr><td>\u8bbe\u7f6e PA5 \u4e3a\u4f4e\u7535\u5e73<\/td><td><code>GPIOA-&gt;BSRR = (1&lt;&lt;21)<\/code><\/td><td>\u9ad8 16 \u4f4d Bit5 \u5199 1\uff085+16\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code><code>GPIOx-&gt;BSRR = GPIO_PIN_0;  \/\/ \u7f6e GPIOx \u7684\u7b2c 0 \u5f15\u811a\u4e3a\u9ad8\u7535\u5e73\nGPIOx-&gt;BSRR = (uint32_t)GPIO_Pin &lt;&lt; 16u;<\/code><\/code><\/pre>\n\n\n\n<p><code>ODR<\/code> \u4fee\u6539\u9700\u8981 <strong>\u8bfb \u2192 \u6539 \u2192 \u5199<\/strong>\uff0c\u4e2d\u65ad\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u6253\u65ad\u5199\u5165\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p><code>BSRR<\/code> \u5199\u5165\u662f <strong>\u4e00\u6b21\u5b8c\u6210\u3001\u539f\u5b50\u64cd\u4f5c<\/strong>\uff0c\u4e0d\u4f1a\u5f71\u54cd\u5176\u4ed6\u5f15\u811a\uff0c\u9002\u5408\u9ad8\u5b9e\u65f6\u573a\u666f\uff08\u5982\u4e2d\u65ad\u3001RTOS\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>while (1)\n{\n    GPIOA-&gt;BSRR = (1 &lt;&lt; 5);           \/\/ PA5 = \u9ad8\n    HAL_Delay(500);                   \/\/ \u5ef6\u65f6 500ms\n    GPIOA-&gt;BSRR = (1 &lt;&lt; (5 + 16));    \/\/ PA5 = \u4f4e\n    HAL_Delay(500);                   \/\/ \u5ef6\u65f6 500ms\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>for i in range(16):\n    led_high = 1 &lt;&lt; i\n    led_low  = 1 &lt;&lt; (i + 16)\n    print(f\"GPIO_PIN_{i:&gt;2}:  SET=0x{led_high:08X}  RESET=0x{led_low:08X}\")\n<\/code><\/pre>\n\n\n\n<p>Drivers\/STM32F1xx_HAL_Driver\/Inc\/stm32f1xx_hal_gpio.h<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>| \u5b8f\u5b9a\u4e49\u540d                          | \u8bf4\u660e                |\n| ----------------------------- | ----------------- |\n| `GPIO_MODE_INPUT`             | \u8f93\u5165\u6a21\u5f0f\uff08\u9ed8\u8ba4\u60ac\u6d6e\uff09        |\n| `GPIO_MODE_OUTPUT_PP`         | \u63a8\u633d\u8f93\u51fa\uff08\u80fd\u4e3b\u52a8\u62c9\u9ad8+\u62c9\u4f4e\uff09    |\n| `GPIO_MODE_OUTPUT_OD`         | \u5f00\u6f0f\u8f93\u51fa\uff08\u53ea\u80fd\u62c9\u4f4e\uff09        |\n| `GPIO_MODE_AF_PP`             | \u63a8\u633d\u590d\u7528\u529f\u80fd\uff08\u5982 UART TX\uff09 |\n| `GPIO_MODE_AF_OD`             | \u5f00\u6f0f\u590d\u7528\u529f\u80fd\uff08\u5982 I2C\uff09     |\n| `GPIO_MODE_ANALOG`            | \u6a21\u62df\u6a21\u5f0f\uff08ADC\uff09         |\n| `GPIO_MODE_IT_RISING`         | \u4e0a\u5347\u6cbf\u4e2d\u65ad\u8f93\u5165           |\n| `GPIO_MODE_IT_FALLING`        | \u4e0b\u964d\u6cbf\u4e2d\u65ad\u8f93\u5165           |\n| `GPIO_MODE_IT_RISING_FALLING` | \u53cc\u8fb9\u6cbf\u4e2d\u65ad\u8f93\u5165           |\n<\/code><\/pre>\n\n\n\n<p><code>MX_GPIO_Init()<\/code> \u51fd\u6570<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>GPIO_InitTypeDef GPIO_InitStruct = {0};\n\n__HAL_RCC_GPIOA_CLK_ENABLE();  \/\/ 1\ufe0f\u20e3 \u4f7f\u80fd GPIOA \u65f6\u949f\n\nGPIO_InitStruct.Pin = GPIO_PIN_5;\nGPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;  \/\/ 2\ufe0f\u20e3 \u63a8\u633d\u8f93\u51fa\u6a21\u5f0f\nGPIO_InitStruct.Pull = GPIO_NOPULL;\nGPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;\nHAL_GPIO_Init(GPIOA, &amp;GPIO_InitStruct);      \/\/ 3\ufe0f\u20e3 \u521d\u59cb\u5316 PA5\n<\/code><\/pre>\n\n\n\n<p>\u5f00\u6f0f\u6a21\u5f0f\uff1aLED \u957f\u811a\uff08\u6b63\u6781\uff09\u8fde GPIO \u77ed\u811a\uff08\u8d1f\u6781\uff09\u8fde\u7535\u963b \u2192 GND<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>GPIO_InitStruct.Pin = GPIO_PIN_0;\nGPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;   \/\/ \u5f00\u6f0f\u8f93\u51fa\u6a21\u5f0f\nGPIO_InitStruct.Pull = GPIO_PULLUP;           \/\/ \u5185\u90e8\u4e0a\u62c9\u7535\u963b\u542f\u7528\nHAL_GPIO_Init(GPIOA, &amp;GPIO_InitStruct);\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/www.taotao01.fun\/wordpress\/wp-content\/uploads\/2025\/08\/image-5.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" class=\"wp-image-160\"\/><\/figure >\n<noscript><img decoding=\"async\" src=\"https:\/\/www.taotao01.fun\/wordpress\/wp-content\/uploads\/2025\/08\/image-5.png\" alt=\"\" class=\"wp-image-160\"\/><\/figure><\/noscript>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/www.taotao01.fun\/wordpress\/wp-content\/uploads\/2025\/08\/image-3.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" class=\"wp-image-158\"\/><\/figure >\n<noscript><img decoding=\"async\" src=\"https:\/\/www.taotao01.fun\/wordpress\/wp-content\/uploads\/2025\/08\/image-3.png\" alt=\"\" class=\"wp-image-158\"\/><\/figure><\/noscript>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u9009\u9879<\/th><th>\u542b\u4e49<\/th><th>\u7528\u4e8e\u54ea\u4e9b\u529f\u80fd<\/th><th>\u662f\u5426\u5fc5\u987b<\/th><\/tr><\/thead><tbody><tr><td><strong>HSE (High Speed Clock)<\/strong><\/td><td>\u9ad8\u901f\u5916\u90e8\u65f6\u949f\uff0c\u901a\u5e38\u4e3a\u5916\u63a5 8MHz \u6676\u632f<\/td><td>\u4e3b\u7cfb\u7edf\u65f6\u949f\uff08SYSCLK\uff09\u3001\u4e32\u53e3\u3001USB\u3001\u5b9a\u65f6\u5668\u7b49\u4f9d\u8d56\u51c6\u786e\u65f6\u949f<\/td><td>\u2705 \u63a8\u8350\u5f00\u542f\uff08\u4f60\u7684\u677f\u5b50\u901a\u5e38\u5e26 8MHz \u6676\u632f\uff09<\/td><\/tr><tr><td><strong>LSE (Low Speed Clock)<\/strong><\/td><td>\u4f4e\u901f\u5916\u90e8\u65f6\u949f\uff0c\u5e38\u4e3a 32.768KHz \u6676\u4f53<\/td><td>\u7528\u4e8e RTC \u5b9e\u65f6\u65f6\u949f\u3001\u4f4e\u529f\u8017\u5b9a\u65f6\u3001\u65e5\u5386\u529f\u80fd\u7b49<\/td><td>\u274c \u901a\u5e38\u4e0d\u9700\u8981\uff08\u9664\u975e\u4f60\u7528\u5230 RTC\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u8fdb\u9636\uff1astm32 + \u5149\u654f\u7535\u963b\u6a21\u5757 + \u6709\u6e90\u8702\u9e23\u5668\u6a21\u5757<\/p>\n\n\n\n<p>\u5149\u654f\u7535\u963b\u6a21\u5757Pin<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u5f15\u811a\u540d<\/th><th>\u529f\u80fd<\/th><\/tr><\/thead><tbody><tr><td>A0<\/td><td>\u6a21\u62df\u8f93\u51fa\uff08\u53ef\u9009\uff09<\/td><\/tr><tr><td>GND<\/td><td>\u5730\u7ebf<\/td><\/tr><tr><td>D0<\/td><td>\u6570\u5b57\u8f93\u51fa\uff08\u9ad8\/\u4f4e\u7535\u5e73\uff09<\/td><\/tr><tr><td>VCC<\/td><td>\u7535\u6e90\uff08\u4e00\u822c 3.3V \u6216 5V\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u6709\u6e90\u8702\u9e23\u5668\u6a21\u5757<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u8702\u9e23\u5668\u5f15\u811a<\/th><th>\u8bf4\u660e<\/th><th>\u8fde\u63a5\u5230 STM32 \u5c0f\u677f<\/th><\/tr><\/thead><tbody><tr><td>VCC<\/td><td>\u7535\u6e90\uff083.3V\u62165V\uff09<\/td><td><code>3.3V \u6216 5V<\/code>\uff08\u5efa\u8bae\u5148\u7528 5V\uff09<\/td><\/tr><tr><td>GND<\/td><td>\u5730<\/td><td><code>GND<\/code><\/td><\/tr><tr><td>I\/O<\/td><td>\u63a7\u5236\u5f15\u811a\uff08\u4f4e\u7535\u5e73\u89e6\u53d1\uff09<\/td><td>\u6bd4\u5982 <code>PA0<\/code>\uff08GPIO\u8f93\u51fa\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u6709\u6e90\u8702\u9e23\u5668\u6a21\u5757\u63a5\u7ebf\uff08\u4f4e\u7535\u5e73\u89e6\u53d1\u578b\uff09<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u8702\u9e23\u5668\u6a21\u5757\u5f15\u811a<\/th><th>\u8bf4\u660e<\/th><th>\u63a5 STM32 \u5c0f\u677f<\/th><\/tr><\/thead><tbody><tr><td><strong>VCC<\/strong><\/td><td>\u7535\u6e90<\/td><td><code>5V<\/code>\uff08\u6216 3.3V\uff09<\/td><\/tr><tr><td><strong>GND<\/strong><\/td><td>\u5730<\/td><td><code>GND<\/code><\/td><\/tr><tr><td><strong>I\/O<\/strong><\/td><td>\u63a7\u5236\u8f93\u5165<\/td><td><code>PA0<\/code>\uff08\u8f93\u51fa\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5149\u654f\u7535\u963b\u6a21\u5757\u63a5\u7ebf\uff08\u6570\u5b57\u8f93\u51fa D0\uff09<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u5149\u654f\u6a21\u5757\u5f15\u811a<\/th><th>\u8bf4\u660e<\/th><th>\u63a5 STM32 \u5c0f\u677f<\/th><\/tr><\/thead><tbody><tr><td><strong>VCC<\/strong><\/td><td>\u7535\u6e90\uff08\u5efa\u8bae 5V\uff09<\/td><td><code>5V<\/code><\/td><\/tr><tr><td><strong>GND<\/strong><\/td><td>\u5730<\/td><td><code>GND<\/code><\/td><\/tr><tr><td><strong>D0<\/strong><\/td><td>\u6570\u5b57\u4fe1\u53f7\u8f93\u51fa\uff08\u9ad8\/\u4f4e\uff09<\/td><td><code>PA1<\/code>\uff08\u8f93\u5165\uff09<\/td><\/tr><tr><td><strong>A0<\/strong><\/td><td>\u6a21\u62df\u8f93\u51fa\uff08\u53ef\u5ffd\u7565\uff09<\/td><td>\u4e0d\u63a5\u6216\u63a5 <code>ADC<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>#include \"main.h\"\n\nvoid SystemClock_Config(void);\nstatic void MX_GPIO_Init(void);\n\nint main(void)\n{\n  HAL_Init();\n  SystemClock_Config();\n  MX_GPIO_Init();\n\n  while (1)\n  {\n    \/\/ \u5982\u679c\u68c0\u6d4b\u5230\u4f4e\u7535\u5e73\uff0c\u8bf4\u660e\u73af\u5883\u53d8\u6697\n    if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_1) == GPIO_PIN_RESET)\n    {\n      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET); \/\/ \u8702\u9e23\u5668\u54cd\n    }\n    else\n    {\n      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET); \/\/ \u8702\u9e23\u5668\u5173\u95ed\n    }\n\n    HAL_Delay(100); \/\/ \u7a0d\u4f5c\u5ef6\u65f6\n  }\n}\n<\/code><\/pre>\n\n\n\n<p>\u7ee7\u7535\u5668\u5438\u5408\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#define RELAY_ON()  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET) \/\/ \u4f4e\u7535\u5e73\u5438\u5408\n#define RELAY_OFF() HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET)   \/\/ \u9ad8\u7535\u5e73\u65ad\u5f00\n\nRELAY_ON();   \/\/ \u5438\u5408\nHAL_Delay(1000);\nRELAY_OFF();  \/\/ \u65ad\u5f00\nHAL_Delay(1000);\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5c42\u7ea7 \u65b9\u5f0f \u793a\u4f8b \u96be\u5ea6 \u9002\u5408\u4eba\u7fa4 \u9ad8\u7ea7 HAL \u5e93\uff08CubeMX \u9ed8\u8ba4\uff09 HAL_GPIO_WritePin() \u2b50 \u65b0\u624b\u5165\u95e8 \u4e2d &#8230;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-141","post","type-post","status-publish","format-standard","hentry","category-haware"],"_links":{"self":[{"href":"https:\/\/www.taotao01.fun\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.taotao01.fun\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.taotao01.fun\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.taotao01.fun\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.taotao01.fun\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=141"}],"version-history":[{"count":0,"href":"https:\/\/www.taotao01.fun\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/141\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.taotao01.fun\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.taotao01.fun\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.taotao01.fun\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}