pkowalski 1 Posted December 2, 2013 Share Posted December 2, 2013 Hello, I am just getting started with the MSP-EXP430G2 development board so that I can use it for a project. For this project I need to receive/send serial commands on one port and then send/receive them on another. I pulled up the MultiSerial example to get me a quick example and I get an error when trying to compile: MultiSerial.ino: In function 'void setup()': MultiSerial.ino:22:3: error: 'Serial1' was not declared in this scope MultiSerial.ino: In function 'void loop()': MultiSerial.ino:27:7: error: 'Serial1' was not declared in this scope freshfeesh 1 Quote Link to post Share on other sites
pkowalski 1 Posted December 2, 2013 Author Share Posted December 2, 2013 A part of my post above got cut off after the quote tag, sorry about that. I was saying I searched around but couldn't find anything in regards to this so my apologies if it was already covered. I also can't find where serial1 is defined. This is my code from the example: /* Multple serial test Receives from the main serial port, sends to the others. Receives from serial port 1, sends to the main serial (Serial 0). The circuit: * Any serial device attached to Serial port 1 * Serial monitor open on Serial port 0: created 30 Dec. 2008 by Tom Igoe This example code is in the public domain. */ void setup() { // initialize both serial ports: Serial.begin(9600); Serial1.begin(9600); } void loop() { // read from port 1, send to port 0: if (Serial1.available()) { int inByte = Serial1.read(); Serial.write(inByte); } } Quote Link to post Share on other sites
abecedarian 330 Posted December 2, 2013 Share Posted December 2, 2013 Did you look at the SoftwareSerial example? That should let you use hardware serial on the G2553 and 'bit bang' serial on other pins. Quote Link to post Share on other sites
pkowalski 1 Posted December 2, 2013 Author Share Posted December 2, 2013 Edit: Never mind, I didn't select the right processor. Thanks, giving this example a try now. Quote Link to post Share on other sites
pkowalski 1 Posted December 3, 2013 Author Share Posted December 3, 2013 Did you look at the SoftwareSerial example? That should let you use hardware serial on the G2553 and 'bit bang' serial on other pins. Thank you for your help with this, looks like it got me on the right path. However, I am having an issue which I'm sure is due to me not understanding how serial communication works on these devices. I looked at the serial reference library on Energia as well as the more detailed one on Arduino and unfortunately I'm still lost. It appears that when I try to send a string of characters the characters are sent (or possibly read) back one by one and only up to a certain point (like the buffer is getting full). Here is what I am getting using serial monitor: Quote Link to post Share on other sites
pkowalski 1 Posted December 3, 2013 Author Share Posted December 3, 2013 To add to my post above, if on the board that is receiving the serial commands I comment out the serial.write code so that no serial.write exists shouldn't I get the information in the serial console coming from the board that is sending the information? I have pin 1.1 and 1.2 crossed for both boards. However, when I do this and open up the console I get nothing. I am attaching a picture of my setup to make sure I have the wires connected correctly: http://i.imgur.com/TMNaEgg.jpg?1 Thanks! Quote Link to post Share on other sites
pkowalski 1 Posted December 3, 2013 Author Share Posted December 3, 2013 After doing some more testing am I correct in assuming that the serial data is sent one byte at a time? Am I also correct in assuming that the buffer can only store 14 bytes? I am basing this by looking at the mySerial.available() function. When my wires are connected the value is always 14. As soon as I disconnect the RX/TX pins the value drops by 1 each loop until finally it gets to 0. Thanks. Quote Link to post Share on other sites
pkowalski 1 Posted December 3, 2013 Author Share Posted December 3, 2013 Sorry to keep adding to this. After some debugging it appears that I am getting data one byte at a time. And if the data is sent faster than the receiver can receive it some kind of overflow happens. Is it possible to send entire strings over serial or is it only possible to get one byte at a time? Also, I still haven't figured out why I'm not getting data from the hardware UART. It would seem to me that if I use serial.write on the sending board I should be able to pull up the serial monitor on the receiver board and see the messages coming through without having to use Serial.write(Serial.read()); Is this assumption on my part wrong? Thanks. Quote Link to post Share on other sites
semicolo 39 Posted December 4, 2013 Share Posted December 4, 2013 Why are you connecting both serial ports between the cards? Could you explain what you're trying to do? If you want to use the usb to serial interface of one card, nothing should be connected on rx tx (but you're jumping these pins to the other board). Quote Link to post Share on other sites
pkowalski 1 Posted December 4, 2013 Author Share Posted December 4, 2013 I wanted to pass the state of the digital pins and a couple of the analog pins between a network of boards and act on the information (anywhere from 2 to maybe even 8 boards). Each board will have a unique address and be daisy chained sort of like RS-485. I intent to also add a checksum in case bits get lost. After playing with this some more it seems that this works ok: Receiver Board (Which will ultimately be the sender as well): #include <SoftwareSerial.h> SoftwareSerial mySerial(P1_4, P1_3); // RX, TX void setup() { pinMode(RED_LED, OUTPUT); pinMode(P1_6, OUTPUT); digitalWrite(P1_6, HIGH); // Open serial communications and wait for port to open: Serial.begin(9600); // set the data rate for the SoftwareSerial port mySerial.begin(9600); } void loop() // run over and over { //******************* //Serial Port //******************* while(mySerial.available()) { Serial.write(mySerial.read()); } while(Serial.available()) { Serial.write(Serial.read()); } delay(10); } Send Board (which will also be receiver eventually): #include <SoftwareSerial.h> SoftwareSerial mySerial(P1_4, P1_3); // RX, TX void setup() { pinMode(RED_LED, OUTPUT); digitalWrite(RED_LED, HIGH); // Open serial communications and wait for port to open: Serial.begin(9600); mySerial.begin(9600); } void loop() // run over and over { delay(1000); mySerial.println("Software |"); Serial.println("Hardware |"); } The while loop allows me to get all the bytes out of the buffer in one cycle. I'm not sure if this is the best way of doing it. I hope that with this I can combine the data from the while loop, parse it, and create a network of boards. Any thoughts on this would be greatly appreciated. Edit: I noticed I am limited to how long the string can be, about 15 bytes. I'm not sure if that's due to the datatype that println uses. Quote Link to post Share on other sites
semicolo 39 Posted December 4, 2013 Share Posted December 4, 2013 The 15 bytes limit is probably due to the serial buffer, you have to send data at the serial rate or lower to not overrun the said buffer. Using while depends on the amount of data received/sent, if you work on single bytes, you can probably replace the while by ifs. Quote Link to post Share on other sites
energia 485 Posted December 4, 2013 Share Posted December 4, 2013 SoftwareSerial has a hard buffer limit set to 16 bytes. So you 15 is 15 char+ line feed. Reason for setting it so low is that this implementation was done to bring Serial support to the 2231 which has only 128 bytes of RAM. If you are working on a G2553 then you can up this a bit to say 32 bytes. You can so so by changing the define _SS_MAX_RX_BUFF in SoftwareSerial.h which is located in hardware/msp430/libraries/SoftwareSerial Robert 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.