Connecting an SD-Card to your Launchpad opens up your options to use the MSP430 platform as a cheap data logger, from temperature to acceleration. Although you can log to an SD-Card in a raw format, it is much more useful if you could store data onto it as files. This will allow you to disconnect the card from your Launchpad(using a BoosterPack) and view the files on it on a PC.

Luckily for us, a guy known as Elm-Chan created a free, open-source FAT file system library, which can be used on flash disks and USB sticks. However, if you have worked with the Launchpad G2, you have realized that it is low on memory making us wary of dumping huge code libraries into it. Elm-Chan comes to our rescue again with a smaller library, aptly named Petite-FS. The only drawback of this library is the user has to pre-create the file on the SD-Card on a PC before using it on the Launchpad. This should not pose an issue as we can write to that file all day long.

Required Tools And Hardware

Required Software

  • Energia, download from here.
  • SD-Card demo code, download from here.

 

Make sure the BoosterPack is oriented on the Launchpad the correct way.

Connections

The 43oh Store sells an SD-Card BoosterPack, assembled or PCB only. The new version v1.2 of the PCB already has the jumpers set to connect the SD-Card pins to the USCI module of the MSP430. Pin 8 or Port2.0 connects Chip Select line to the SD-Card.

One major advantage of the SD-Card BoosterPack is that you can connect it to any other micro-controller of your choice using the breakout connector J3. Mount the SD-Card BoosterPack to the Launchpad as shown in the adjoining image.

Hardware Preparationmsp430_application_uart

 1. Insert the Launchpad into a spare USB port on your PC. Make sure your drivers for the Launchpad get installed correctly. You should see "MSP430 Application UART" in your COM port device manager. If not, you can download the drivers from here.

2. Take the SD-Card you want to use and plop it into your PC. PetiteFS requires the user to pre-create the log file of the desired size. In this example we create a log file of 1MByte using fsutil and fill it with NULLs. This will allows us to log 2048 log entries( 1048576/512 = 2048 ). Open up a command window in windows as administrator and issue the following command:

fsutil file createnew LOG.txt 1048576

fatfs_sd_card_msp430_launchpad_file creationTo make it easier for you we created a LOG.txt file for you in the same folder as the sketch.

3. Copy the the file LOG.txt under the PFatFs subdirectory to the root folder of the SD-Card. You can leave any other files on the card, but deleting them for this example is suggested.

4. Now copy the file to your SDCard and insert it into your BoosterPack. When you connect your Launchpad to the PC, the red led on the BoosterPack should turn on, which means the card has been inserted properly.

sdcard_launchpad_energia_tutorial_msp430

Downloading and Running Code

1. We hope you have Energia downloaded and running. If not, go here to download the latest version.

3. Download the code for this example from here. See the SDCardTutorialWithEnergia folder? Unzip it and copy it to the Energia Library directory, under hardware msp430 libraries

Now, open Energia and click Open. Browse to the sketch SDCardTutorialWithEnergia.ino under hardware msp430 libraries SDCardTutorialWithEnergiaexamples SDCardTutorialWithEnergia

3. Open Energia.exe and select the correct terminal for your Launchpad as shown below:

sdcard_launchpad_energia_tutorial_msp430_menu_serialport4. Now click File->Upload and Open Serial Monitor. A serial port should pop up. Press the reset button on your Launchpad and you should see something like the below window.

sdcard_launchpad_energia_tutorial_msp430_menu_serialport_2

That's it. Press button S2 and the Launchpad will start writing the current temperature into your SD-Card.

sdcard_launchpad_energia_tutorial_msp430_serialport

 

Closing Notes

  • Logs are spaced out at 5seconds. You can changes this under LOG_DELAY define in your sketch file.
  • To stop the logging, click the reset button on the Launchpad.
  • When you read the file on a PC, you might see a bunch of nulls. This depends on how your text editor in configured. Use notepad++ to view the data.
  • If you reset the MSP430, the prevoius data will be overwritten.
  • If you need more than 2048 entries to be logged, you need to create a bigger file with fsutil.

Thanks To

  • Calinp from the 43oh forums for writing the Energia library and helping me out with the seek function.
  • Elm Chan for his free FatFs library.

Support

You can ask for support in the comments below or this 43oh Forum thread.