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.

MSP430FR5994: Using the Launchpad's SD card with SLAA281B

Part Number: MSP430FR5994
Other Parts Discussed in Thread: MSP-EXP430FR5994

Hi

I'm trying to write to, and read from, the microSD card on the MSP430FR5994 Launchpad. I have previously converted the 'Out of box experience' to use the SD card alone, but the speeds I am getting are too slow (I need to sample and store 32 bits of data at 5000Hz).  I want to try write data to sectors of the SD card without creating a file (I plan to convert it later after collecting data).

I am trying to use SLAA281B 'Interfacing the MSP430 With MMC/SD Flash Memory Cards'. I have noted from the Launchpad schematic that the SD card connections are as follows:

CS - P4.0

MOSI - P1.6

SPICLK - 2.2

MISO - P1.7

SD_DETECT - P7.2

My questions are:

1) In the libraries, it seems that MOSI, MISO and CLK are all on the same port, however they are not on this launchpad. I am unsure as to how I should go about changing this without interfering with the code operation.

2) What components of the code can I remove to optimize speed? I know I'm using SPI (USCIB0), so I've attempted to remove checks for other communication methods with little success.

3) When main.c uses 'mmcReadSector', the data isn't stored to a variable. Would a variable declared as 'char RXData[512]' suffice?

4) To determine how many total sectors are available for use, can the 'mmcReadCardSIze' function be used?

Sorry for basic questions, I am not experienced in this area.

Thank you

John

  • Part Number: MSP430FR5994

    Hi all

    I have a MSP430FR5994 Launchpad and am trying to use the on board SD card. I first tried to use the Out of Box Experience demo, but found that I couldn't get it to write fast enough. I've come across the document titled 'Interfacing the MSP430 with MMC/SD flash memory cards' (attached) which doesn't create a .txt file, instead writing to sectors. Since the SD card connections on the launchpad are different to the example code (link available in the document), I have changed the some of the code to reflect this:

    #include "msp430FR5994.h"              // Adjust this according to the      edited 28/07
                                         // MSP430 device being used.
    // SPI port definitions              // Adjust the values for the chosen
    #define SPI_PxSEL         P1SEL      // interfaces, according to the pin    edited 28/07
    #define SPI_PxDIR         P1DIR      // assignments indicated in the        edited 28/07
    #define SPI_PxIN          P1IN       // chosen MSP430 device datasheet.     edited 28/07
    #define SPI_PxOUT         P1OUT      //                                     edited 28/07
    #define SPI_SIMO          0x40       //                                     edited 28/07
    #define SPI_SOMI          0x80       //                                     edited 28/07
    #define SPI_UCLK          0x04       //                                     edited 28/07
    // SPI port definitions              // Adjust the values for the chosen
    #define MMC_PxSEL         SPI_PxSEL      // interfaces, according to the pin
    #define MMC_PxDIR         SPI_PxDIR      // assignments indicated in the
    #define MMC_PxIN          SPI_PxIN       // chosen MSP430 device datasheet.
    #define MMC_PxOUT         SPI_PxOUT      
    #define MMC_SIMO          SPI_SIMO
    #define MMC_SOMI          SPI_SOMI
    #define MMC_UCLK          SPI_UCLK
    
    // Chip Select
    #define MMC_CS_PxOUT      P4OUT     // edited 28/07
    #define MMC_CS_PxDIR      P4DIR     // edited 28/07
    #define MMC_CS            0x02      // edited 28/07
    
    // Card Detect
    #define MMC_CD_PxIN       P7IN      // edited 28/07
    #define MMC_CD_PxDIR      P7DIR     // edited 28/07
    #define MMC_CD            0x04      // edited 28/07

    I've changed MOSI to P1.6, MISO to P1.7, UCLK to P2.2, CS to P4.0, and CD to P7.2. I've also added the MSP430FR5994 header file. Additionally, I swapped the functions of CS_LOW and CS_HIGH, since the Out of Box Experience demo uses the SD card when CS is held high, whereas this example selects the card when CS is low.

    I also changed the following in mmc.c to account for the fact that MOSI and MISO are on a different port to CLK:

      // Init Port for MMC (default high)
      //MMC_PxOUT |= MMC_SIMO + MMC_UCLK;     edited 28/07
      P1OUT |= MMC_SIMO;
      P2OUT |= MMC_UCLK;
      //MMC_PxDIR |= MMC_SIMO + MMC_UCLK;     edited 28/07
      P1DIR |= 0xC0;
      P2DIR |= 0x04;
      // Enable secondary function
    #if SPI_SER_INTF != SER_INTF_BITBANG
      //MMC_PxSEL |= MMC_SIMO + MMC_SOMI + MMC_UCLK;
      P1SEL |= 0xC0;    // MOSI, MISO       edited 28/07
      P2SEL |= 0x04;    // CLK              edited 28/07
    #endif  

    The program gets stuck when running 'mmcInit' in main.c, as it seems to never return a non-zero value for the variable 'status'.

    Additionally, I would also like to comment out the following:

    #define SPI_SER_INTF      SER_INTF_BITBANG  // Interface to MMC

    And the uncomment the following, since I am using UCB0 in SPI instead of bitbanging:

    //#define SPI_SER_INTF      SER_INTF_USCIB0  // Interface to MMC

    However, when I do, I get an error stating that P1SEL is undefined. Do I need to include another file, or have I done something incorrectly?

    I have spent some time trying to get this to work, so any help is greatly appreciated. I have also attached my current program in a .zip file.

    slaa281b.pdf

    Raw SD Card Write Test.zip

  • Hi John,

    You should not be using SLAA281, the MSP-EXP430FR5994 Out of Box Experience code will be your best resource for SD card communication. If you would like to increase the SPI communication speed then change the desiredSpiClock parameter inside of HAL_SDCard to DESIRED_SPI_FAST_FREQ. You could also increase the SMCLK frequency to 16 MHz (currently 8 MHz) but this will take some additional steps to achieve.

    Edit: I've merged two threads which contain the same topic, perhaps the authors can help one another out.

    Regards,
    Ryan

  • Part Number: MSP430FR5994

    Tool/software: Code Composer Studio

    Hi all

    I’m trying to write data to the SD card of the MSP430FR5994 launchpad. I’ve been using the 'Out of Box' Experience demo, however I would like to try writing directly to sectors.

    I’ve noted that in ‘mmc.c’ the following commands are defined:

    /* MMC/SD command (SPI mode) */
    
    #define CMD0 (0)                 /* GO_IDLE_STATE */
    
    #define CMD1 (1)                 /* SEND_OP_COND */
    
    #define      ACMD41 (0x80+41)    /* SEND_OP_COND (SDC) */
    
    #define CMD8 (8)                 /* SEND_IF_COND */
    
    #define CMD9 (9)                 /* SEND_CSD */
    
    #define CMD10 (10)          /* SEND_CID */
    
    #define CMD12 (12)          /* STOP_TRANSMISSION */
    
    #define ACMD13      (0x80+13)    /* SD_STATUS (SDC) */
    
    #define CMD16 (16)          /* SET_BLOCKLEN */
    
    #define CMD17 (17)          /* READ_SINGLE_BLOCK */
    
    #define CMD18 (18)          /* READ_MULTIPLE_BLOCK */
    
    #define CMD23 (23)          /* SET_BLOCK_COUNT */
    
    #define      ACMD23 (0x80+23)    /* SET_WR_BLK_ERASE_COUNT (SDC) */
    
    #define CMD24 (24)          /* WRITE_BLOCK */
    
    #define CMD25 (25)          /* WRITE_MULTIPLE_BLOCK */
    
    #define CMD41 (41)          /* SEND_OP_COND (ACMD) */
    
    #define CMD55 (55)          /* APP_CMD */
    
    #define CMD58 (58)          /* READ_OCR */

    Through some research online, I’ve noticed some other people making use of these, but I do not fully understand it.

    ‘mmc.c’ seems to create functions to use these commands, but when I step through the 'Out of Box' Experience, they don’t seem to be used.

    Would someone be able to explain how I might use these functions to write to blocks? Or any alternative options?

    Thank you

    Vivek

  • Hi Vivek,

    mmc.c is part of the FatFs (FAT FileSystem), the commands of which are called by ff.c and utilized in sdcard.c. You do not have to worry about any of these folder/library abstraction layers but you do need to know how to properly call the sdcard.c functions to control your file system. You can use SDCardLogMode.c as an example.

    Regards,
    Ryan

**Attention** This is a public forum