2017-02-22 12:18 AM
Posted on February 22, 2017 at 09:18
Hey all,
I want to write to SD card, I'm Using cube-mxstm32Nucleo-L476RG MCU ,and 4-pin SD card,
I attach my cube project, the main program has the following code:
declaring and init :
FATFS SDFatFs;
FIL MyFile;
extern char SD_Path[4]; /* SD logical drive path */
/* USER CODE END 0 */
int main(void)
{
/* USER CODE BEGIN 1 */
FRESULT res;
uint32_t byteswriten,byteread;
uint8_t wtext[]='Hello from STM32!!\0';
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_DFSDM1_Init();
MX_SDMMC1_SD_Init();
MX_FATFS_Init();
MX_TIM6_Init();
MX_SDMMC1_SD_Init();
I am trying to write to sd card by the following code:
if(res=f_mount(&SDFatFs,(TCHAR const*)SD_Path,0)!=FR_OK)
{
Error_Handler();
}
else
{
if(res=f_open(&MyFile,'0:/mywrite.txt',FA_CREATE_ALWAYS | FA_WRITE ) != FR_OK)
{
Error_Handler();
}
else
{
res=f_write(&MyFile,wtext,sizeof(wtext),(void*)&byteswriten);
if((byteswriten==0) || (res!=FR_OK))
{
Error_Handler();
}
else
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
}
f_close(&MyFile);
}
}
I get FR_NO_FILESYSTEM if the SD is connected and if the SD is not connected, I get FR_NOT_READY,
Thanks for any help.
Note: this post was migrated and contained many threaded conversations, some content may be missing.
2018-05-16 07:02 AM
The stm32_adafruit_sd.c code in the HAL trees should support SDHC/XC (>= 4GB) cards via SPI. The larger cards use a slightly different command/protocol to address the blocks on the media.
STM32Cube_FW_F4_V1.19.0\Drivers\BSP\Adafruit_Shield\stm32_adafruit_sd.c
I've used this code on NUCLEO boards to support MicroSD cards. I don't have the shield but wired the socket using equivalent pins.
FatFS should support FAT32 volumes with usually settings, for >=64GB media you'd want to enable EXFAT support
2018-05-16 07:22 AM
i am using stm32f103ze controller,in my code option is their for fat32 operation,i dont know why it is not working for 8gb card,so if u have any fat technical specifications pdf or fat tutorial can u send me.
THANKS FOR THE HELP
2018-05-16 08:18 AM
It's not working because the SPI-SD code you are using only supports SD cards, the SDHC and SDXC cards use a slightly different protocol, and are not compatible with code that only uses the old protocol.
The SPI code I have cited supports BOTH class of cards, you'll need to use that as the basis for your own solution.
2018-05-17 12:10 AM
thanks clive,i need a site for entire project for accesing sd card using spi + fat32 for stm32103zc controller.if u have that info plz share it.
2018-05-21 06:32 AM
Hi Clive One,
I AM WRITING DATA TO WORD DOCUMENT AND EXCEL DOCUMENT USING SD+SPI+FAT DRIVER,BUT IN EXCEL DOCUMENT ,ALL THE DATA(40KB) IS GETTING STORED IN FIRST BLOCK ONLY,HOW TO CHANGE THE BLOCK TO STORE DATA BY INCREMENT ROW AND COLUMN.
THANK YOU