I am interfacing with an SD card and a CAN interface chip (the MCP2515) on an SPI interface. For speed of writing, I am using a FAT library and opening a file to stream to. If I temporarily stop streaming data to the SD card to gather data from the CAN chip, resuming the card writes causes corruption of the file.
I cannot see why the two interact with each other. If at the lowest level there is no overlap in pulling the CS pins low for each device, surely the SD card would effectively be blind to what was happening on the SPI bus. I have confirmed releasing the CS pin of the SD card is not causing any issue, nor pulling the SC pin of the CAN interface chip. It is only with an SPI transfer that the SD card writing becomes corrupted.
Is this a problem of electronics, or is this more likely a firmware/library issue that I am facing?
- Microprocessor: ATmega2560
- CAN Interface: MCP2515
- SD Card: Transcend 4GB C10 MicroSD HC
- SD Card level shifter: 74hc4050
The writes are done in complete 512 byte chunks, aligned with the blocks on the SD card. The symptom of failure is that the next block written returns a failure to write. I have not been able to decipher the meaning of the fault yet, though two codes are returned for each failure. These may be generated by the SD card itself bud I do not know yet:
- 0xFF, 0xE0, 0x7F or 0x3F
Once the SD write completes, its CS pin is pulled high before the CAN CS pin goes low. Once the CAN operations are complete and the CS pins are swapped. Though this is when the fault occurs.