Jump to content

Unexplained Serial behaviour

Recommended Posts

I have the following simple code set up to echo whatever I type into the Serial Monitor, but as HEX with a comma separating each byte (So I can also see control codes) :

int inByte = 0;          // incoming serial byte
byte buffer[30]; // buffer for bytes coming from HMI.

void setup()
{                         // Enable USCI_A1 RX interrupt

// start serial port at 9600 bps:

void loop()
        int bytesread = 0;
        // if we get a valid byte, read analog ins:

        if (Serial1.available()>0) { // there are bytes in the serial buffer to read
                while(Serial1.available()>0) { // every time a byte is read it is expunged
                        // from the serial buffer so keep reading the buffer until all the bytes
                        // have been read.
                        byte inbyte = Serial1.read();
                        buffer[bytesread] = inbyte;

        for (int x = 0; x < bytesread; x++)
                Serial1.print(buffer[x], HEX);


However, it is behaving a bit weird and unexplained.


If I enter ABCDE and press ENTER I would expect the output to be:


But instead it just prints


When I enter ABCDE and ENTER a second time I then get:


Which is the missing characters from the first entry pluis the first character only from the second.


This is not what I expected.


Device is an MSP430-5969


Any ideas please?





Link to post
Share on other sites

OK that was something at the terminal side rather the MSP430 side.


However, I have discovered something weird going on...


I have a Nextion display that communicates over serial at 9600 baud.


When you press a button it sends a text string with codes to show which button on which page has been pressed etc.


When the screen is connected to an Arduino Nano I get valid strings back which look like:

"65 0 4 0 ffff ffff ffff"

But when connected to the MSP430 the message back from the display is just garbled.


I can send data FROM the MSP430 to the display perfectly fine and control it no problem. But data received back from the display is garbled. The display is fine (as shown when connecting it to a Nano) so what is going on here?

Link to post
Share on other sites


Has anybody else with an MSP430 (even better still the FR5969 variant) managed to get serial at 9600 baud to be read successfully by the device?

Yes, of course.  When you ask for advice, always specify the compiler/version you are using as well as the LaunchPad.  Also, describe or post a photo of the circuit where it makes sense. Fully describe the problem and where possible give sufficient information for others to duplicate the problem.  There is a button below posts in 43oh where you can thank others when you get help.


The following was done in Energia V17.  First, set up a source for Serial1.  I used a F5529.  TX for Serial1 is on pin 4.  Here is the code, it outputs the 255 characters  on one line and then starts over:

void setup()

void loop()
  int i;
  for(i=0; i<255; i++){

Second, set up a receiver, in this case a FR5969.  RX for Serial1 is on pin3 and it is attached to pin 4 (TX) on the F5529.  I am powering both LaunchPads off of the FR5969.  Be sure to place a ground wire between the two LaunchPads.



Here is the code for the receiver:

void setup() {
  // initialize both serial ports:

void loop() {
    if (Serial1.available()) {
      int inByte = Serial1.read();

Run and the output will look something like this....



Link to post
Share on other sites

As far as I know the Arduino Nano is a 5 Volt device. I think the same is true for the Nextion display. The MSP430 however is a 3.3 Volt device. So be very carful with that. The I/O's on the MSP430 are NOT 5 Volt tolerant and you might have burned out the RX pin on the MSP430. To test this you can connect the TX pin to the RX pin on the MSP430 to see if it is still operational. 



Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...