有没有一种干净的方法来禁用莱昂纳多的USBCore的RX控制
Is there a clean way of disabiling RX control from USBCore in leonardo?
目前,我正在尝试使用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 或电阻器,可以避免这种情况。
相关文章:
- 多态性和功能结合
- 具有默认模板参数的多态类的模板推导失败
- 处理多个异常集合的C++方法
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 尝试通过多个向量访问变量时,向量下标超出范围
- 在没有太多条件句的情况下,我如何避免被零除
- 在C++中使用cURL和多线程
- Ardunio UNO解决了多个重叠的定时器循环
- 在计算中使用二的幂有多有利可图
- MSVC多行宏编译器错误
- 通过多个头文件使用常量变量
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 多成员Constexpr结构初始化
- 是否可以通过C++扩展强制多个python进程共享同一内存
- 多态二进制函数
- 基于多个条件处理地图中的所有元素
- 有没有一种干净的方法来禁用莱昂纳多的USBCore的RX控制
- C++ System() 的替代方法,用于启动多个命令提示符.威纳皮 ( 无 MFC ).
- 如何在列奥纳多堆中找到根的左右子结点
- 纳睡眠不适用于多个线程