energia / Energia

Fork of Arduino for the Texas Instruments LaunchPad's
http://energia.nu
Other
795 stars 671 forks source link

Serial Port Management With and Without USCI #60

Closed rei-vilo closed 12 years ago

rei-vilo commented 12 years ago

As suggested by RickKimball on #58

#if !defined( __MSP430_HAS_USCI__ )
#include <TimerSerial.h>
TimerSerial Serial;
#endif

The code raises the following error messages:

sketch_may30a.cpp: 3:13: error: conflicting declaration 'TimerSerial Serial' /Applications/Energia.app/Contents/Resources/Java/hardware/msp430/cores/msp430/HardwareSerial.h:60:23: error: 'Serial' has a previous declaration as 'HardwareSerial Serial'

  • with a msp430g2553

core.a(HardwareSerial.cpp.o): In function 'HardwareSerial::available()': /Applications/Energia.app/Contents/Resources/Java/hardware/msp430/cores/msp430/HardwareSerial.cpp:140: multiple definition of 'rx_buffer' TimerSerial/TimerSerial.cpp.o:/Applications/Energia.app/Contents/Resources/Java/hardware/msp430/libraries/TimerSerial/TimerSerial.cpp:104: first defined here

core.a(HardwareSerial.cpp.o): In function 'HardwareSerial::available()': /Applications/Energia.app/Contents/Resources/Java/hardware/msp430/cores/msp430/HardwareSerial.cpp:140: multiple definition of 'tx_buffer' TimerSerial/TimerSerial.cpp.o:/Applications/Energia.app/Contents/Resources/Java/hardware/msp430/libraries/TimerSerial/TimerSerial.cpp:104: first defined here

Moreover,

robertinant commented 12 years ago

This could be solved by:

 #ifdef __cplusplus
 #include "WCharacter.h"
 #include "WString.h"
+#if defined( __MSP430_HAS_USCI__ )
 #include "HardwareSerial.h"
+#else
+#include <TimerSerial.h>
+TimerSerial Serial;
+#endif

 uint16_t makeWord(uint16_t w);
 uint16_t makeWord(byte h, byte l);

But won't work since Energia.h is not going through the pre-processor like the Sketch is and the compiler will complain about not being able to find TimerSerial.h. The preprocessor basically looks at all the include files and will copy the lib that goes with it to the tmp directory for compilation.

Alternatively we could just move TimerSerial into the core and be done with it.

I will have a look at if there is a clean way to address this in the preprocessor build into the IDE.

RickKimball commented 12 years ago

I like the idea of just moving TimerSerial.h to the core and turning it on by default for non USCI chips.

RickKimball commented 12 years ago

I grabbed this and will start working on it.

rei-vilo commented 12 years ago

Good idea!

RickKimball commented 12 years ago

So I have something working. I haven't checked it in yet. Part of the solution for making it work well with the lower end chips is changing the UART speed to 4800. This makes the communication more reliable when running @ 1MHz. I'm leaning towards just changing the baud rate anyplace in the Examples where Serial.begin() is called to Serial.begin(4800). What are peoples thoughts about this.

robertinant commented 12 years ago

This will make it so much easier for everybody so go for it. I rather have a slower port than all the questions about not working Serial. Can you put a comment that devices running at 16MHz can run serial at up to 9600?

RickKimball commented 12 years ago

there are 48 instances of begin(9600) hmm ...

RickKimball commented 12 years ago

You can a look at the issue_60 branch and try out what I have so far.

robertinant commented 12 years ago

Very nice and so much better. Pulled it into master..