2026-02-03 1:09 PM
Hello everyone,
I'm working on a data logging project using a NUCLEO-L432KC board and a standard Micro-SD card module.
I have a very frustrating issue: Reading from the SD card works perfectly, but Writing fails immediately.
MCU: STM32L432KC (Nucleo-32 board)
SD Module: Generic MicroSD Card Module (with 5V to 3.3V regulator and level shifter).
Power: Module is powered via the 5V rail from the Nucleo. I added a 1000µF / 25V electrolytic capacitor in parallel on the breadboard to prevent any power drops (brown-outs) during write operations.
Pinout: * SCK: PB3
MISO: PB4
MOSI: PA7
CS: PB6 (Software managed)
Library: FatFS R0.12c (via STM32CubeIDE).
FatFS Config: _FS_READONLY = 0 (Disabled), _FS_LOCK = 0.
SPI Config: MSB First, CPOL Low, CPHA 1 Edge, Baud Rate 125.0 Kbits/s for init.
GPIO: SPI pins are set to "High" output speed.
My code successfully initializes the SD card. f_mount returns FR_OK, and f_getfree correctly reports the total and free space (approx. 1.18 GB).
However, when I try to write:
f_open works (FR_OK).
f_puts immediately returns EOF (-1).
f_sync fails with Error Code 9 (FR_INVALID_OBJECT).
Here is my debug log:
DEBUG: CMD0 sent. Reponse = 0x01
SD Card Mounted Successfully!!!
TotalSpace : 1185923072 bytes, FreeSpace = 1185906688 bytes
Writing data!!!
ERREUR: f_puts KO. sd card full or lock.
ERREUR CRITIQUE f_sync (9) : Voltage drop or spi crash.
Erreur fermeture fichier : (9)
Read Data :
Closing File!!!Formatted the SD card to FAT32 (MBR) using the official SD Memory Card Formatter.
Kept the SPI speed slow (SPI_Fast(); is commented out).
Added the 1000µF capacitor to the 5V line.
Some people suggested this could be a MISO line issue (missing pull-up resistor, or the 5V logic level shifter messing with the "Data Accepted" token during the write process). Since reading works, MISO works for general data, but maybe not for the write confirmation token?
Has anyone experienced this specific "Read OK / Write Fail" behavior with these 5V modules? Should I add a pull-up on PB4?
Any help would be greatly appreciated! Thank you.
More info:
2026-02-03 1:26 PM
I just tried to change SCK to PA5 and add pull-up on MISO, not working ...