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.

MSP430F5638: Driving a microsd card via SPI from MSP430F5638

Part Number: MSP430F5638
Other Parts Discussed in Thread: MSP430FR5994

Using an MSP430F5638 on a custom SBC driving a graphical LCD - this is running fine. Trying to use the TI SLAA281C.pdf example notes and related code to read and write from a microSD card via P8 and UCB1 SPI. I've looked at the 3 other cases that refer to SLAA281C and they are only partially helpful. 

The SLAA281C example uses BITBANG by default to communicate with the card. This builds in CCS v10, loads into the MCU and displays data on the LCD. But I'm using UCB1 SPI, so must change the code for that.

Not using DMA, so it's disabled.

Changed header files to those appropriate for the F5638 and the SBC

Changed #define SPI_SER_INTF  SER_INTF_BITBANG   to #define SPI_SER_INTF  SER_INTF_USCIB1

Changed example P5 to P8, and the pins I'm using for SPI: P8.1 UCB1STE, P8.4 UCB1CLK, P8.5 UCB1SIMO, P8.6 UCB1SOMI

CCS v10 gets build errors for the following variables or constants, typically not defined

halSPITXDONE, IFG1, U0RXBUF, U0TXBUF, UCB1MCTL, URXIFG0, UTXIFG0

I've tried numerous variations of declaring these specific variables or constants in different places in the files, but can't get a clean build.

Can you provide any insight as to where these items need to be declared and used?

  • Look at the header file (msp430f5638.h) to see how the serial registers are defined. I see UCA0, UCA1, UCB0, and UCB1

    grep TXBUF /usr/ti/gcc/include/msp430f5638.h
    sfr_b(UCA0TXBUF);                             /* USCI A0 Transmit Buffer */
    sfr_b(UCB0TXBUF);                             /* USCI B0 Transmit Buffer */
    sfr_b(UCA1TXBUF);                             /* USCI A1 Transmit Buffer */
    sfr_b(UCB1TXBUF);                             /* USCI B1 Transmit Buffer */

  • Generally for these kinds of issues, go to the project that is working, right click on one of the names not found in the new project and select "show declaration" - sometimes you have to do it a few times. The file containing the definition will show up, in this case the one David indicates.

  • Hi Ted Fryberger,

    On the hal_MMC_hardware_board.h are you including the #include <msp430.h> or you could use #include "msp430f5638.h" to be just your device?  Because, you're having the common constants undefined it seems to be an include issue. David's code section is showing on the msp430f5638.h include which is what defines a lot of those variables/constants. 

    Regards,

    Luke

  • Thanks to all for your responses. I've already included msp430f5638.h in both main.c and hal_MMC_hardware_board.h.

    I have used "open declaration" or "open resource" to find identifiers in the code. Right now CCS is not finding UCRXIFG and UCTXIFG - and both are clearly defined in msp430f5638.h under UCBxIFG control bits. I will dive into this file more deeply.

    Part of my problem is not understanding clearly how these pieces need to fit together: SPI + MMC + MicroSD card. And the P8 UCB1 SPI port is working by itself, sending data to a data sniffer.

  • The use of "MMC" is a red flag so I dug up the code and you will have to modify that to work with modern cards. It certainly will not work with a SDHC card. A copy of the SDHC specification will help. www.sdcard.org/.../

    SDHC addresses data in blocks and the initialization flow is different.


    I have been down that road once or twice. Beginning back when MMC cards were still a thing. (I have a 64MB MMC card gathering dust.) My most recent MSP430 effort is in Forth instead of C.

  • David, thanks for your latest post. I'm going to punt on TI's MMC code for now. TI might want to add a note to SLAA281C stating that it is dated, and will require modifications to work with current microSD cards. It's still a good general reference and overview. Also spent quite a bit of time trying to get Elm Chan's examples running - so far unsuccessfully. There is a ton of info online about programming microSD cards and all of it is dated - 8 to 15 years old, with lots of holes where they completely skip over critical steps. All are helpful as an overview with some detail here and there.

    I'm going to contact the sdcard.org and see if they have any current examples or recommendations, also revisit Elm Chan to look for any newer examples.

    Has anyone gotten an MSP430 reading & writing to a microSD card via SPI & C in recent years? Or know of any other good reference sources?

  • It isn't too difficult. I have done it several times starting with the SparkFun Logomatic. (I looked at that for the first time in a while. It appears to do the SD 2.0 initialization except for the capacity bit so should be easily changed for SDHC.) Then in Forth for the MSP430. Which formed the basis of the version for the Teensy. That doesn't use SPI but instead its SD hardware.

    The flow chart of the initialization process in the SD spec isn't too hard to follow. Plus you are probably safe in leaving out code to init MMC or SD 1.0 cards.

  • David, Thanks for the SparkFun link, I'll take a look at that.

  • Hi Ted,

    Were you able to fix the define errors you were getting earlier? 

    We also have some code (not for this device directly) that involves the SD card if you want some reference material. You can find it from the MSP-EXP430FR5994_Software_Examples under the Firmware/Source/OutOfBox_MSP430FR5994. There's the obvious files with SD in the name but, there is also the SD configuration in the HAL file. This code is for the MSP430FR5994 so it will not work directly with your device and should only serve as a reference.

    Regards,

    Luke

  • Luke, Thanks for the update. I gave up on porting the SLAA281C, according to David, there have been many changes over the years and it will not easily support the newer SD cards without lots of mods. I'll take a look at your MSP430FR5994 link, anything that supports the 430 should be closer than the many (very old) online references to other MCU's.

    Elm Chan does have a 4/2021 update and I'm looking at that too - although his code is MCU agnostic. Also Joonas Pihlajamaa has a useful 4 part tutorial on basic SD card control at

    https://codeandlife.com/2012/04/02/simple-fat-and-sd-tutorial-part-1/  which I'm also looking at.

    So far the only thing that has worked is TI's MSP432 launch pad + BOOSTXL card - that works perfectly! But was not successful porting the code to the 430.

  • The MSP432 and MSP430 don't mix too well when trying to port a 1 to 1. They have different cores (MSP432 uses ARM, MSP430 uses TI) so they can't directly port into each other. The MCU agnostic and the MSP430FR5994 would be your best resources, though the MSP430FR5994 uses FRAM instead of flash for its main memory so, that is another important factor depending on your implementation.

  • Luke, thanks for the update. I bought a MSP430FR5994 LaunchPad which is running fine in Live Temp, and FRAM log modes from the GUI. But can't get it running in SDCard log mode. 

    Assume it can use FAT32 formatted 32GB & 64GB microSD cards. Sounds like you have to run it like running FRAM Log mode. Power up LP and press S1 + S2 twice to get into mode 3 SDCard, connect GUI and start SDCard mode from GUI, I see 3 flashes on the Red LED, run for a short time, press S2 to stop, reconnect GUI and load SDCard data. But GUI says there is no data to load. Viewing card from Win also shows no additional data.

    What am I missing?

**Attention** This is a public forum