arduino stm32 不能使用PA11 PA12问题解决办法

应为stm32库里默认使用了usb serial cdc占用了这两个引脚,所以导致不管怎么设置外设的odr都是无效的,不管给定brr或者bsrr都是没有动作的,这个问题的解决办法如下

const int run =PA12;

const int err =PA11;

void setup() {

  Serial.end();

这个串口默认初始化为serial 禁用也不起作用,这个时做到bootloader里的,所以这里必须Serial.end();

结束这个串口就释放了外设,从而解决问题

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
The DHT11 is a digital temperature and humidity sensor that can be interfaced with an Arduino or an STM32 microcontroller. The sensor communicates through a single wire digital interface and provides an accuracy of ±2°C for temperature and ±5% for humidity readings. To interface the DHT11 sensor with an Arduino or an STM32 microcontroller, you can use the following steps: 1. Connect the Vcc pin of the DHT11 sensor to the 5V pin of the microcontroller. 2. Connect the GND pin of the DHT11 sensor to the GND pin of the microcontroller. 3. Connect the data pin of the DHT11 sensor to any digital pin of the microcontroller. For Arduino: 4. Install the DHT11 library from the Arduino IDE library manager. 5. Include the DHT11 library in the Arduino sketch. 6. Create a DHT11 object and initialize it with the data pin. 7. Read the temperature and humidity values using the read() method of the DHT11 object. Here's a sample code to read the temperature and humidity values from the DHT11 sensor using Arduino: #include <dht11.h> dht11 DHT; #define DHT11_PIN 2 void setup() { Serial.begin(9600); } void loop() { int chk = DHT.read(DHT11_PIN); Serial.print("Temperature: "); Serial.print(DHT.temperature); Serial.print("°C | Humidity: "); Serial.print(DHT.humidity); Serial.println("%"); delay(2000); } For STM32: 4. Download the DHT11 library from the internet. 5. Include the DHT11 library in the STM32 project. 6. Create a DHT11 object and initialize it with the data pin. 7. Read the temperature and humidity values using the read() method of the DHT11 object. Here's a sample code to read the temperature and humidity values from the DHT11 sensor using STM32: #include "DHT11.h" DHT11 dht11(GPIOA, GPIO_PIN_0); int main(void) { HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); while (1) { if (dht11.read() == DHT11_OK) { printf("Temperature: %d°C | Humidity: %d%%\n", dht11.getTemperature(), dht11.getHumidity()); } HAL_Delay(2000); } } Note: The data pin of the DHT11 sensor should be connected to a GPIO pin that supports input/output mode and has a pull-up resistor. Also, make sure to use a capacitor between the Vcc and GND pins of the DHT11 sensor to stabilize the power supply.
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值