Running LEDs on MSP-EXP430FR5739 FRAM board

In this part we are going to create a simple project for MSP-EXP430FR5739 FRAM board. As development tools we are going to use Code Composer Studio which is free to up to 16KB Flash code size. MSP430FR5739 microcontroller has exactly 16KB of FRAM memory so we can use it all with no hustle.

EXP430FR5739_running_LEDS

Download Code Compose Studio (CCS) and install it to your PC. Then start application and go to workbench. It is Eclipse based IDE so should be no problem if you have used Eclipse before.

To create new project go to File->New->CCS Project. You will be prompted to enter project name and storage location.

CCS_new_project

In the next window we need to choose MSP430 Project Type and select both- Debug and Release Configurations.

CCS_select_project_type

Click Next until you reach project settings. Here you select Executable output Type and in device variant select suitable microcontroller. In our case we look up for MSP430FR5739 and then click Finish. And we end up with project skeleton where Necessary includes are linked to project:

CSS_project_tree

Lets create new source file called main.c in project main directory. This will be our main code file. For now we are going to drive LEDs. Without messing main code lets put LED related function in to different source file called led.c with header file led.h. And put them in to Drivers directory in project directory tree. First of all lets take care of LED header file. Here we simply define pin numbers for each of 8 LEDs and write function prototypes as follows:

CCS_led_h

All we need here is to initialize LED pins and then add several control functions like turning ON/OFF and toggling diodes. In led.c file we need to write actual functions. First of all lets deal with LEDInit function that has to enable LED connected pins as output and set initial LED states:

void LEDInit(void)
{
  //first four bits
  PJDIR |=LED1+LED2+LED3+LED4;
  //Leds Off
  PJOUT &= ~(LED1+LED2+LED3+LED4);    
  //last four leds
  P3DIR |=LED5+LED6+LED7+LED8;
  //Leds Off
  P3OUT &=~(LED5+LED6+LED7+LED8);
}

In MSP-EXP430FR5739 FRAM board there are 8 user programmable LEDs four of them are connected to PORTJ pins 0..3 and another four is to PORT3 4..7 pins. LEDs are connected to GND via current limiting resistors:

MSP-EXP430FR5739_LEDS

Initially we also need to set port pins to low so LEDs were OFF.

To make code a bit more compact we are going to use array of led pins:

//array of led pins
unsigned char leds[]={LED1, LED2, LED3, LED4, LED5, LED6, LED7, LED8};

This makes easier to pass led number to control functions. Bellow you can see implementation of all three control functions:

void LEDOn(unsigned char LEDn)
{
    if ((LEDn>0)&&(LEDn<=4))
  {
      PJOUT |= leds[--LEDn];
  }
    if ((LEDn>4)&&(LEDn<=8))
  {
      P3OUT |= leds[--LEDn];
  }
}
void LEDOff(unsigned char LEDn)
{
    
  if ((LEDn>0)&&(LEDn<=4))
  {
      PJOUT &= ~leds[--LEDn];
  }
    if ((LEDn>4)&&(LEDn<=8))
  {
      P3OUT &= ~leds[--LEDn];
  }
}
void LEDToggle(unsigned char LEDn)
{
    
  if ((LEDn>0)&&(LEDn<=4))
  {
      PJOUT ^= leds[--LEDn];
  }
    if ((LEDn>4)&&(LEDn<=8))
  {
      P3OUT ^= leds[--LEDn];
  }
}

Now when we have drivers ready we can write main program. This task becomes very simple:

#include "msp430fr5739.h"
#include "Drivers/led.h"
void main(void)
{
  unsigned char i;
  // Stop WDT
  WDTCTL = WDTPW + WDTHOLD;                 
  LEDInit();
  while(1)
  {
      //run through LEDs
      for(i=0; i<=8; i++)
      {
          LEDToggle(i);
          __delay_cycles(100000);
      }
  }
}

At the beginning of main.c file we need to include device and our led driver headers. Then in main routine we simply initialize ports where LEDs are connected and then run infinity loop that sweeps all 8 LEDs.

Now we can build our project by selecting Project->Build Active Project. After successful build compiler produces .out file that will be programmed in to Flash. Simplest way to program board is to run debugger. For this go to menu Target->Debug Active Project. This will automatically load compiled file to flash memory and prepare environment for debugging. You have two choices – run debugger and analyze your program flow step by step where you can watch how each instruction is executed or simply leave debugger, reset your board and enjoy your new program.

Project source files: MSP-EXP430FR5739 FRAM board LED test run

Leave a Reply

Your email address will not be published. Required fields are marked *