TI中文支持网
TI专业的中文技术问题搜集分享网站

MSP430G2553 I2C SCLK 波型異常

Other Parts Discussed in Thread:MSP430G2553, FDC2212

各位前輩與先進您好,

目前使用MSP430G2553來進行I2C通訊,

程式代碼:

if ( TI_USCI_I2C_slave_present(0x2a) ) ;// 這行回傳值為"1"

while ( TI_USCI_I2C_notready() );     // wait for bus to be free

TI_USCI_I2C_transmitinit(0x2a,ISPEED);

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

其中黃色為SCLK,藍色為SDA,下圖為示波器上看到的值。

可以看到一開始為高電位,但是結束後卻沒有拉回到高電位。

還請各位先進與高手幫忙解答,感謝

 

Susan Yang:

请问您现在从设备是什么?建议您根据从设备I2C的时序要求,增加驱动程序里等待响应的时间试试。

另外网络上有一些比较好的故障分析,您也可以先看一下

www.jianshu.com/…/95f53ca2724e

,

user6529956:

Susan 您好,

MSP43-G2553 (EXP430G2) with the FDC2212(Captative to digital IC).

 BCSCTL1 = CALBC1_8MHZ;                    //

 DCOCTL = CALDCO_8MHZ;                     //

 array[0] = 0x08;  array[1]=0xff;    array[2]= 0xff;     // RCOUNT = ffff

 while ( TI_USCI_I2C_notready() );     // wait for bus to be free

 TI_USCI_I2C_transmitinit(0x2a,ISPEED);

 while ( TI_USCI_I2C_notready() );     // wait for bus to be free

 TI_USCI_I2C_transmit(3,array);        // transmit the first three bytes from array

++ 傳遞之後,波型如下:

i2C 外掛 10k 歐姆,有pull high.

想要跟您請教:

1. 如何通常pull high電阻會用多少?

2. 如何增加延遲時間以利i2c能夠順利傳送資料(避免佔線問題)

謝謝您

lin

,

Susan Yang:

user6529956 说:1. 如何通常pull high電阻會用多少?

一般使用的是10K

例程的话,您可以参考链接中的一系列I2C例程

对于 FDC2212,我们也有一个专门的文档,您可以看一下

另外请您以附件形式上传一下图片,谢谢

,

user6529956:

Dear Susan,

非常感謝您的迅速回復,我已經有參考過FDC2212的文件。

至於圖形有兩個疑問:

1. 為何傳完資料後,SDA與SCLK並沒有拉高準位? (資料內容請參考我前一封提問)

2. 為何資料看起來跟我要傳的,完全對不起來?

拜託Susan指導

,

user6529956:

Dear Susan,

需要您的特別幫忙,

我參考TI_USCI_I2C_master.c 檔案

//——————————————————————————
// void TI_USCI_I2C_transmit(unsigned char byteCount, unsigned char *field)
//
// This function is used to start an I2C communication in master-transmit mode.
//
// IN:unsigned char byteCount=>number of bytes that should be transmitted
//unsigned char *field=>array variable. Its content will be sent.
//——————————————————————————
void TI_USCI_I2C_transmit(unsigned char byteCount, unsigned char *field){TI_transmit_field = field;byteCtr = byteCount;UCB0CTL1 |= UCTR + UCTXSTT;// I2C TX, start condition
}

並在主程式中,欲傳遞以下資料array[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);

但是用示波器去看,總是有問題(SCLK 看起來都會掉Clock,SDA資料看起也不對)
,可以拜託您幫忙看一下 程式碼有無問題嗎?

感謝~

,

Susan Yang:

若是可以的话,请您私信/上传一下您的完整代码,谢谢

,

user6529956:

6138.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 500signed char byteCtr;
signed char Alive=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 arraywhile ( 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// 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 arraywhile ( 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// 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 arraywhile ( 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// 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 arraywhile ( 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// 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 arraywhile ( 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// 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 arraywhile ( 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// 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 arraywhile ( 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// 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 arraywhile ( 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// 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 arraywhile ( 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// 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 arraywhile ( 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// 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 arraywhile ( 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// 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 arraywhile ( 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 FDCDataChannel_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 arraywhile ( 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 FDCDataChannel_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 arraywhile ( 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 FDCDataChannel_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 arraywhile ( 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 FDCDataChannel_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 arraywhile ( 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 FDCDataChannel_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 arraywhile ( 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 FDCDataChannel_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;// 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 arraywhile ( 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 FDCDataChannel_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 arraywhile ( 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 FDCDataChannel_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 arraywhile ( 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 FDCDataChannel_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 arraywhile ( 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 FDCDataChannel_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 arraywhile ( 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 FDCDataChannel_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 arraywhile ( 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 FDCDataChannel_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}

Dear Susan,

目前看起來I2c已經能夠正常傳遞資料,不過對於FDC2212的量測,仍然不清楚,

  // 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];

     Measurement1 = DataChannel_1_MSB * 65536 + DataChannel_1_LSB;

程式中,重複兩次(Measurement1),接下來還有Measurement2&3.

最後利用這個判斷式,判斷電路是否有效觸發:(Margin 設為500)

if((Measurement1 > (Measurement2 + MARGIN)) && (Measurement3 > (Measurement2 + MARGIN)))

能否請您指導該如何做實驗,來提升判斷的準確度,謝謝您!

,

Susan Yang:

之后我们将在下面的链接讨论

e2echina.ti.com/…/624314

赞(0)
未经允许不得转载:TI中文支持网 » MSP430G2553 I2C SCLK 波型異常
分享到: 更多 (0)