Other Parts Discussed in Thread:MSP430G2553, FDC2212
版上的前輩您好,
這是透過MSP430G2553,搭配使用FDC2212的電容轉數位訊號IC。
BCSCTL1 = CALBC1_8MHZ; //
DCOCTL = CALDCO_8MHZ; //
期待獲得
拜託前輩大神給予方向指導,感謝!
Susan Yang:
请问能否给出详细信息或者具体描述下您的问题?您现在图2参考的资料能否给出链接?
,
user6529956:
Dear Susan,
圖二的資料鏈接為www.ti.com/…/tidud21.pdf page 23。
我所參考的文件就是這份,MCU:msp430g2553, IC:FDC2212,通訊I2C。
Graphic設定如下,還懇請教導2112.main.c
/*** 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 FreisingAdded 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 0x3F #define ISPEED 63 //#define ISPEED 12 #define MARGIN 50000signed char byteCtr; signed char Alive=0; signed char zero_flag=0; unsigned char *TI_receive_field; unsigned char *TI_transmit_field;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] = {0x00,0x00}; 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,0x78,0x00}; unsigned char IDRIVE_1[3] = {0x1F,0x78,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 longDataChannel_0 ; unsigned short DataChannel_1_MSB=0 ; unsigned short DataChannel_1_LSB=0; unsigned longDataChannel_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 boardP1DIR |= BIT1;// P1.1 is an output (unused pin)P1DIR |= BIT4;// P1.4 is an output (Shutdown) -> FDC2212 Pin6 SDP1OUT &= ~BIT4;// Set P1.4 low so Shutdown is LOWP1DIR |= BIT2;// P1.2 is an output (ADDR)P1OUT &= ~BIT2;// Set P1.2 low so ADDR is LOW and FDC2212 address is 0x2a, -> FDC2212 Pin4 ADDR //P1OUT |= BIT2;// Set P1.2 high so ADDR is HIGH and FDC2212 address is 0x2bP2DIR |= BIT1;// Set P2.1 as an output, Green LedP2DIR |= BIT2;// Set P2.2 as an output, Red Led//P2DIR |= BIT5;// Set P2.5 as an output, //P2OUT |= BIT5;// Set P2.5 high to pull up SDA and SCLBCSCTL1 = CALBC1_8MHZ;//DCOCTL = CALDCO_8MHZ;// //BCSCTL1 = CALBC1_1MHZ;// //DCOCTL = CALDCO_1MHZ;//_EINT();// Enable interrupts//Prepare to write to the FDC2212-Q1 registerswhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHzAlive=TI_USCI_I2C_slave_present(0x2a);//Write to the RCOUNT registers for Channel 0 and Channel 1array[0] = 0x08;array[1]=0xff;array[2]= 0xff;// RCOUNT = ffffwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(3,array);// transmit the first three bytes from array__delay_cycles(2000);array[0] = 0x09; array[1]=0xff;array[2]= 0xff;// RCOUNT = ffff, register address for RCOUNT_CH1while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(3,array);// transmit the first three bytes from array, consisting of the register address plus two data bytes__delay_cycles(2000);//Write to the ERROR_CONFIG registerarray[0] = 0x19;array[1]=0x00;array[2]= 0x01;// disable all the error reports, enable the data flag interrwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(3,array);// transmit the first three bytes from array__delay_cycles(2000);//Write to the SETTLECOUNT registersarray[0] = 0x10;array[1]=0x00;array[2]= 0x0A;// SETTLECOUNT = 000Awhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(3,array);// transmit the first three bytes from array__delay_cycles(2000);array[0] = 0x11;array[1]=0x00;array[2]= 0x0A;// SETTLECOUNT = 000A, register address for SETTLECOUNT_CH1while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(3,array);// transmit the first three bytes from array (register address plus two data bytes)__delay_cycles(2000);//Write to the CLOCK_DIVIDERS registersarray[0] = 0x14;array[1]=0x20;array[2]= 0x01;// CLOCK_DIVIDERS FIN_SEL=2, FREF_DIVIDER=1while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(3,array);// transmit the first three bytes from array__delay_cycles(2000);array[0] = 0x15; array[1]=0x20;array[2]= 0x01;// CLOCK_DIVIDERS FIN_SEL=2, FREF_DIVIDER=1,register address for CLOCK_DIVIDERS_CH1while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(3,array);// transmit the first three bytes from array (register address plus two data bytes)__delay_cycles(2000);//Write to the DRIVE_CURRENT registersarray[0] = 0x1E;array[1]=0x78;array[2]= 0x00;// see current drive table p.36 of FDC2212-Q1 datasheetwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(3,IDRIVE_0);// transmit the first three bytes from array__delay_cycles(2000);array[0] = 0x1F; array[1]=0x78;array[2]= 0x00;// register address for DRIVE_CURRENT_CH1while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(3,IDRIVE_1);// transmit the first three bytes from array (register address plus two data bytes)__delay_cycles(2000);//Write to the MUX_CONFIG registerarray[0] = 0x1B;array[1]=0x82;array[2]= 0x0D;// see p.35 of FDC2212-Q1 datasheetwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(3,array);// transmit the first three bytes from array__delay_cycles(2000);//Write to the CONFIG register// Last of the set-up write commandsarray[0] = 0x1A;array[1]=0x5e;array[2]= 0x01;// see p.34 of FDC2212-Q1 datasheetwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(3,array);// transmit the first three bytes from array__delay_cycles(2000);// Read the CONFIG_MUX registerwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2aarray[0] = 0x1B;// register for Device IDwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,MUX_CNFG);// receive 2 bytes from slave__delay_cycles(2000);// Read the RCOUNT_0 registerwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2aarray[0] = 0x08;// register for Device IDwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,RCOUNT_0);// receive 2 bytes from slave__delay_cycles(2000);// Read the RCOUNT_1 registerwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2aarray[0] = 0x09;// register for Device IDwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,RCOUNT_1);// receive 2 bytes from slave__delay_cycles(2000);// Read the SCOUNT_0 registerwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2aarray[0] = 0x10;// register for Device IDwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,SCOUNT_0);// receive 2 bytes from slave__delay_cycles(2000);// Read the SCOUNT_1 registerwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2aarray[0] = 0x11;// register for Device IDwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,SCOUNT_1);// receive 2 bytes from slave__delay_cycles(2000);// Read the IDRIVE_0 registerwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2aarray[0] = 0x1E;// register for Device IDwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,&IDRIVE_0[1]);// receive 2 bytes from slave__delay_cycles(2000);// Read the IDRIVE_1 registerwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2aarray[0] = 0x1F;// register for Device IDwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,&IDRIVE_1[1]);// receive 2 bytes from slave__delay_cycles(2000);// Read the CLOCK_DIVIDERS_CH0 registerwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2aarray[0] = 0x14;// register for CLOCK_DIVIDERS_CH0while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,CK_DIV_0);// receive 2 bytes from slave__delay_cycles(2000);// Read the CLOCK_DIVIDERS_CH1 registerwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2aarray[0] = 0x15;// register for CLOCK_DIVIDERS_CH0while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,CK_DIV_1);// receive 2 bytes from slave__delay_cycles(2000);// Read the ERROR_CONFIG registerwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2aarray[0] = 0x19;// register for ERROR_CONFIGwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,ERR_CNFG);// receive 2 bytes from slave__delay_cycles(2000);// Read the CONFIG registerwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2aarray[0] = 0x1a;// register for CONFIGwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,CONFIG);// receive 2 bytes from slave__delay_cycles(2000);// begin the loopingfor(;;){// Measurement 1 ************P2OUT &= ~BIT1;// Turn off the Green LEDP2OUT |= BIT2;// Turn on the RED LED__delay_cycles(10000000);// Read the MSB of Channel 1 Datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHzarray[0] = 0x02;// register for DATA_CH1MSB of channel 1 datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,MSB_Channel_1); // receive 2 bytes from FDC__delay_cycles(2000);DataChannel_1_MSB = MSB_Channel_1[0] * 256 + MSB_Channel_1[1];// Read the LSB of Channel 1 Datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHzarray[0] = 0x03;// register for DATA_CH1_LSBLSB of channel 1 datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,LSB_Channel_1); // receive 2 bytes from FDC__delay_cycles(2000);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 Datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHzarray[0] = 0x02;// register for DATA_CH1MSB of channel 1 datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,MSB_Channel_1); // receive 2 bytes from FDC__delay_cycles(2000);DataChannel_1_MSB = MSB_Channel_1[0] * 256 + MSB_Channel_1[1];// Read the LSB of Channel 1 Datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHzarray[0] = 0x03;// register for DATA_CH1_LSBLSB of channel 1 datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,LSB_Channel_1); // receive 2 bytes from FDC__delay_cycles(2000);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 Datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHzarray[0] = 0x02;// register for DATA_CH0MSB of channel 1 datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,MSB_Channel_1); // receive 2 bytes from FDC__delay_cycles(2000);DataChannel_1_MSB = MSB_Channel_1[0] * 256 + MSB_Channel_1[1];// Read the LSB of Channel 1 Datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHzarray[0] = 0x03;// register for DATA_CH0_LSBLSB of channel 1 datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,LSB_Channel_1); // receive 2 bytes from FDC__delay_cycles(2000);DataChannel_1_LSB = LSB_Channel_1[0] * 256 + LSB_Channel_1[1];Measurement2 = DataChannel_1_MSB * 65536 + DataChannel_1_LSB ;// Read the MSB of Channel 1 Datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHzarray[0] = 0x02;// register for DATA_CH0MSB of channel 1 datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,MSB_Channel_1); // receive 2 bytes from FDC__delay_cycles(2000);DataChannel_1_MSB = MSB_Channel_1[0] * 256 + MSB_Channel_1[1];// Read the LSB of Channel 1 Datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHzarray[0] = 0x03;// register for DATA_CH0_LSBLSB of channel 1 datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,LSB_Channel_1); // receive 2 bytes from FDC__delay_cycles(2000);DataChannel_1_LSB = LSB_Channel_1[0] * 256 + LSB_Channel_1[1];//DataChannel_0 = DataChannel_0_MSB * 65536 + DataChannel_0_LSB ;Measurement2 = 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 LEDP2OUT |= BIT2;// Turn on the RED LED__delay_cycles(10000000);// Read the MSB of Channel 1 Datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHzarray[0] = 0x02;// register for DATA_CH0MSB of channel 1 datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,MSB_Channel_1); // receive 2 bytes from FDC__delay_cycles(2000);DataChannel_1_MSB = MSB_Channel_1[0] * 256 + MSB_Channel_1[1];// Read the LSB of Channel 1 Datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHzarray[0] = 0x03;// register for DATA_CH0_LSBLSB of channel 1 datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,LSB_Channel_1); // receive 2 bytes from FDC__delay_cycles(2000);DataChannel_1_LSB = LSB_Channel_1[0] * 256 + LSB_Channel_1[1];//DataChannel_0 = DataChannel_0_MSB * 65536 + DataChannel_0_LSB ;Measurement3 = DataChannel_1_MSB * 65536 + DataChannel_1_LSB ; //Measurement3 = DataChannel_1;P2OUT |= BIT1;// Turn on the Green LEDP2OUT |= BIT2;// Turn on the RED LED //__delay_cycles(10000000);// Read the MSB of Channel 1 Datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHzarray[0] = 0x02;// register for DATA_CH0MSB of channel 1 datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,MSB_Channel_1); // receive 2 bytes from FDC__delay_cycles(2000);DataChannel_1_MSB = MSB_Channel_1[0] * 256 + MSB_Channel_1[1];// Read the LSB of Channel 1 Datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmitinit(0x2a,ISPEED);// init transmitting to slave 2a with baud rate SMCLK / 3f (3f = 63) that is, 8 MHz / 63 = 126 kHzarray[0] = 0x03;// register for DATA_CH0_LSBLSB of channel 1 datawhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_transmit(1,array);// transmit the first byte from array__delay_cycles(2000);while ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receiveinit(0x2a,ISPEED); // init receiving with USCIwhile ( TI_USCI_I2C_notready() );// wait for bus to be freeTI_USCI_I2C_receive(2,LSB_Channel_1); // receive 2 bytes from FDC__delay_cycles(2000);DataChannel_1_LSB = LSB_Channel_1[0] * 256 + LSB_Channel_1[1];//DataChannel_0 = DataChannel_0_MSB * 65536 + DataChannel_0_LSB ;Measurement3 = DataChannel_1_MSB * 65536 + DataChannel_1_LSB ;//Measurement3 = DataChannel_1;P2OUT &= ~BIT1;// turn off Green LEDP2OUT &= ~BIT2;// turn off Red LED__delay_cycles(5000000);if((Measurement1 > (Measurement2 + MARGIN)) && (Measurement3 > (Measurement2 + MARGIN))){P2OUT |= BIT1;//red__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;//green__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 loopLPM3;// low power mode 3}
,
user6529956:
透過array把量測資料讀出來,確實發現數值沒有掉為0。
看起來就是watch list的設定問題了,煩請大神看看有沒有好的文件可以參考?
,
Susan Yang:
感谢您对TI产品的关注!为更加有效地解决您的问题,我们建议您将问题发布在E2E英文技术论坛上,将由资深的英文论坛工程师为您提供帮助。
e2e.ti.com/…/166