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
- Launchpad EXP-MSP430G2
- SD-Card BoosterPack
- SD-Card, any size.
- USB cable
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 Preparation
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
To 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.
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:
4. 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.
That's it. Press button S2 and the Launchpad will start writing the current temperature into your SD-Card.
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.
Awesome tutorial. One question, if we need to create more log files or entires, should the size of the LOG.tXT file be increased?
Yes, you need to increase the file size accordingly using fsutil. If you have a bigger card, you can fill the full card with nulls using fsutil. See pt.2 under Hardware Preparation.
What is the max size sdcard you can use with this code? Thanks for writing this up.
The PetiteFS library supports Fat32. So the maximum file size is 4GByte. However you can use a larger size card. We used an 8GByte card as a test and we were able to write to it. But it will not be of much help, as the largest file that can be used is 4GB.
You can however, create two files – 4GB each and switch files when one reaches 4GB. Hope this helps.
Is there a browsable repository of the code?
No.. Just the downloadable zip mentioned above.
i need to do the following please tell if possible :
1> store analog values in different files
2> read different files based on some conditions
3>output the analog value of that file to pwm pins
Hi,
im really interested in that library as i´ve been looking for something like this for so long, so thank you in advance. I´ve got some questions:
how about the power? mAs during writing? mAs during reading?
maximum speed?
thanks a lot!
Have not done any bench-marking, sorry.
Hello,
I followed the tutorial step by step, but when I check the file back on my PC I only get the first line written and nothing else. For some reason I’m also unable to see anything with SerialMonitor.
Great tutorial!
Is there an energia library also for the FatFs instead of the Petit FatFs (even if that consumes more resources)?
Thanks.
None so far, just the Petite FatFS version. I’m sure the normal one can be ported from an Arduino library.
But the Arduino’s SD library has utilized many libraries and translating it to MSP maybe difficult.
Hello.
I downloaded the zip folder and tried to open the *.ino file in Energia.
When i do the verify+check, there are some errors. The software can’t find the library:
“In file included from pfatfs.cpp:9:0:
/pfatfs.h:23:25: fatal error: utility/pff.h: No such file or directory
compilation terminated.”
That’s an example.
So i copied the *.h files in the same directory as the *.ino but it doesn’t work neither.
Can you help me to solve the problem ?
Thank you in advance
I had the same issue. When you download the demo code, make sure you copy all of the following files into your library folder.
utility (its a folder)
keywords.txt
pfatfs.cpp
pfatfs.h
pffconf.h
If the folder and the four files aren’t in the same directory in your library folder, the demo won’t compile
Is it possible to use SD card reader from Arduino?
Your SD card reader isout of stock!
Thanks
Yes. As per my understanding, as long as you connect the pins properly, you should be fine.
P1.6 -> master in slave out (MISO)
P1.7 -> master out slave in (MOSI)
P1.4 -> slave transit enable
P1.5 -> clock input
Hey,
I am connecting the SD card pins with SPI of Winc1500 Adafruit. But i am getting this error when i run fatsdraw…..
”
Starting the FatSD Raw example
This example requires a FAT filesystem on the SD card.
You will get errors if your SD card is not formatted with a filesystem.
Drive 0 is mounted
Reading disk information…
Error getting the free cluster count from the FatFs object”
So even if the entry per line is a small number like “XXXX”, the consumed space counts as 512Byte? (and so 1024^2/512 = 2048 lines only)
Hey Guys,
I have a hardware that uses MSP430 G2553 USCI A0. This code uses USCI B0. Does anybody can guide on how to make this code work on USCI A0 SPI?
Thank you very much for your help!!
The link you have provided to download the code is no longer available.
Can you please give an alternate link for the download?
Thank you for this tutorial.
Hey, What Changes will be there for MSP 432 Launchpad.Any Clue??As the provided method is not working…
I have a tutorial coming out on using the SDCard BoosterPack with the MSP432 Launchpad in the next week. Stay tuned!
Hi,any updates regarding MSP432 Launchpad SD card Boosterpack Tutorial.
You can find initial sample code for the MSP432 with SDCard in the forum:
http://forum.43oh.com/topic/8972-full-sd-card-fatfs-elm-chan-module-support-for-the-msp432-launchpad/
Hi Gerard,Is your tutorial out? Or When are you going to publish it?Plese help…
You can find initial sample code for the MSP432 with SDCard in the forum:
http://forum.43oh.com/topic/8972-full-sd-card-fatfs-elm-chan-module-support-for-the-msp432-launchpad/
Hi, I am trying to use this boosterpack with my MSP430F5529 LP on Code Composer Studio6. I can import the Energia code, but it’s for a different board so I can’t use it as is. I tried replacing the target config folder, with has the .ccxml for my board, as well as replaced the .cmd file in the root project folder. But now the code is all out of whack, is it possible to use this code for other boards? Thanks.
It is possible to use it for other boards, but you probably have to change/port the USC modules.
Hi guys,
I use a MSP432 launchpad from TI and a microSD Breakout Board from Adafruit. Is it possible to use the code from the website in combination with Energia or does it work only for the MSP430.
Hi Chris,
The code will not completely drop in. You will need to port the code a teeny bit and make a few changes to the hardware connections. From what I can see, you do not need any additional hardware and the Adafruit board should work. It is just a breakout board.
Hy Gerard,
i tried to fit the code with the msp432 but the energia compiler returned me this error:
C:\Users\Christoph\Downloads\energia-0101E0016-windows\energia-0101E0016/hardware/msp432/
cores/msp432/inc/msp432p401r.h:313:69: error: expected ‘)’ before ‘*’ token
#define CS ((CS_Type*) CS_BASE)
^
pfatfs.h:41:25: note: in expansion of macro ‘CS’
static unsigned char CS;
I don’t know how to solve that problem.
Do you have ideas how to solve thatz?
Hi Chris, I have some sample code in the link below, but it does not use Energia.
http://forum.43oh.com/topic/8972-full-sd-card-fatfs-elm-chan-module-support-for-the-msp432-launchpad/
Hi Gerard,
thank you for your support. 😉
Does this code also work on this Adafruit Beakout Board? (http://www.exp-tech.de/shields-module/speicher/adafruit-microsd-card-breakout-board)
But why isn’t your code supported on energia?
Greetings,
Chris
is it possible to interfae sd card in the same way as described above with msp432p401r launchpad ??
You may have to change the pins for the SPI lines on the USCI or UART channels.
Its been a while, has anyone come up with MSP432 Energia Library to interface SD card?
Suggestion on changes in library for MSP430 to work with MSP432 will also be helpful.
This interfacing looked comforting on Arduino.
I need to know how to delete the previous data stored on the sd card. I’m making data logger. when I store the big entries in the sd card on the next time when I’m reading short entries that previous data also coming. I want to remove the data which is previously stored. so anyone please give me the solution to solve it.
Would this booster be compatible with the TM4C123G launchpad?
Hi ,
I testing this library with the MSP430FR4133 LP and my own code.. the Read and Write function is working fine, But the Thing is while writing to a file only Five characters is getting written to the file i.e if I write KAMALESH only KAMAL is written to the file.
Can you post the code?
Hi ,
I testing this library with the MSP430FR4133 LP and my own code.. the Read and Write function is working fine, But the Thing is while writing to a file only Five characters is getting written to the file i.e if I write KAMALESH only KAMAL is written to the file. Can you Help me with this issuse
When I push the S2 button, it shows “Failed with rc=6”
Can you please tell me how to fix this?
Thanks