• Announcements

    • bluehash

      Forum Upgrade   03/11/2017

      Hello Everyone, Thanks for being patient while the forums were being fixed and upgraded. Please see details and report issues in this thread. Thanks!
Sign in to follow this  
Followers 0
Unit

MSP430F5529 JSON Code

6 posts in this topic

Hello Forums

 

I am trying to use GUI Composer v2 (on the cloud) to create a GUI for a battery managment system, similar to the one in the SLAA478 Application Report, using the MSP-EXP430F5529LP and bq76PL536EVM-3.

 

I've decided to use USB/Serial comms, which requires me to modify the code to send the information using JSON. I am following the example of using USB/Serial IO: https://dev.ti.com/gc/designer/help/Tutorials/Serial/index.html.

 

The code given is as follows:

#include <aJSON.h>

// most launchpads have a red LED
#define LED RED_LED

//see pins_energia.h for more LED definitions
void printled_statewithjson(int state){
  aJsonObject* root = aJson.createObject();
  if (root == NULL) {
    return;
  }

  aJson.addItemToObject(root, "LED", aJson.createItem(state));

  char* string = aJson.print(root);
  
  if (string != NULL) {
    Serial.println(string);
    free(string);
  } 
  
  aJson.deleteItem(root);
}


  
// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(LED, OUTPUT);     
  Serial.begin(9600); 
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(LED, HIGH);   // turn the LED on (HIGH is the voltage level)
  printled_statewithjson(1); // print json object with LED status set to 1 to UART
  delay(1000);               // wait for a second
  digitalWrite(LED, LOW);    // turn the LED off by making the voltage LOW
  printled_statewithjson(0); // print json object with LED status set to 0 to UART
  delay(1000);               // wait for a second
}

I am trying to fully understand this example code, before implementing it into my program. Using CCS Cloud, I stepped through the program in debug mode.

 

From what I understand, the loop() function is essentially the main function, which blinks the LED; setup() does as expected and initializes the MCU LED pin, and opening a serial port at 9600 baud rate.

 

I cannot, however, understand the printled_statewithjson() function. How exactly does it work to be able to send the information? 

 

Regards

Share this post


Link to post
Share on other sites

You need to dig into the aJSON library. 

 

Basically, the library only manages the { } and structure for formatting the message.

 

You can prepare a JSON-compliant message with plain string functions instead of using that library.

{ "LED" : 1 }

Find more at http://www.json.org.

energia, Unit and Fmilburn like this

Share this post


Link to post
Share on other sites

You need to dig into the aJSON library. 

 

Basically, the library only manages the { } and structure for formatting the message.

 

You can prepare a JSON-compliant message with plain string functions instead of using that library.

{ "LED" : 1 }

Find more at http://www.json.org.

 

Thanks for the link. I now understand how JSON works, and how the GUI interprets the information.

 

Should be straight forward to write JSON-compliant messages now, with or without using that library.

 

Regards

Share this post


Link to post
Share on other sites

In a further update, I tried writing some code to sent similar information to the host PC:

 if (g%2 == 0){
       strcpy(OutputString,"\r\n{\"LED\":0\}\r\n");
       #ifdef UART_COMM
       // Send the message to the host over UART
             putsUART((BYTE*)OutputString,strlen(OutputString));
       #endif
   }
   else{
       strcpy(OutputString,"\r\n{\"LED\":1\}\r\n");
       #ifdef UART_COMM
       // Send the message to the host over UART
             putsUART((BYTE*)OutputString,strlen(OutputString));
       #endif
   }
   g++;

I verified with PuTTY that the COM port does indeed, receive the information (http://i1337.photobucket.com/albums/o678/pulser18/puttyworks_zpsl9ahm2tz.png~original).

 

When I try using the GUI Composer v2, the service says that it is connected to the COM port, but is waiting on data. The service never receives the data.

 

Any advice?

Regards

Share this post


Link to post
Share on other sites

did you remember to close the putty window?

 

Yes, I did. I learned quite a while back that only one application can access the COM port at a particular instant in time. So I closed the PuTTY window, then tried accessing the COM port via GUI Composer v2.

 

Regards

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
Sign in to follow this  
Followers 0