I'm designing a data recorder application which uses an 8-bit AVR microcontroller. It uses the TWI and SPI interfaces with the microcontroller being the master. There is one SPI device, a microSD card, and one TWI device, the MMA8452 accelerometer. The accelerometer is going to be sampled at
400~800 Hz, and I plan on storing relatively large amounts of data so there will be semi-frequent writes to the microSD card as the uC's memory gets filled.
My question is what is the recommended workflow for enabling/disabling the interfaces. Can I keep the SS for the SPI interface asserted low throughout my application, or should I only keep it active when I'm interfacing with the microSD card?
Also, can I keep the TWI/SPI master interfaces enabled, or should I enable them only when the interface is required?
ex. code (for TWI, similar for SPI):
// enable/disable during each operation twi_master_enable(&TWIC); // ... TWI-related operations twi_master_disable(&TWIC);
Or, is this better:
// initialization/wake-up code twi_master_enable(&TWIC); // .. somewhere else in the code, perform TWI operations // power-down/sleep code twi_master_disable(&TWIC);