Associate II
April 4, 2020
Question
Nucleo-L476RG - SD card not creating any .txt files or any files at all. Does anyone have an example code to let the sd card work ?
- April 4, 2020
- 12 replies
- 3225 views
Hey guys,
I am pretty new to stm32 (-> beginner) and I am trying to create a .txt file on my sd card. My pc is connected by usb to the Nucleo-L476RG board, which is connected to an onboard sd card.
These are the connected pins:
/**SDMMC1 GPIO Configuration
PC8 ------> SDMMC1_D0
PC9 ------> SDMMC1_D1
PC10 ------> SDMMC1_D2
PC11 ------> SDMMC1_D3
PC12 ------> SDMMC1_CK
PD2 ------> SDMMC1_CMD
*/
I already checked the PC12 pin and saw a good working sd clk.
I have uploaded my project, which is created by CubeMX.
I appreciate any kind of help.
Thank you in advance,
Greetings
#include "main.h"
#include "fatfs.h"
ADC_HandleTypeDef hadc1;
ADC_HandleTypeDef hadc2;
DMA_HandleTypeDef hdma_adc1;
DMA_HandleTypeDef hdma_adc2;
SD_HandleTypeDef hsd1;
SPI_HandleTypeDef hspi2;
FATFS fs; /* Filesystem object */
FIL fil; /* File object */
FRESULT res; /* API result code */
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_ADC1_Init();
MX_ADC2_Init();
MX_SDMMC1_SD_Init();
MX_SPI2_Init();
MX_FATFS_Init();
/* USER CODE BEGIN 2 */
HAL_Delay(500);
/*PA12 = SD Detecteion Pin*/
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_12,GPIO_PIN_RESET);
f_mount(&fs,SDPath,1);
f_open(&fil,"text.txt",FA_CREATE_ALWAYS);
f_close(&fil);
