pine 140 Posted March 3, 2014 Share Posted March 3, 2014 Hi All, I am looking for advice on converting a CCS project into Energia, preferably making a library. I did not created the CCS project, it is actually a demo project downloadable from TI for a booster pack called TMP006. The link is http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/boosterpack/TMP006/latest/index_FDS.html?DCMP=msp430&HQS=tmp006boosterpack The zip package included a CCS project with some C and header files. Where should I start? Any advise or links to understand Energia library will be much appreciated. Thanks in advance. Quote Link to post Share on other sites
energia 484 Posted March 3, 2014 Share Posted March 3, 2014 I would advice to get CCSv6 that features Energia Sketch import. Get it here: http://processors.wiki.ti.com/index.php/Category:Code_Composer_Studio_v6 Robert pine 1 Quote Link to post Share on other sites
spirilis 1,265 Posted March 3, 2014 Share Posted March 3, 2014 I think he's talking about going the other direction; translating a pure-C CCS library into an Energia C++ lib. For a tutorial on writing Energia (Wiring/Arduino) libraries, see here: http://energia.nu/Tutorial_Library.html Any other pages talking about the details writing libraries for Arduino may offer assistance here. A quick word of note is that if it's a pure C library, you might be able to just use it out of the box; put its .c and .h files in a named directory under your local Energia libraries folder, and #include its .h files in your app. But keep in mind it'll be operating on the native hardware's pin identifiers/etc. If you feel you understand the hardware & library well enough to take a go at rolling your own from scratch, definitely look through that tutorial and inspect some of the libraries that ship with Energia to get ideas about what kinds of things you can do. The basic gist is that Energia libraries, the native ones anyhow, are C++ classes in which you can declare an instantiation (object) of only at compile time; e.g. at the top of your sketch you'll see a declaration of an instance of the library, like: Enrf24 radio(params...); (using my own Enrf24 library as an example) The contents of the "params..." section are passed to a constructor function, defined in my Enrf24 lib like: Enrf24::Enrf24(int cePin, int csnPin, int irqPin) { ... blah blah ... } Since that constructor executes in an early context where stuff isn't necessarily set up right, it's common practice for Energia, Arduino, etc. libraries to have a special "begin" method that *actually* initializes the hardware controlled by the library in question. See "Serial.begin()" for an example there. In the example I just posted, "radio" becomes the name of the instantiated object, so you can do radio.begin(), radio.print(), etc. inside the sketch. pine 1 Quote Link to post Share on other sites
rsjsouza 1 Posted March 3, 2014 Share Posted March 3, 2014 I would advice to get CCSv6 that features Energia Sketch import. Get it here: http://processors.wiki.ti.com/index.php/Category:Code_Composer_Studio_v6 Just a piggyback to Robert's link, there is also a short intro video at the CCS youtube channel pine 1 Quote Link to post Share on other sites
energia 484 Posted March 4, 2014 Share Posted March 4, 2014 Sorry, misread the post. I have not done CCS Project-> Energia so am afraid I can't be of much help here. Quote Link to post Share on other sites
pine 140 Posted March 4, 2014 Author Share Posted March 4, 2014 Thanks all for your advice. I am trying to move the source from CCS bit by bit to Energia, and the strategy is to make it work first, and then I'll follow the tutorial link from @@spirilis to refactor into a library. Having read the original main.c file I realized the uart.* are not necessary as Energia provided the serial function already. So is the LED blinking stuff which will be commented out. These are going to make things simpler I guess. The library folder as of now consist only tmp006.c and tmp006.h. Then I tried to migrate the original CCS main.c into a new Energia project, but got hit with the following error: TMP006\tmp006.c.o: In function `tmp006_calculateTemp': C:\energia-0101E0011\hardware\msp430\libraries\TMP006/tmp006.c:238: undefined reference to `pow' C:\energia-0101E0011\hardware\msp430\libraries\TMP006/tmp006.c:238: undefined reference to `pow' collect2: ld returned 1 exit status It seems like the pow() function is not recognized by Energia? Or did I haven't setup the correct import directives? There is #include <math.h> in the tmp006.c, and the above error is complaining the following statements: long double tmp006_calculateTemp(long double * tDie, long double * vObj) { /* Calculate TMP006. This needs to be reviewed and calibrated by TMP group */ long double S0 = 6 * pow(10, -14); /* Default S0 cal value */ long double a1 = 1.75*pow(10, -3); long double a2 = -1.678*pow(10, -5); long double b0 = -2.94*pow(10, -5); long double b1 = -5.7*pow(10, -7); Any help will be much appreciated, thanks in advance. Quote Link to post Share on other sites
spirilis 1,265 Posted March 4, 2014 Share Posted March 4, 2014 Try changing all the "double" to "float" and change any reference to "pow" into "powf". pine 1 Quote Link to post Share on other sites
spirilis 1,265 Posted March 4, 2014 Share Posted March 4, 2014 Although, I'm not sure if mspgcc deals with "long double" but I doubt it matters. Change all instances of "long double" to float and see if it works. Quote Link to post Share on other sites
spirilis 1,265 Posted March 4, 2014 Share Posted March 4, 2014 Additionally, as food for thought, look around and see if any Arduino libs have already been created for the TMP006 hardware. Might be wasting your time here pine 1 Quote Link to post Share on other sites
pine 140 Posted March 4, 2014 Author Share Posted March 4, 2014 Thanks Spirilis! The source compiles ok now after changing all long double to float, and pow to powf. My problem now is that I left the TMP006 module in another place so can't test the code now And yes you are right, there is an Arduino library for exactly this module from Adafruit! Will test this out as well. It looks like this library used the Wire library and I think it is more generic than the CSS demo code, in a sense that Wire library in Energia will be abstracted across the various LPs? When I was porting the code, I found that the compiler will complains some sort of registers if the board selected is not G2553, which is the original CCS demo code written for.. error messages like below: tmp006_test1.ino:58:5: error: 'BCSCTL3' was not declared in this scope tmp006_test1.ino:58:16: error: 'LFXT1S_2' was not declared in this scope tmp006_test1.ino:61:9: error: 'CALBC1_1MHZ' was not declared in this scope tmp006_test1.ino:65:9: error: 'DCOCTL' was not declared in this scope tmp006_test1.ino:67:9: error: 'BCSCTL1' was not declared in this scope tmp006_test1.ino:68:18: error: 'CALDCO_1MHZ' was not declared in this scope Thanks again. Quote Link to post Share on other sites
spirilis 1,265 Posted March 4, 2014 Share Posted March 4, 2014 Thanks Spirilis! The source compiles ok now after changing all long double to float, and pow to powf. My problem now is that I left the TMP006 module in another place so can't test the code now And yes you are right, there is an Arduino library for exactly this module from Adafruit! Will test this out as well. It looks like this library used the Wire library and I think it is more generic than the CSS demo code, in a sense that Wire library in Energia will be abstracted across the various LPs? When I was porting the code, I found that the compiler will complains some sort of registers if the board selected is not G2553, which is the original CCS demo code written for.. error messages like below: tmp006_test1.ino:58:5: error: 'BCSCTL3' was not declared in this scope tmp006_test1.ino:58:16: error: 'LFXT1S_2' was not declared in this scope tmp006_test1.ino:61:9: error: 'CALBC1_1MHZ' was not declared in this scope tmp006_test1.ino:65:9: error: 'DCOCTL' was not declared in this scope tmp006_test1.ino:67:9: error: 'BCSCTL1' was not declared in this scope tmp006_test1.ino:68:18: error: 'CALDCO_1MHZ' was not declared in this scope Thanks again. Yeah that's probably specific to the G2553. The adafruit lib should work across LP's much better. Keep in mind since the library uses floating point, it'll bloat the firmware by a bit (4KB or so?) reducing your available size for other stuff. Probably not a huge issue though. pine 1 Quote Link to post Share on other sites
pine 140 Posted March 8, 2014 Author Share Posted March 8, 2014 Finally have the actual TMP006 module tested in Energia code, the Adafruit library worked without any modification. But still I think I will try to take the other way converting the CCS project for learning. The setup is using an MSP430F5529LP, the TI TMP006 booster pack, and a 16x2 LCD display. The code in Energia and will display in the LCD both sensor and die temperature, record max/min, and sample counts. Thanks everyone! 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.