I am trying to put MSP430FR6889 in sleep mode and wake it up using an external Accelerometer (BMI160). Whenever someone moves the Accel, MSP430 should wake up and read the accel to process the data.BMI 160: https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmi160-ds000.pdf
I have so far tried to read accelerometer and process data but interrupt and waking up is not working.
// Sequence and Unique headers Working//#define GLOBAL_Q 15//#include "IQmathLib.h"//#include "QmathLib.h"//#include <msp430.h>#include "driverlib.h"#include <gpio.h>#include <intrinsics.h>#include <msp430fr5xx_6xxgeneric.h>#include <stdint.h>#include <stdio.h>//#define GLOBAL_Q 15//#include "QmathLib.h"//_iq15 q15FFT;//_iq15 q15Amp; // Q variables using Q15 type//volatile float qFFT_out;//volatile float qAmp_out;//new//#include "myClocks.h"//new//******************************************************************************// Defines *********************************************************************//******************************************************************************//Address if the BMI160#define SLAVE_ADDR 0x69//Maximum I2C buffer size#define MAX_BUFFER_SIZE 20//Number of FFT samples#define SAMPLES 1024//#define TimeStampSample 10/* Declare as persistent to move variable from RAM to FRAM */#pragma PERSISTENT(input)int16_t input[SAMPLES] = {0}; //Store samples#pragma PERSISTENT(max)int16_t max[SAMPLES] = {0}; //Store frequencies with maximum amplitudes#pragma PERSISTENT(amp)int16_t amp[SAMPLES] = {0}; //Store the maximum amplitudes/* Temporary data array for processing */DSPLIB_DATA(temp,4)/* Declare as persistent to move variable to FRAM */#pragma PERSISTENT(temp)int16_t temp[3*SAMPLES/2] = {0};//Global flags for sensor interrupts to avoid interrupt nestingvolatile int motion_trigger = 0;/* Benchmark cycle counts */volatile uint32_t cycleCount;#pragma PERSISTENT(SENSORTIME)volatile int32_t SENSORTIME[SAMPLES] = {0}; //Store samples//Store received data from NeoCortecvolatile int receiveData = 0;unsigned int temperature;volatile float temperatureDegC;unsigned int battery;volatile float voltage;#define CALADC12_12V_30C *((unsigned int *)0x1A1A) // Temperature Sensor Calibration-30 C //See device datasheet for TLV table memory mapping#define CALADC12_12V_85C *((unsigned int *)0x1A1C) // Temperature Sensor Calibration-85 C//new#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//new//******************************************************************************// Frequency Functions *********************************************************//******************************************************************************void bubbleSort(int amp[], int max[], int n){ int i, j, temp; for (i = 0; i < n-1; i++) { // Last i elements are already in place for (j = 0; j < n-i-1; j++) { if (amp[j] < amp[j+1]) { temp = max[j]; max[j] = max[j+1]; max[j+1] = temp; temp = amp[j]; amp[j] = amp[j+1]; amp[j+1] = temp; } } }}void getMaximums(int16_t input[], int samples, int16_t max[], int16_t amp[]){ int i,j = 0; for(i=1; i<samples-1; i++) { if((input[i-1] < input[i]) && (input[i] > input[i+1])) { amp[j] = input[i]; max[j++] = i; } } bubbleSort(amp, max, samples);}//******************************************************************************// Timer Functions *************************************************************//******************************************************************************//******************************************************************************// Timer Functions *************************************************************//******************************************************************************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} // end delay//******************************************************************************// UART Functions **************************************************************//******************************************************************************void UART_transmitString( char *pStr ) //Transmits a string over UART0{ while( *pStr ) { while(!(UCA0IFG&UCTXIFG)); UCA0TXBUF = *pStr; pStr++; }}//******************************************************************************// I2C Functions ***************************************************************//******************************************************************************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;/* Used to track the state of * the software state * machine*/I2C_Mode MasterMode = IDLE_MODE;uint8_t TransmitRegAddr = 0; //Register address for transmissionuint8_t ReceiveBuffer[MAX_BUFFER_SIZE] = {0}; //Buffer for received valuesuint8_t RXByteCtr = 0; //Count received bytesuint8_t ReceiveIndex = 0; //Index of received datauint8_t TransmitBuffer[MAX_BUFFER_SIZE] = {0}; //Buffer for transmitted valuesuint8_t TXByteCtr = 0; //Count transmitted bytesuint8_t TransmitIndex = 0; //Index of transmitted datavoid CopyArray(uint8_t *source, uint8_t *dest, uint8_t count){ uint8_t copyIndex = 0; for (copyIndex=0; copyIndex<count; copyIndex++) { dest[copyIndex]=source[copyIndex]; }}I2C_Mode I2C_Master_ReadReg(uint8_t dev_addr, uint8_t reg_addr, uint8_t count){ //printf("R\n"); /* Initialize state machine */ MasterMode = TX_REG_ADDRESS_MODE; TransmitRegAddr = reg_addr; RXByteCtr = count; TXByteCtr = 0; ReceiveIndex = 0; TransmitIndex = 0; /* Initialize slave address and interrupts */ UCB1I2CSA = dev_addr; UCB1IFG &= ~(UCTXIFG + UCRXIFG); // Clear any pending interrupts UCB1IE &= ~UCRXIE; // Disable RX interrupt UCB1IE |= UCTXIE; // Enable TX interrupt UCB1CTLW0 |= UCTR + UCTXSTT; // I2C TX, start condition __bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupts // UCB1IE &= ~UCRXIE; // Disable RX interrupt return MasterMode;}I2C_Mode I2C_Master_WriteReg(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t count){ /* Initialize state machine */ MasterMode = TX_REG_ADDRESS_MODE; TransmitRegAddr = reg_addr; //Copy register data to TransmitBuffer CopyArray(reg_data, TransmitBuffer, count); TXByteCtr = count; RXByteCtr = 0; ReceiveIndex = 0; TransmitIndex = 0; /* Initialize slave address and interrupts */ UCB1I2CSA = dev_addr; UCB1IFG &= ~(UCTXIFG + UCRXIFG); // Clear any pending interrupts UCB1IE &= ~UCRXIE; // Disable RX interrupt UCB1IE |= UCTXIE; // Enable TX interrupt UCB1CTLW0 |= UCTR + UCTXSTT; // I2C TX, start condition __bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupts //printf("W\n"); return MasterMode;}//******************************************************************************// BMI160 Functions ************************************************************//******************************************************************************void bmi160_init(char FOC_axis){ uint8_t writeData[1]; //Read Chip ID, which is D1 I2C_Master_ReadReg(SLAVE_ADDR, 0x00, 1); if(ReceiveBuffer[0] != 0xD1) { UART_transmitString(" Incorrect sensor chip ID "); printf("Incorrect sensor chip ID\n"); } //Configure the accelerometer writeData[0]=0b00101000; //Set acc_us to 0 for off, and acc_bwp must then be 010. Set acc_odr to 1011(800Hz),1100(1600Hz),1000(100Hz),0001(25/32Hz) I2C_Master_WriteReg(SLAVE_ADDR, 0x40, writeData, 1); //Check if configuration worked I2C_Master_ReadReg(SLAVE_ADDR, 0x40, 1); if(ReceiveBuffer[0] != writeData[0]) { UART_transmitString(" Accelerometer config failed "); printf("Accelerometer config failed\n"); } //Set the range of the accelerometer writeData[0]=0b1000; //0b0011 for 2g, 0b0101 for 4g, 0b1000 for 8g I2C_Master_WriteReg(SLAVE_ADDR, 0x41, writeData, 1); //Check if range is set I2C_Master_ReadReg(SLAVE_ADDR, 0x41, 1); if(ReceiveBuffer[0] != writeData[0]) { UART_transmitString(" Accelerometer range set failed "); printf("Accelerometer range set failed\n"); } //Set the Accelerometer to normal power mode writeData[0] = 0x11; I2C_Master_WriteReg(SLAVE_ADDR, 0x7E, writeData, 1); //Read power mode status of sensors I2C_Master_ReadReg(SLAVE_ADDR, 0x03, 1); if(ReceiveBuffer[0] != 0x10) { UART_transmitString(" Accelerometer not on "); printf("Accelerometer not on\n"); }}//******************************************************************************// Device Initialization *******************************************************//******************************************************************************void initGPIO(){ /* Terminate all GPIO pins to Output LOW to minimize power consumption */ GPIO_setAsOutputPin(GPIO_PORT_PA, GPIO_PIN_ALL16); GPIO_setAsOutputPin(GPIO_PORT_PB, GPIO_PIN_ALL16); GPIO_setAsOutputPin(GPIO_PORT_PC, GPIO_PIN_ALL16); GPIO_setAsOutputPin(GPIO_PORT_PD, GPIO_PIN_ALL16); GPIO_setAsOutputPin(GPIO_PORT_PE, GPIO_PIN_ALL16); GPIO_setAsOutputPin(GPIO_PORT_PF, GPIO_PIN_ALL16); GPIO_setOutputLowOnPin(GPIO_PORT_PA, GPIO_PIN_ALL16); GPIO_setOutputLowOnPin(GPIO_PORT_PB, GPIO_PIN_ALL16); GPIO_setOutputLowOnPin(GPIO_PORT_PC, GPIO_PIN_ALL16); GPIO_setOutputLowOnPin(GPIO_PORT_PD, GPIO_PIN_ALL16); GPIO_setOutputLowOnPin(GPIO_PORT_PE, GPIO_PIN_ALL16); GPIO_setOutputLowOnPin(GPIO_PORT_PF, GPIO_PIN_ALL16); // I2C pins (P4.0 is SDA, P4.1 is SCL) P4SEL1 |= BIT0 | BIT1; P4SEL0 &= ~(BIT0 | BIT1); // Configure P3.4 and P3.5 to UART (Primary, TX and RX respectively) for NeoCortec P3SEL0 |= BIT4 | BIT5; // USCI_A1 UART operation P3SEL1 &= ~(BIT4 | BIT5); // SEL1 is 0 and SEL0 is 1 for primary operation, inverse for secondary // Configure P2.0 and P2.1 to UART (Primary, TX and RX respectively) for PC //P2SEL0 |= BIT0 | BIT1; // USCI_A0 UART operation //P2SEL1 &= ~(BIT0 | BIT1); // SEL1 is 0 and SEL0 is 1 for primary operation, inverse for secondary //// Configure button S1 (P1.1) interrupt //GPIO_selectInterruptEdge(GPIO_PORT_P1, GPIO_PIN1, GPIO_HIGH_TO_LOW_TRANSITION); //GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1); //GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN1); //GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN1); //// Configure button S2 (P1.2) interrupt //GPIO_selectInterruptEdge(GPIO_PORT_P1, GPIO_PIN2, GPIO_HIGH_TO_LOW_TRANSITION); //GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN2); //GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN2); //GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN2); // Configure CTS active (P1.3) interrupt GPIO_selectInterruptEdge(GPIO_PORT_P1, GPIO_PIN3, GPIO_HIGH_TO_LOW_TRANSITION); GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN3); GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN3); GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN3); // Configure Nwu (P1.4) interrupt GPIO_selectInterruptEdge(GPIO_PORT_P1, GPIO_PIN4, GPIO_HIGH_TO_LOW_TRANSITION); GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN4); GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN4); GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN4); //// Configure INT1 (P3.2) interrupt //GPIO_selectInterruptEdge(GPIO_PORT_P3, GPIO_PIN2, GPIO_HIGH_TO_LOW_TRANSITION); //GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P3, GPIO_PIN2); //GPIO_clearInterrupt(GPIO_PORT_P3, GPIO_PIN2); //GPIO_enableInterrupt(GPIO_PORT_P3, GPIO_PIN2); //// Configure INT2 (P2.5) interrupt //GPIO_selectInterruptEdge(GPIO_PORT_P2, GPIO_PIN5, GPIO_HIGH_TO_LOW_TRANSITION); //GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P2, GPIO_PIN5); //GPIO_clearInterrupt(GPIO_PORT_P2, GPIO_PIN5); //GPIO_enableInterrupt(GPIO_PORT_P2, GPIO_PIN5); // Disable the GPIO power-on default high-impedance mode to activate // previously configured port settings PM5CTL0 &= ~LOCKLPM5; __bis_SR_register(GIE);}void initClockTo16MHz(){ // Configure one FRAM waitstate as required by the device datasheet for MCLK // operation beyond 8MHz _before_ configuring the clock system. FRCTL0 = FRCTLPW | NWAITS_1; // Clock System Setup CSCTL0_H = CSKEY_H; // Unlock CS registers CSCTL1 = DCOFSEL_0; // Set DCO to 1MHz // Set SMCLK = MCLK = DCO, ACLK = VLOCLK (9.4kHz) CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK; // Per Device Errata set divider to 4 before changing frequency to // prevent out of spec operation from overshoot transient CSCTL3 = DIVA__4 | DIVS__4 | DIVM__4; // Set all corresponding clk sources to divide by 4 for errata CSCTL1 = DCOFSEL_4 | DCORSEL; // Set DCO to 16MHz // Delay by ~10us to let DCO settle. 60 cycles = 20 cycles buffer + (10us / (1/4MHz)) __delay_cycles(60); CSCTL3 = DIVA__32 | DIVS__1 | DIVM__1; // Set ACLK to 239.75Hz, SMCLK to 16MHz, and MCLK to 16MHz CSCTL0_H = 0; // Lock CS registers}void initI2C(){ UCB1CTLW0 = UCSWRST; // Enable SW reset UCB1CTLW0 |= UCMODE_3 | UCMST | UCSSEL__SMCLK | UCSYNC; // I2C master mode, SMCLK UCB1BRW = 160; // fSCL = ACLK/160 = ~100kHz UCB1I2CSA = SLAVE_ADDR; // Slave Address UCB1CTLW0 &= ~UCSWRST; // Clear SW reset, resume operation UCB1IE |= UCNACKIE;}void UART_init(void){ // Configure USCI_A1 for UART mode UCA1CTLW0 = UCSWRST; // Put eUSCI in reset UCA1CTLW0 |= UCSSEL__SMCLK; // CLK = SMCLK UCA1BR0 = 8; // Clock prescaler set to 8 UCA1BR1 = 0x00; // High byte empty, low byte is 8 UCA1MCTLW |= UCOS16 | UCBRF_10 | 0xF700; // Over-sampling on, first modulation register set to 10, second modulation register set to 0xF7 (247) for high byte, 0 for low byte UCA1CTLW0 &= ~UCSWRST; // Initialize eUSCI UCA1IE |= UCRXIE; // Enable USCI_A1 RX interrupt // Configure USCI_A0 for UART mode UCA0CTLW0 = UCSWRST; // Put eUSCI in reset UCA0CTLW0 |= UCSSEL__SMCLK; // CLK = SMCLK UCA0BR0 = 8; // Clock prescaler set to 8 UCA0BR1 = 0x00; // High byte empty, low byte is 8 UCA0MCTLW |= UCOS16 | UCBRF_10 | 0xF700; // Over-sampling on, first modulation register set to 10, second modulation register set to 0xF7 (247) for high byte, 0 for low byte UCA0CTLW0 &= ~UCSWRST; // Initialize eUSCI UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt}void ADC_init(void){ // Initialize the shared reference module // By default, REFMSTR=1 => REFCTL is used to configure the internal reference while(REFCTL0 & REFGENBUSY); // If ref generator busy, WAIT REFCTL0 |= REFVSEL_0 + REFON; // Enable internal 1.2V reference /* Initialize ADC12_A */ ADC12CTL0 &= ~ADC12ENC; // Disable ADC12 ADC12CTL0 = ADC12SHT0_8 + ADC12SHT0_9 + ADC12ON + ADC12MSC; //Set sample and hold time for ADC12MEM0 to 32 ADC12CLK cycles by setting bits 8 and 9 to 1, multiple sample and conversion ADC12CTL1 = ADC12SHP + ADC12DIV0_L + ADC12DIV1_L + ADC12DIV2_L + ADC12CONSEQ_1; //Source SAMPCON signal from the sampling timer, turn on all 3 clock divider bits for /8. Clock source is ADC12OSC (4.8MHz) (MODOSC), sequence-of-channels ADC12CTL2 = ADC12RES_2 + ADC12PWRMD_L; // 12 bit resolution and low power mode ADC12CTL3 = ADC12TCMAP; // Enable internal temperature sensor ADC12MCTL0 = ADC12VRSEL_1 + ADC12INCH_30; // ADC input channel A30 => temperature sensor ADC12MCTL1 = ADC12VRSEL_1 + ADC12INCH_8 + ADC12EOS; // ADC input channel A8 => battery measurement, end of channel sequence while(!(REFCTL0 & REFGENRDY)); // Wait for reference generator to settle ADC12CTL0 |= ADC12ENC; // Enable ADC12 ADC12CTL0 &= ~ADC12ON; // Turn off to save power}uint16_t sequenceNumber = 0; // Initialize sequence number// Function to increment and return sequence numberuint16_t getNextSequenceNumber() { sequenceNumber++; if(sequenceNumber == 255) // Roll over to 1 if sequence number reaches maximum value sequenceNumber = 1; return sequenceNumber;}void enterLowPowerMode() { __bis_SR_register(LPM4_bits + GIE); // Enter LPM4}int findLargestNumber(int array[], int size) { int largest = array[0]; // Initialize largest with the first element of the array // Iterate through the array to find the largest number for (int i = 1; i < size; i++) { if (array[i] > largest) { largest = array[i]; } } return largest; // Return the largest number}// Function to read Z axis accelerationvoid readZAxis() { bmi160_init('Z'); printf("Reading samples\n"); // Read SAMPLES amount of data from the BMI160 for(int i = 0; i < SAMPLES; i++) { I2C_Master_ReadReg(SLAVE_ADDR, 0x16, 2); // Read the acceleration value from the BMI160 registers input[i] = ReceiveBuffer[0] | (ReceiveBuffer[1] << 8); // Store the value in the input array }}// Function to find the largest number in Z axis acceleration samplesint findLargestInZAxis() { readZAxis(); // Call readZAxis to populate the input array return findLargestNumber(input, SAMPLES); // Find the largest number in the input array}void FFTProcessing(){ // Initialize the FFT parameters msp_status status; msp_fft_q15_params fftParams; /* Initialize the fft parameter structure. */ fftParams.length = SAMPLES; fftParams.bitReverse = true; fftParams.twiddleTable = msp_cmplx_twiddle_table_1024_q15; //Twiddle table for 4096 values int i = 0; uint8_t transmitData[10] = {0}; uint8_t *tempData; //Array of pointers to float temperature data uint8_t temporaryArray[4]; uint8_t transmission_target = 0x0010; readZAxis(); printf("Samples imported from readZAxis function \n"); msp_benchmarkStart(MSP_BENCHMARK_BASE, 16); status = msp_fft_fixed_q15(&fftParams, input); //Perform FFT cycleCount = msp_benchmarkStop(MSP_BENCHMARK_BASE); msp_checkStatus(status); printf("FFT completed\n"); getMaximums(input, SAMPLES, max, amp); printf("Max amp frequencies found\n"); for(i = 0; i < 5; i++) { transmitData[i * 2 + 2] = max[i] >> 8; // High byte transmitData[i * 2 + 3] = max[i] & 0xFF; // Low byte } // Identifier for frequency payload transmitData[0] = getNextSequenceNumber(); // Sequence number transmitData[1] = FREQUENCY_PAYLOAD_ID; ExampleSendAcknowledged(transmission_target, 0x00, transmitData, 0x0C); printf("Sent max amp frequencies\n");}//******************************************************************************// Main ************************************************************************//****************************************************************************** int main(void) { printf("Hello"); WDTCTL = WDTPW; // Stop watchdog timer printf("Hello2"); //Initialize all peripherals initClockTo16MHz(); initGPIO(); UART_init(); ADC_init(); initI2C(); timer_init(); NcApiInit(); TA0CTL = TA0CTL | (SMCLK + CONTINUOUS); // SMCLK: Counts faster than ACLK // CONTINUOUS: Count 0 to 0xFFFF TA0CCTL0 = CCIE; // Timer_0 interrupt TA1CTL = TA1CTL | (ACLK + UP ); // Count up from 0 with ACLK TA1CCR0 = MS_10; // Duration approximatley 10ms _BIS_SR(GIE); // Activate all interrupts __bis_SR_register(GIE); while(1) { enterLowPowerMode(); }} //I2C Interrupt #pragma vector = USCI_B1_VECTOR __interrupt void USCI_B1_ISR(void) { //Must read from UCB1RXBUF uint8_t rx_val = 0; switch(__even_in_range(UCB1IV, USCI_I2C_UCBIT9IFG)) { case USCI_NONE: break; // Vector 0: No interrupts case USCI_I2C_UCALIFG: break; // Vector 2: ALIFG case USCI_I2C_UCNACKIFG: // Vector 4: NACKIFG UCB1CTLW0 |= UCTXSTT; // Re-send start if NACK break; case USCI_I2C_UCSTTIFG: break; // Vector 6: STTIFG case USCI_I2C_UCSTPIFG: break; // Vector 8: STPIFG case USCI_I2C_UCRXIFG3: break; // Vector 10: RXIFG3 case USCI_I2C_UCTXIFG3: break; // Vector 12: TXIFG3 case USCI_I2C_UCRXIFG2: break; // Vector 14: RXIFG2 case USCI_I2C_UCTXIFG2: break; // Vector 16: TXIFG2 case USCI_I2C_UCRXIFG1: break; // Vector 18: RXIFG1 case USCI_I2C_UCTXIFG1: break; // Vector 20: TXIFG1 case USCI_I2C_UCRXIFG0: // Vector 22: RXIFG0 rx_val = UCB1RXBUF; if (RXByteCtr) { ReceiveBuffer[ReceiveIndex++] = rx_val; RXByteCtr--; } if (RXByteCtr == 1) { UCB1CTLW0 |= UCTXSTP; } else if (RXByteCtr == 0) { UCB1IE &= ~UCRXIE; MasterMode = IDLE_MODE; __bic_SR_register_on_exit(CPUOFF); // Exit LPM0 } break; case USCI_I2C_UCTXIFG0: // Vector 24: TXIFG0 switch (MasterMode) { case TX_REG_ADDRESS_MODE: UCB1TXBUF = TransmitRegAddr; if (RXByteCtr) MasterMode = SWITCH_TO_RX_MODE; // Need to start receiving now else MasterMode = TX_DATA_MODE; // Continue to transmision with the data in Transmit Buffer break; case SWITCH_TO_RX_MODE: UCB1IE |= UCRXIE; // Enable RX interrupt UCB1IE &= ~UCTXIE; // Disable TX interrupt UCB1CTLW0 &= ~UCTR; // Switch to receiver MasterMode = RX_DATA_MODE; // State state is to receive data UCB1CTLW0 |= UCTXSTT; // Send repeated start if (RXByteCtr == 1) { //Must send stop since this is the N-1 byte while((UCB1CTLW0 & UCTXSTT)); UCB1CTLW0 |= UCTXSTP; // Send stop condition } break; case TX_DATA_MODE: if (TXByteCtr) { UCB1TXBUF = TransmitBuffer[TransmitIndex++]; TXByteCtr--; } else { //Done with transmission UCB1CTLW0 |= UCTXSTP; // Send stop condition MasterMode = IDLE_MODE; UCB1IE &= ~UCTXIE; // disable TX interrupt __bic_SR_register_on_exit(CPUOFF); // Exit LPM0 } break; default: __no_operation(); break; } break; default: break; } } #pragma vector = PORT1_VECTOR __interrupt void PORT1_ISR(void) { switch(__even_in_range(P1IV, P1IV_P1IFG7)) { case P1IV_NONE : break; case P1IV_P1IFG0 : break; case P1IV_P1IFG1 : // Button S1 pressed __bic_SR_register_on_exit(LPM3_bits); break; case P1IV_P1IFG2 : // Button S2 pressed __bic_SR_register_on_exit(LPM3_bits); break; case P1IV_P1IFG3 : // CTS high to low transition on P1.3 __bic_SR_register_on_exit(LPM3_bits); NcApiCtsActive(0); break; case P1IV_P1IFG4 : // NeoCortec wake-up __bic_SR_register_on_exit(LPM3_bits); NcApiCallbackNwuActive(0); break; case P1IV_P1IFG5 : break; case P1IV_P1IFG6 : break; case P1IV_P1IFG7 : break; default : _never_executed(); } } #pragma vector = PORT2_VECTOR __interrupt void PORT2_ISR(void) { switch(__even_in_range(P2IV, P2IV_P2IFG7)) { case P2IV_NONE : break; case P2IV_P2IFG0 : break; case P2IV_P2IFG1 : break; case P2IV_P2IFG2 : break; case P2IV_P2IFG3 : break; case P2IV_P2IFG4 : break; case P2IV_P2IFG5 : //Int2 sensor interrupt break; case P2IV_P2IFG6 : break; case P2IV_P2IFG7 : break; default : _never_executed(); } } #pragma vector = PORT3_VECTOR __interrupt void PORT3_ISR(void) { switch(__even_in_range(P3IV, P3IV_P3IFG7)) { case P3IV_NONE : break; case P3IV_P3IFG0 : break; case P3IV_P3IFG1 : break; case P3IV_P3IFG2 : //Int1 sensor interrupt motion_trigger = 1; break; case P3IV_P3IFG3 : break; case P3IV_P3IFG4 : break; case P3IV_P3IFG5 : break; case P3IV_P3IFG6 : break; case P3IV_P3IFG7 : break; default : _never_executed(); } } #pragma vector=USCI_A0_VECTOR __interrupt void USCI_A0_ISR(void) { switch(__even_in_range(UCA0IV, USCI_UART_UCTXCPTIFG)) { case USCI_NONE: break; case USCI_UART_UCRXIFG:break; case USCI_UART_UCTXIFG: break; case USCI_UART_UCSTTIFG: break; case USCI_UART_UCTXCPTIFG: break; } }#pragma vector=ACC_VECTOR // Replace ACC_VECTOR with actual accelerometer vector__interrupt void accelerometer_ISR(void) { __bic_SR_register_on_exit(LPM4_bits); // Exit LPM on ISR exit // Read accelerometer data float z_axis_data = findLargestInZAxis(); // Implement this function based on your accelerometer if (z_axis_data >= 1) { printf("FFT about to happen\n"); FFTProcessing(); // Implement this function to send data }}