Other Parts Discussed in Thread: TIDA-01409, MSP430G2553, FDC2214EVM
Dear Experts,
I tried to develop the code for the FDC2212 and take tida-01409 example code for my reference.
Here, I want to have your kindly assistance:
1. In this example code, the sensor is using the single end design(channel 0) or two channel(channel 0&1)?
2. In the flow chart, it mentioned that the it also detect the key if exist or not, but i can't find it in the code.
Article name: Automotive Capacitive Kick-to-Open Reference Design, Section 3.1.2(page.13)
/*** USCI master library ************************************************************ In this file the usage of the USCI I2C master library without DMA support is shown. This library uses pointers to specify what data is to be sent. When calling the TI_USCI_I2C_receive or TI_USCI_I2C_transmit routines the number of bytes, which are to be transmitted or received have to be passed as well as a pointer to a data field, that contains(or stores) the data. This code checks if there is a slave with address 0x50 is connected to the I2C bus and if the slave device is present, bytes are received and transmitted. Uli Kretzschmar MSP430 Systems Freising Added FDC2212-Q1 code for TIDA-01409 Capacitive Kick-to-Open Reference Design *******************************************************************************/ #include "msp430g2553.h" #include "TI_USCI_I2C_master.h" #define DATA_CH0_MSB_REG 0x00 #define DATA_CH0_LSB_REG 0x01 #define DATA_CH1_MSB_REG 0x02 #define DATA_CH1_LSB_REG 0x03 #define ISPEED 0x55 #define MARGIN 500 unsigned char timercounter; unsigned char array[3] = {0x00, 0x00, 0x00 }; unsigned char store[10] = { 0xff, 0xff }; unsigned char LSB_Channel_0[2] = { 0x0, 0x0}; unsigned char MSB_Channel_0[2] = { 0x0, 0x1}; unsigned char LSB_Channel_1[2] = { 0x0, 0x2}; unsigned char MSB_Channel_1[2] = { 0x0, 0x3}; unsigned char MUX_CNFG[2] = {'M','C'}; unsigned char RCOUNT_0[2] = {'R','0'}; unsigned char RCOUNT_1[2] = {'R','1'}; unsigned char SCOUNT_0[2] = {'S','0'}; unsigned char SCOUNT_1[2] = {'S','0'}; unsigned char IDRIVE_0[3] = {0x1E,0x60,0x00}; unsigned char IDRIVE_1[3] = {0x1F,0x60,0x00}; unsigned char CK_DIV_0[2] = {'C','D'}; unsigned char CK_DIV_1[2] = {'c','d'}; unsigned char ERR_CNFG[2] = {'E','C'}; unsigned char CONFIG[2] = {'C','F'}; unsigned short DataChannel_0_MSB ; unsigned short DataChannel_0_LSB ; unsigned long DataChannel_0 ; unsigned short DataChannel_1_MSB ; unsigned short DataChannel_1_LSB ; unsigned long DataChannel_1 ; unsigned long Measurement1; unsigned long Measurement2; unsigned long Measurement3; void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WatchDogTimer // Set up the GPIO pins for the TIDA-01409 board P1DIR |= BIT1; // P1.1 is an output (unused pin) P1DIR |= BIT2; // P1.2 is an output (ADDR) P1DIR |= BIT4; // P1.4 is an output (Shutdown) P1OUT &= ~0x10; // Set P1.4 low so Shutdown is LOW P1OUT &= ~BIT2; // Set P1.2 low so ADDR is LOW and FDC2212 address is 0x2a // P1OUT |= BIT2; // Set P1.2 high so ADDR is HIGH and FDC2212 address is 0x2b P2DIR |= BIT1; // Set P2.1 as an output P2DIR |= BIT2; // Set P2.2 as an output P2DIR |= BIT5; // Set P2.5 as an output P2OUT |= BIT5; // Set P2.5 high to pull up SDA and SCL BCSCTL1 = CALBC1_8MHZ; // DCOCTL = CALDCO_8MHZ; // _EINT(); // Enable interrupts // if ( TI_USCI_I2C_slave_present(0x2a) ) ; // // Prepare to write to the FDC2212-Q1 registers while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED); // init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHz // Write to the RCOUNT registers for Channel 0 and Channel 1 array[0] = 0x08; array[1]=0x12; array[2]= 0x34; // RCOUNT = ffff while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(3,array); // transmit the first three bytes from array array[0] = 0x09; // register address for RCOUNT_CH1 while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(3,array); // transmit the first three bytes from array, consisting of the register address plus two data bytes // Write to the ERROR_CONFIG register array[0] = 0x19; array[1]=0x30; array[2]= 0x00; // disable all the error reports while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(3,array); // transmit the first three bytes from array // Write to the SETTLECOUNT registers array[0] = 0x10; array[1]=0x04; array[2]= 0x00; // SETTLECOUNT = 0400 while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(3,array); // transmit the first three bytes from array array[0] = 0x11; // register address for SETTLECOUNT_CH1 while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(3,array); // transmit the first three bytes from array (register address plus two data bytes) // Write to the CLOCK_DIVIDERS registers array[0] = 0x14; array[1]=0x10; array[2]= 0x01; // CLOCK_DIVIDERS FIN_SEL=2, FREF_DIVIDER=1 while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(3,array); // transmit the first three bytes from array array[0] = 0x15; // register address for CLOCK_DIVIDERS_CH1 while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(3,array); // transmit the first three bytes from array (register address plus two data bytes) // Write to the DRIVE_CURRENT registers array[0] = 0x1E; array[1]=0x88; array[2]= 0x00; // see current drive table p.36 of FDC2212-Q1 datasheet while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(3,IDRIVE_0); // transmit the first three bytes from array array[0] = 0x1F; // register address for DRIVE_CURRENT_CH1 while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(3,IDRIVE_1); // transmit the first three bytes from array (register address plus two data bytes) // Write to the MUX_CONFIG register array[0] = 0x1B; array[1]=0x02; array[2]= 0x0D; // see p.35 of FDC2212-Q1 datasheet while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(3,IDRIVE_1); // transmit the first three bytes from array // Write to the CONFIG register // Last of the set-up write commands array[0] = 0x1A; array[1]=0x5e; array[2]= 0x01; // see p.34 of FDC2212-Q1 datasheet while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(3,array); // transmit the first three bytes from array // Read the CONFIG_MUX register while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a array[0] = 0x1b; // register for Device ID while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,MUX_CNFG); // receive 2 bytes from slave // Read the RCOUNT_0 register while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a array[0] = 0x08; // register for Device ID while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,RCOUNT_0); // receive 2 bytes from slave // Read the RCOUNT_1 register while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a array[0] = 0x09; // register for Device ID while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,RCOUNT_1); // receive 2 bytes from slave // Read the SCOUNT_0 register while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a array[0] = 0x10; // register for Device ID while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,SCOUNT_0); // receive 2 bytes from slave // Read the SCOUNT_1 register while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a array[0] = 0x11; // register for Device ID while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,SCOUNT_1); // receive 2 bytes from slave // Read the IDRIVE_0 register while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a array[0] = 0x1E; // register for Device ID while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,&IDRIVE_0[1]); // receive 2 bytes from slave // Read the IDRIVE_1 register while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a array[0] = 0x1F; // register for Device ID while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,&IDRIVE_1[1]); // receive 2 bytes from slave // Read the CLOCK_DIVIDERS_CH0 register while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a array[0] = 0x14; // register for CLOCK_DIVIDERS_CH0 while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,CK_DIV_0); // receive 2 bytes from slave // Read the CLOCK_DIVIDERS_CH1 register while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a array[0] = 0x15; // register for CLOCK_DIVIDERS_CH0 while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,CK_DIV_1); // receive 2 bytes from slave // Read the ERROR_CONFIG register while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a array[0] = 0x19; // register for ERROR_CONFIG while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,ERR_CNFG); // receive 2 bytes from slave // Read the CONFIG register while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a array[0] = 0x1a; // register for CONFIG while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,CONFIG); // receive 2 bytes from slave // begin the looping for(;;){ /* // Read the device ID - should be 0x3055 (0U) while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED); // init transmitting to slave array[0] = 0x7f; // register for Device ID while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,&store[2]); // receive 2 bytes from slave // Read the Manufacture ID - should be 0x5449 (TI) while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED); // init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHz array[0] = 0x7e; // register for Manufacturer ID while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,&store[4]); // receive 2 bytes from slave // Write to the CONFIG register // continuously read Channel 0 while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a array[0] = 0x1A; array[1]=0x1e; array[2]= 0x01; // see p.34 of FDC2212-Q1 datasheet while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(3,array); // transmit the first three bytes from array // Read the CONFIG register while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a array[0] = 0x1a; // register for CONFIG while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,CONFIG); // receive 2 bytes from slave // Read the MSB of Channel 0 Data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED); // init transmitting to slave 2a array[0] = 0x00; // register for DATA_CH0 MSB of channel 0 data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,MSB_Channel_0); // receive 2 bytes from FDC DataChannel_0_MSB = MSB_Channel_0[0] * 256 + MSB_Channel_0[1]; // Read the LSB of Channel 0 Data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a array[0] = 0x01; // register for DATA_CH0_LSB LSB of channel 0 data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,LSB_Channel_0); // receive 2 bytes from FDC DataChannel_0_LSB = LSB_Channel_0[0] * 256 + LSB_Channel_0[1]; __delay_cycles(1000); // Write to the CONFIG register // continuously read Channel 1 while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a array[0] = 0x1A; array[1]=0x5e; array[2]= 0x01; // see p.34 of FDC2212-Q1 datasheet while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(3,array); // transmit the first three bytes from array // Read the CONFIG register while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a array[0] = 0x1a; // register for CONFIG while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,CONFIG); // receive 2 bytes from slave */ // Measurement 1 ************ P2OUT &= ~BIT1; // Turn off the Green LED P2OUT |= BIT2; // Turn on the RED LED __delay_cycles(10000000); // Read the MSB of Channel 1 Data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHz array[0] = 0x02; // register for DATA_CH1 MSB of channel 1 data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,MSB_Channel_1); // receive 2 bytes from FDC DataChannel_1_MSB = MSB_Channel_1[0] * 256 + MSB_Channel_1[1]; // Read the LSB of Channel 1 Data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHz array[0] = 0x03; // register for DATA_CH1_LSB LSB of channel 1 data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,LSB_Channel_1); // receive 2 bytes from FDC DataChannel_1_LSB = LSB_Channel_1[0] * 256 + LSB_Channel_1[1]; DataChannel_0 = DataChannel_0_MSB * 65536 + DataChannel_0_LSB ; // DataChannel_1 = DataChannel_1_MSB * 65536 + DataChannel_1_LSB ; Measurement1 = DataChannel_1_MSB * 65536 + DataChannel_1_LSB ; // Read the MSB of Channel 1 Data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHz array[0] = 0x02; // register for DATA_CH1 MSB of channel 1 data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,MSB_Channel_1); // receive 2 bytes from FDC DataChannel_1_MSB = MSB_Channel_1[0] * 256 + MSB_Channel_1[1]; // Read the LSB of Channel 1 Data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHz array[0] = 0x03; // register for DATA_CH1_LSB LSB of channel 1 data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,LSB_Channel_1); // receive 2 bytes from FDC DataChannel_1_LSB = LSB_Channel_1[0] * 256 + LSB_Channel_1[1]; DataChannel_0 = DataChannel_0_MSB * 65536 + DataChannel_0_LSB ; // DataChannel_1 = DataChannel_1_MSB * 65536 + DataChannel_1_LSB ; Measurement1 = DataChannel_1_MSB * 65536 + DataChannel_1_LSB ; // Measurement 2 ************ P2OUT &= ~BIT2; // Turn off the Red LED __delay_cycles(10000000); P2OUT |= BIT1; // Turn on the Green LED __delay_cycles(10000000); // Read the MSB of Channel 1 Data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHz array[0] = 0x02; // register for DATA_CH0 MSB of channel 1 data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,MSB_Channel_1); // receive 2 bytes from FDC DataChannel_1_MSB = MSB_Channel_1[0] * 256 + MSB_Channel_1[1]; // Read the LSB of Channel 1 Data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHz array[0] = 0x03; // register for DATA_CH0_LSB LSB of channel 1 data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,LSB_Channel_1); // receive 2 bytes from FDC DataChannel_1_LSB = LSB_Channel_1[0] * 256 + LSB_Channel_1[1]; DataChannel_0 = DataChannel_0_MSB * 65536 + DataChannel_0_LSB ; DataChannel_1 = DataChannel_1_MSB * 65536 + DataChannel_1_LSB ; Measurement2 = DataChannel_1; // Read the MSB of Channel 1 Data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHz array[0] = 0x02; // register for DATA_CH0 MSB of channel 1 data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,MSB_Channel_1); // receive 2 bytes from FDC DataChannel_1_MSB = MSB_Channel_1[0] * 256 + MSB_Channel_1[1]; // Read the LSB of Channel 1 Data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHz array[0] = 0x03; // register for DATA_CH0_LSB LSB of channel 1 data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,LSB_Channel_1); // receive 2 bytes from FDC DataChannel_1_LSB = LSB_Channel_1[0] * 256 + LSB_Channel_1[1]; DataChannel_0 = DataChannel_0_MSB * 65536 + DataChannel_0_LSB ; DataChannel_1 = DataChannel_1_MSB * 65536 + DataChannel_1_LSB ; Measurement2 = DataChannel_1; P2OUT &= ~BIT1; P2OUT &= ~BIT2; __delay_cycles(10000000); // Measurement 3 ************ P2OUT |= BIT1; // Turn on the Green LED P2OUT |= BIT2; // Turn on the RED LED __delay_cycles(10000000); // Read the MSB of Channel 1 Data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHz array[0] = 0x02; // register for DATA_CH0 MSB of channel 1 data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,MSB_Channel_1); // receive 2 bytes from FDC DataChannel_1_MSB = MSB_Channel_1[0] * 256 + MSB_Channel_1[1]; // Read the LSB of Channel 1 Data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHz array[0] = 0x03; // register for DATA_CH0_LSB LSB of channel 1 data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,&array[0]); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,&LSB_Channel_1[0]); // receive 2 bytes from FDC DataChannel_1_LSB = LSB_Channel_1[0] * 256 + LSB_Channel_1[1]; DataChannel_0 = DataChannel_0_MSB * 65536 + DataChannel_0_LSB ; DataChannel_1 = DataChannel_1_MSB * 65536 + DataChannel_1_LSB ; Measurement3 = DataChannel_1; P2OUT |= BIT1; // Turn on the Green LED P2OUT |= BIT2; // Turn on the RED LED // __delay_cycles(10000000); // Read the MSB of Channel 1 Data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHz array[0] = 0x02; // register for DATA_CH0 MSB of channel 1 data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,array); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,MSB_Channel_1); // receive 2 bytes from FDC DataChannel_1_MSB = MSB_Channel_1[0] * 256 + MSB_Channel_1[1]; // Read the LSB of Channel 1 Data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHz array[0] = 0x03; // register for DATA_CH0_LSB LSB of channel 1 data while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_transmit(1,&array[0]); // transmit the first byte from array while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCI while ( TI_USCI_I2C_notready() ); // wait for bus to be free TI_USCI_I2C_receive(2,&LSB_Channel_1[0]); // receive 2 bytes from FDC DataChannel_1_LSB = LSB_Channel_1[0] * 256 + LSB_Channel_1[1]; DataChannel_0 = DataChannel_0_MSB * 65536 + DataChannel_0_LSB ; DataChannel_1 = DataChannel_1_MSB * 65536 + DataChannel_1_LSB ; Measurement3 = DataChannel_1; P2OUT &= ~BIT1; // turn off Green LED P2OUT &= ~BIT2; // turn off Red LED __delay_cycles(5000000); if((Measurement1 > (Measurement2 + MARGIN)) && (Measurement3 > (Measurement2 + MARGIN))){ P2OUT |= BIT1; __delay_cycles(2000000); P2OUT &= ~BIT1; __delay_cycles(2000000); P2OUT |= BIT1; __delay_cycles(2000000); P2OUT &= ~BIT1; __delay_cycles(2000000); P2OUT |= BIT1; __delay_cycles(2000000); P2OUT &= ~BIT1; __delay_cycles(2000000); P2OUT |= BIT1; __delay_cycles(2000000); P2OUT &= ~BIT1; __delay_cycles(2000000); } else{ P2OUT |= BIT2; __delay_cycles(2000000); P2OUT &= ~BIT2; __delay_cycles(2000000); P2OUT |= BIT2; __delay_cycles(2000000); P2OUT &= ~BIT2; __delay_cycles(2000000); P2OUT |= BIT2; __delay_cycles(2000000); P2OUT &= ~BIT2; __delay_cycles(2000000); P2OUT |= BIT2; __delay_cycles(2000000); P2OUT &= ~BIT2; __delay_cycles(2000000); } // end of if-else loop __delay_cycles(3000000); } // end of for loop LPM3; // low power mode 3 }
3. In the code, i think there have 3 measurements and take 3 results as the determine the gesture or not, but it can't find it in the article, may i have some help to know why this design?
Thanks for your kindly help,
Best regards,
Lin