This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/MSP430F5529: How can I convert Energia code to entirely C code?

Part Number: MSP430F5529
Other Parts Discussed in Thread: ENERGIA

Tool/software: TI C/C++ Compiler

Hi!

I am hoping to convert part of an Energia example into entirely C code for use in CCS (ADC examples should be included) to get external thermistor readings with the MSP430F5529 Launchpad. I don't have much experience in using C, but I need to know what should be added/changed to get the thermistor readings. Can anyone help me with this?

Here's the code from the example:

void setup()
{
// initialize serial communication over UART at 9600 baud
Serial.begin(9600);
}

void loop()
{
// >>> Thermistor Section <<<
// take in analog data from thermistor and run it through formulas
// and conversions

float ThermistorVal = analogRead(2);
float ThermistorTempC;
float ThermistorTempF;

ThermistorTempC = logf(10000.0 * ((1024.0 / ThermistorVal - 1)));
// = logf(10000.0 / (1024.0 / ThermistorVal - 1)); // for pull-up configuration
ThermistorTempC = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * ThermistorTempC
* ThermistorTempC ))* ThermistorTempC );
ThermistorTempC = ThermistorTempC - 273.15; // Convert Kelvin to Celcius
ThermistorTempF = (ThermistorTempC * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
Serial.print("Thermistor: ");
Serial.print("vin=");
Serial.print(ThermistorVal);
Serial.print(" ");
Serial.print("TempC=");
Serial.print(ThermistorTempC);
Serial.print(" ");
Serial.print("TempF=");
Serial.print(ThermistorTempF);
Serial.println();

}

Here's what I have so far in the conversion (some Energia code remains):

#include <msp430.h> 

/*

 * main.c

 */

int main(void) {

    WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

    {

      Serial.begin(9600);

    }

    while()

    {

      float ThermistorVal = analogRead(2);

      float ThermistorTempC;

      float ThermistorTempF;

      ThermistorTempC = logf(10000.0 * ((1024.0 / ThermistorVal - 1)));

      //         = logf(10000.0 / (1024.0 / ThermistorVal - 1)); // for pull-up configuration

      ThermistorTempC = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * ThermistorTempC

                        * ThermistorTempC ))* ThermistorTempC );

      ThermistorTempC = ThermistorTempC - 273.15;            // Convert Kelvin to Celcius

      ThermistorTempF = (ThermistorTempC * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit

      printf("Thermistor: ");

      printf("vin=");

      printf(ThermistorVal);

      printf(" ");

      printf("TempC=");

      printf(ThermistorTempC);

      printf("  ");

      printf("TempF=");

      printf(ThermistorTempF);

      printf();

return 0;

}

  • I suggest you start with the driverlib example code. At a minimum you need to grok the uart and ADC examples so you can meld them.

    If you don't know much C, than I *strongly* suggest you stay with Energia. It's whole reason to exist is to make it easy for those (like artists!) who don't want to learn a lot of programming, but still want to use a microcontroller. For example, if you follow the path I outlined above you are going to have to dive into interrupts. Energia handles all that for you.
  • And if you actually want to understand how to implement those Energia library calls, look at the Energia source code.

**Attention** This is a public forum