I am using nucleo-f401re board for my project and I want to write sensor data to SD card. I am writing data when sensor interrupts occur, and that happens at 408 Hz, so I have around 2 ms to write data. I am using SPI at max frequency to communicate with SD card reader, I am using micro SD card reader module for mounting SD card. I am only using 1 interrupt which reads sensor data and sets flag, writing is occurring in while(1). Everything seems to work fine and writing finishes before next interrupt arrives, but every 8-9 writing cycle, writing function takes way longer than normally and I lose 1 data sample:
As you can see, yellow signal is my while cycle and that short pulse is writing time, except when 1 writing cycle takes 2.34 ms. Blue is my interrupt, I must write during low state of blue and finish it before new high level arrives. Why this keep happening? As I said, this longer writing occurs every 8, sometimes 9 writing cycle. Is there a way to fix it, or this is FATFS problem? I know that this occurs during FATFS write because I debugged it, I keep my file open all the time when I am gathering data.