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.

MSP-EXP430FR4133: SD Card Interfacing using SPI to read audio .wav files

Part Number: MSP-EXP430FR4133

Hi all, im hoping for some guidance, im currently trying to communicate via SPI to an external SD card reader with a 4GB Card installed, in this case SDHC would apply ( i think thats correct ).
I have downloaded the needed FATF32 Libraries, included them in my code, alongside a third party MSP430 library for most boards with the correct selection of Pins I/O for SPI configuration. Im struggling with the implementation of some FATF functions and as wondering if anyone could help me out :). 

I have linked my code below and after that i have uploaded the errors which i am facing. 

Using IAR Embedded Workbench IDE 

#include "msp430.h"
#include "msp430_spi.h"  // Include your SPI library
#include "ff.h"         // Include FatFs library for SD card access
#include "diskio.h"     // Include low-level disk I/O functions
#include "userconfig.h"
#include "stdio.h"


#define BUFFER_SIZE 512  // Define buffer size for reading data from SD card
#define SPI_CS BIT3  // Chip select pin

#define CMD0 0x40
#define CMD8 0x48
#define ACMD41  (41 | 0x80)

#define R1_IDLE_STATE 0x01
#define CMD58 0x3A

// Function prototypes
uint8_t send_command(uint8_t cmd, uint32_t arg);
uint8_t read_response(uint8_t *response, uint8_t num_bytes);


// Function prototypes
void sd_card_init();

int main(void) {
    FRESULT result;          // FatFs function result
    FATFS fs;                // File system object
    FIL file;                // File object
    BYTE buffer[BUFFER_SIZE];  // Data buffer for reading from file

    // Disable watchdog timer
    WDTCTL = WDTPW + WDTHOLD;

    // Initialize MSP430 SPI
    spi_init();

    // Initialize SD card
    sd_card_init();

    // Mount the SD card
    result = f_mount(&fs, "", 0);
    if (result != FR_OK) {
        // Error handling
        return 1;
    }

    // Open the text file for reading
    result = f_open(&file, "Test.txt", FA_READ);
    if (result != FR_OK) {
        // Error handling
        return 1;
    }

    // Read data from the file
    UINT bytesRead;
    result = f_read(&file, buffer, BUFFER_SIZE, &bytesRead);
    if (result != FR_OK) {
        // Error handling
        f_close(&file);
        return 1;
    }

    // Close the file
    f_close(&file);

    // Process the data read from the file
    // For example, you can print it to the console
    int i;
    for (i = 0; i < bytesRead; i++) {
        putchar(buffer[i]);  // Assuming UART is used for output
    }

    // End of program
    return 0;
}

// Initialize SD card
void sd_card_init() {
    // Chip select low to select SD card
    P1OUT &= ~SPI_CS;

    // Delay for at least 74 clock cycles (about 1 ms)
    __delay_cycles(1000);

    // Send CMD0 (GO_IDLE_STATE) command
    send_command(CMD0, 0);

    // Send CMD8 (SEND_IF_COND) command
    send_command(CMD8, 0x000001AA);  // CMD8 with argument 0x1AA (voltage range 2.7-3.6V)

    // Read R7 response to CMD8
    uint8_t response[5];
    if (read_response(response, 5) != 0) {
        // Error handling
        return;
    }

    // Verify that SD card is version 2.x and voltage range is supported
    if ((response[2] != 0x01) || (response[3] != 0xAA)) {
        // Error handling
        return;
    }

    // Send ACMD41 (SD_SEND_OP_COND) command until card is ready
    // (loop until card returns R1_IDLE_STATE indicating initialization complete)
    while (send_command(ACMD41, 0) != R1_IDLE_STATE);

    // Send CMD58 (READ_OCR) command to read OCR register
    send_command(CMD58, 0);

    // Read R3 response to CMD58
    if (read_response(response, 5) != 0) {
        // Error handling
        return;
    }

    // Verify SDHC or SDXC card (check CCS bit in OCR)
    if (response[1] & 0x40) {
        // SDHC or SDXC card detected
    } else {
        // Standard capacity SD card detected
    }

    // Chip select high to deselect SD card
    P1OUT |= SPI_CS;
}

	Error[e46]: Undefined external "f_read" referred in main (C:\Users\*****\Documents\SPI_Code\Debug\Obj\main.r43).			

This error occurs for all the functions 'f_open f_close f_read etc.

**Attention** This is a public forum