cc3200上的serialEvent1

时间:2016-06-22 15:27:05

标签: texas-instruments launchpad

我正在尝试在CC3200启动板上的serial1中接收数据,并将数据发送到serial0以进行串行监视。在我的代码中,serialEvent1不起作用。有人有解决方案吗?有什么问题,拜托?

从评论中更新

我希望在serial1中接收数据并将此数据写入serial0以便在串行监视器中读取。我无法使用serialEvent1函数接收数据。当我把例程接收放在循环中时,我可以接收数据。但是使用serialEvent1函数不起作用。抱歉英语不好,我希望现在已经很清楚了。

String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(1200);
  Serial1.begin(1200);
  pinMode(GREEN_LED,INPUT);

  // reserve 200 bytes for the inputString:
  inputString.reserve(200); 

}

void loop()
{
  // print the string when a newline arrives:
  if (stringComplete) {
    Serial.println(inputString); 
    // clear the string:
    inputString = "";
    stringComplete = false;
  }
}

/*
  SerialEvent occurs whenever a new data comes in the
  hardware serial RX. This routine is run between each
  time loop() runs, so using delay inside loop can delay
  response. Multiple bytes of data may be available.
*/
void serialEvent1() {

  while (Serial1.available()) {
    // get the new byte:
    char inChar = (char) Serial1.read(); 
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n') {
    stringComplete = true;
    } 
  }
}

0 个答案:

没有答案