//Accel Interrupt #include "driverlib.h" #include #include #include #include #include #include #define ACCEL_THRESHOLD 4000 volatile int16_t accelValue = 0; //Address if the BMI160 #define SLAVE_ADDR 0x69 //Maximum I2C buffer size #define MAX_BUFFER_SIZE 20 //Number of FFT samples #define SAMPLES 10 //#define TimeStampSample 10 #pragma PERSISTENT(input) int16_t input[SAMPLES] = {0}; //Store samples volatile uint32_t cycleCount; #define UP 0x0010 // Timer_A Up mode #define CONTINUOUS 0x0020 // Timer_A Continuous mode #define ACLK 0x0100 // Timer_A SMCLK source #define DEVELOPMENT 0x5A80 // Stop the watchdog timer #define BOUNCE_DELAY 0xA000 // Delay for Button Bounce #define MS_10 100 // Approximate value to count for 10ms #define SMCLK 0x0200 // Timer_A SMCLK source void timer_init(void) { TA0CCTL0 = CCIE; //Enable counter interrupt TA0CCR0 = 0; //Initially stop Timer by starting at 0 TA0CTL = TASSEL__SMCLK | MC__UP | ID__8; //Set clock source to ACLK, the count mode to Continuous, and the clock divider to 8 TA0EX0 = TAIDEX_7; //Set expansion clock divider to 8 TA1CCTL0 = CCIE; // TACCR0 interrupt enabled TA1CCR0 = 0; // Set count target to 0 by default // Set timer clock speed to 4.5898 ticks/s, or 16524 ticks/hour TA1CTL = TASSEL__ACLK | MC__STOP | ID__8; //Set clock source to ACLK, the count mode to Continuous, and the clock divider to 8 TA1EX0 = TAIDEX_7; //Set expansion clock divider to 8 } int delay(int count) { if(TA1CTL & TAIFG) // If Timer_1 is done counting { count = count-1; // Decrement count TA1CTL = TA1CTL & (~TAIFG); // Reset Timer_1 } return count; // Return the value of count } void UART_transmitString( char *pStr ) //Transmits a string over UART0 { while( *pStr ) { while(!(UCA0IFG&UCTXIFG)); UCA0TXBUF = *pStr; pStr++; } } typedef enum I2C_ModeEnum{ IDLE_MODE, NACK_MODE, TX_REG_ADDRESS_MODE, RX_REG_ADDRESS_MODE, TX_DATA_MODE, RX_DATA_MODE, SWITCH_TO_RX_MODE, SWITHC_TO_TX_MODE, TIMEOUT_MODE } I2C_Mode; I2C_Mode MasterMode = IDLE_MODE; uint8_t TransmitRegAddr = 0; //Register address for transmission uint8_t ReceiveBuffer[MAX_BUFFER_SIZE] = {0}; //Buffer for received values uint8_t RXByteCtr = 0; //Count received bytes uint8_t ReceiveIndex = 0; //Index of received data uint8_t TransmitBuffer[MAX_BUFFER_SIZE] = {0}; //Buffer for transmitted values uint8_t TXByteCtr = 0; //Count transmitted bytes uint8_t TransmitIndex = 0; //Index of transmitted data void CopyArray(uint8_t *source, uint8_t *dest, uint8_t count) { uint8_t copyIndex = 0; for (copyIndex=0; copyIndex ACCEL_THRESHOLD) { // Display accelerometer value printf("Accelerometer value: %d\n", accelValue); } /* printf("Reading samples\n"); //Read SAMPLES amount of data from the BMI160 for(i=0;i