60,6 → 60,12 |
/* --- Initialize I/O Ports ------------------------- */ |
P2SEL = 0x0; // P2SEL resets to 0xC0 |
|
// SPI Pins (idle low) |
SPI_PxOUT &= ~(SPI_SIMO + SPI_SOMI + SPI_UCLK); |
SPI_PxDIR |= SPI_SIMO + SPI_UCLK; |
SPI_PxDIR &= ~SPI_SOMI; |
SPI_PxREN |= SPI_SOMI; |
|
// SD Chip Select (idle high) |
MMC_CS_PxOUT |= MMC_CS; |
MMC_CS_PxDIR |= MMC_CS; |
86,7 → 92,6 |
ADXL_INT1_PxDIR &= ~ADXL_INT1; |
ADXL_INT1_PxIES |= ADXL_INT1; // Interrupt on High -> Low |
ADXL_INT1_PxIFG &= ~ADXL_INT1; // Clear interrupt flag |
ADXL_INT1_PxIE |= ADXL_INT1; // Enable interrupt |
|
// Accelerometer Interrupt 2 (input) |
ADXL_INT2_PxDIR &= ~ADXL_INT2; |
116,11 → 121,12 |
FATFS fs; |
FRESULT result = FR_NOT_READY; |
|
// Delay for a bit to ensure that SD card powers up |
__delay_cycles(16000); |
|
// Init SPI Module |
halSPISetup(); |
|
// __delay_cycles(32000000); |
|
// Attempt the startup procedure four times |
int i; |
for (i = 0; i < 4; i++) { |
171,18 → 177,21 |
} |
|
// If everything is ok, enable accelerometer interrupts |
if (status == 0) { |
ADXLInitInterrupts(); |
} else { |
if (status != 0) { |
// Otherwise turn off everything |
LED_RED_HIGH(); |
void ADXLStandbyOn(void); |
|
} else { |
ADXL_INT1_PxIE |= ADXL_INT1; // Enable interrupt |
ADXLInitInterrupts(); |
} |
|
// LED_RED_HIGH(); |
// Turn off all chips except the accelerometer |
CHIP_RESET_LOW(); |
_BIS_SR(LPM4_bits + GIE); |
|
while(1); |
} |
|
#pragma vector=PORT1_VECTOR |
190,8 → 199,6 |
|
if (ADXL_INT1_PxIFG & ADXL_INT1) { |
LED_GREEN_HIGH(); |
__delay_cycles(1000000); |
LED_GREEN_LOW(); |
|
// Bring chips out of low-power state |
CHIP_RESET_HIGH(); |
205,8 → 212,13 |
// Return chips to low-power state |
CHIP_RESET_LOW(); |
|
// Clear the interrupts on the ADXL chip |
ADXLClearInterrupts(); |
|
// Clear the interrupt flag |
ADXL_INT1_PxIFG &= ~ADXL_INT1; |
|
LED_GREEN_LOW(); |
} |
|
// if (ADXL_INT2_PxIFG & ADXL_INT2) { |
218,5 → 230,4 |
// ADXL_INT2_PxIFG &= ~ADXL_INT2; |
// } |
|
ADXLClearInterrupts(); |
} |