iammiles

Writing C Code in Energia

8 posts in this topic

Hi Everyone!

 

I've just received a Tiva C launchpad and was wondering if you are able to write C code in Energia or if you have to use their Processing-based language?  And if not, is there a way to use just write C code on Mac OS X (with or without an IDE) and upload it to the device?  After a quick search of this forum and Google, most C compilers are meant for a  Windows environment and I haven't been able to find much information for OS X other than Energia or possibly embedXCode.

 

Thanks,

Miles

Share this post


Link to post
Share on other sites

Is there a specific reason for using C instead of C++?

 

The official IDE from Texas Instruments in Code Composer Studio, based on Eclipse.

 

This is a professional grade IDE but I faced many difficulties when installing and maintaining it.

 

If you're familiar with Eclipse, this could be a good choice.

 

The other option is Energia, which actually combines different elements.

 

Energia uses the Wiring framework, adapted to the MSP430 and Stellaris now Tiva C Series, which provides all the libraries for managing I

iammiles likes this

Share this post


Link to post
Share on other sites

Thanks for your quick and thorough reply!

 

The main reason that I want to use the C language is because I'm already fairly familiar with it from previous programming experiences.  My second motive for using C is the free online course, https://www.edx.org/course/utaustinx/utaustinx-ut-6-01x-embedded-systems-1172.  While I understand that they're using Windows, I figured I'd just follow along for my own personal benefit.

 

I suppose I could just use Energia with C++ and not implement objects, but I'm a bit worried with compatibility since C++ isn't a strict superset of C.

Share this post


Link to post
Share on other sites

You and me both, iammiles!  I just received my Tiva C LaunchPads (I bought 2) via FedEx this morning from the TI store, in anticipation of taking the same edX class in a couple weeks.

 

Being new to the world of TI micros, I have installed all kinds of software already ... trying to figure out how to get started.  I installed Keil which will be used during the class, but the TExaS add-on stuff isn't ready for download yet.  (I wonder if I'll have to uninstall and start over once the class starts?)

 

Anyway, after installing Energia I was able to get the Button example sketch to work.  I even changed the LED color and the button (from 2 to 1) and my changes worked too.  I guess that will have to count for my "Hello (TI) world!" maiden voyage.

 

See you around, and Best of Luck!

Share this post


Link to post
Share on other sites

So, typing from my phone here I might not be too much help but one thing I have heard is Energia's core framework has things set up so if you provide your own main() function then Energia scraps the framework and compiles your C app instead. Not sure how well that works for Tiva-C though, because Energia provides its own interrupt vector table that includes pointers to its own framework. If that can be overridden, then TivaWare apps can be written from scratch with the Energia IDE too.

 

Sent from my Galaxy Note II with Tapatalk 4

 

 

Share this post


Link to post
Share on other sites
On 2014-1-7 at 2:16 AM, Rei Vilo said:

Is there a specific reason for using C instead of C++?

 

The official IDE from Texas Instruments in Code Composer Studio, based on Eclipse.

 

This is a professional grade IDE but I faced many difficulties when installing and maintaining it.

 

If you're familiar with Eclipse, this could be a good choice.

 

The other option is Energia, which actually combines different elements.

 

Energia uses the Wiring framework, adapted to the MSP430 and Stellaris now Tiva C Series, which provides all the libraries for managing I

Code composer studio is not detecting my MSP Launchpad while Energia easily detects it and loads program on it. Does anyone know why CCS is not detecting Launchpad??

Share this post


Link to post
Share on other sites

This seems to be an old post. Nevertheless, I was wondering about the same thing and I figured that you can write native C code using Energia in a very simple way. Here is an example. Forgive me if my formatting of the message was not perfect, but this is my first post to this forum... :)

I wanted to create a simple test application that would print numbers 0 to 31 to my COM port (using serial monitor of Energia). I created three files:

testc (Energia sketch)
myfun.c (C code for a single function that increments a number)
myfun.h (C header file which provides prototype for the increment function)

Here is the complete code:

Energia sketch for testc

extern "C" {
#include "myfun.h"
}

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);

  // prints title with ending line break
  Serial.println("Increment Test");

}

int x = 0;

void loop() {
  if (x >= 32) {
    while(true) {
      continue;
    }
  }
  Serial.println(x,DEC);
  x = inc(x);
}

myfun.c:

int inc(int x)
{
  return(x+1);
}

myfun.h:

extern int inc(int x);
 

I used MSP430FR6989 LaunchPad to execute this and it worked. The output from my (application) COM port was as expected:

Increment Test
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

That's it! The key to this example was to remember to use extern "C" {} declaration so that Energia would recognize that what was included was written using C language.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now