2013-10-06 47 views
0

目前我正在嘗試使用sparkfun promicro隨意使用此草圖https://www.sparkfun.com/tutorials/338來控制RX引腳。在leonardo中有沒有一種清除USBCore RX控制的乾淨方法?

但是,我遇到了一個問題,儘管控制了RX和TX,但它受到了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。然而,這樣做的做法很糟糕。

回答

1

如果可能在您的情況下,您可以使用引腳17作爲輸入,希望釋放另一個引腳,然後可以用作輸出。

要做到這一點,只需使用pinMode()將引腳17設置爲INPUT即可。

這可以有效地禁用RXLED功能。當USBCore向該引腳寫入高電平時,僅打開上拉電阻。只要驅動輸入的設備即使在上拉時打開足夠的電流,這也不會起作用。所以不需要修改USBCore。

編輯:當引腳17爲低電平時LED亮起,這意味着信號源需要吸收電流。如果通過切斷LED旁邊的PCB軌道或通過拆焊LED或電阻來解決問題,可以避免這種情況。

相關問題