有没有一种干净的方法来禁用莱昂纳多的USBCore的RX控制

Is there a clean way of disabiling RX control from USBCore in leonardo?

本文关键字:莱昂纳多 USBCore 控制 RX 方法 有没有 一种      更新时间:2023-10-16

目前,我正在尝试使用sparkfun promicro使用此草图 https://www.sparkfun.com/tutorials/338 随意控制RX引脚。

但是,我遇到了一个问题,尽管可以控制RX和TX led,但它受到arduino中的USBCore.cpp干扰。我想知道是否有一种干净的方法来禁用 USBCore 对 RX 和 TX 引脚的控制,同时仍然保留 USB 串行,以便我可以直接控制这些引脚,即使在接收和发送串行数据时也是如此。

/* Pro Micro Test Code
   by: Nathan Seidle
   modified by: Jim Lindblom
   SparkFun Electronics
   date: January 20, 2012
   license: Public Domain - please use this code however you'd like.
   It's provided as a learning tool.
   This code is provided to show how to control the SparkFun
   ProMicro's TX and RX LEDs within a sketch. It also serves
   to explain the difference between Serial.print() and
   Serial1.print().
*/
int RXLED = 17;  // The RX LED has a defined Arduino pin
// The TX LED was not so lucky, we'll need to use pre-defined
// macros (TXLED1, TXLED0) to control that.
void setup()
{
 pinMode(RXLED, OUTPUT);  // Set RX LED as an output
 // TX LED is set as an output behind the scenes
 Serial.begin(9600); //This pipes to the serial monitor
 Serial1.begin(9600); //This is the UART, pipes to sensors attached to board
}
void loop()
{
 Serial.println("Hello world");  // Print "Hello World" to the Serial Monitor
 Serial1.println("Hello!");  // Print "Hello!" over hardware UART
 digitalWrite(RXLED, HIGH);   // set the LED on
 TXLED1; //TX LED is not tied to a normally controlled pin
 delay(1000);              // wait for a second
 digitalWrite(RXLED, LOW);    // set the LED off
 TXLED0;
 delay(1000);              // wait for a second
}

如果在不修改 arduino 环境的情况下无法干净地解决这个问题,那么我将修改 USBCore.cpp 。然而,这样做可能是不好的做法。

如果可能的话,您可以使用引脚 17 作为输入,希望释放另一个引脚,然后您可以将其用作输出。

为此,只需使用 pinMode() 将引脚 17 设置为 INPUT。

这有效地禁用了 RXLED 功能。 当USBCore向该引脚写入高电平时,它只是打开上拉电阻。 只要驱动输入的器件即使在上拉开启时也能吸收足够的电流,这就不会产生任何影响。 因此,无需修改USBCore。

编辑:当引脚17为低电平时,LED亮起,这意味着信号源需要吸收电流。 如果问题通过切断 LED 旁边的 PCB 走线或拆焊 LED 或电阻器,可以避免这种情况。