allefpablo 0 Posted June 22, 2016 Share Posted June 22, 2016 I'm trying to receive data in serial1 on CC3200 launchpad and send the data to serial0 for serial monitor. In my code, serialEvent1 don't work. Anyone has a solution for this? What is wrong, please? 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; } } } Quote Link to post Share on other sites
Fmilburn 446 Posted June 22, 2016 Share Posted June 22, 2016 Hi @@allefpablo You need a call to serialEvent() in loop(). Your comment about serialEvent being called when new data comes in is incorrect. Quote Link to post Share on other sites
allefpablo 0 Posted June 22, 2016 Author Share Posted June 22, 2016 Hello, @@Fmilburn! Thanks for you reply. We have this code in file main.cpp in energia folder (\hardware\cc3200\cores\cc3200): int main(void) { setup(); for (; { loop(); if (serialEventRun) serialEventRun(); } } and, we have this code in HardwareSerial.cpp in same folder: void serialEventRun(void) { if (Serial.available()) serialEvent(); if (Serial1.available()) serialEvent1(); } Quote Link to post Share on other sites
Fmilburn 446 Posted June 22, 2016 Share Posted June 22, 2016 @@allefpablo OK, put some debug print in serialEvent() for inChar to see if characters are being received. In particular, make sure that a "/n" is being received so that the flag is set. The serial monitor in Energia has a pull down tab lower right hand side that can be set to "No line ending" for example which would prevent this from working. EDIT: I don't have a working cc3200. But for some reason, a baud rate of 1200 does not work reliably on the F5529 for me. So you might try increasing that to 9600 or higher. Quote Link to post Share on other sites
Sam123 0 Posted May 8, 2020 Share Posted May 8, 2020 Hi @allefpablo I have a similar problem accessing 2nd UART port. Have you been able to solve the problem? THanks, Sam Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.