Interrupt during write to SD card


I'm trying to build a CAN-bus datalogger with the CAN shield, which writes all messages to a SD card.

Because of the relatively long time of writing a 512 byte block to the SD, I would like to interrupt this process when there is a new CAN message available, so I won't miss any CAN messages during writing to the card. The CAN message will be temporarily stored in a buffer.

The problem is that once there is an interrupt, the CS (chip select) input from the SD card is set HIGH during a write cycle (first the current byte is finished, after that the CS becomes HIGH), the SD card still goes on writing bytes. In the interrupt routine there is SPI communication with the CAN controller (20 bytes).

I connected a logic analyzer which shows that the status byte after the 512 bytes block is coming 20 bytes earlier. It looks like the SD card still writes bytes at every 8 clock cycles, however the CS of the card is HIGH.

Any ideas how to solve this issue, so I can interrupt the SPI communication and use the bus for communication with the CAN controller?