工具/软件:Code Composer Studio
大家好、
我正在努力将 BMP180传感器连接到 msp430g2553。 我已经在 MSP430中完成了 I2C 与 BMP180通信的配置部分。 但通信并未建立。 它将进入 while 循环。 我随附了我的代码。
空 BMP180GetCalVals (tBMP180Cals * calInst)
{
静态常量 uint8_t bmpCalRegs[11]={BMP180_REG_CAL_AC1、BMP180_REG_CAL_AC2、BMP180_REG_CAL_AC3、BMP180_REG_CAL_AC4、BMP180_REG_CAL_AC5、 BMP180_REG_CAL_AC6、BMP180_REG_CAL_B1、BMP180_REG_CAL_B2、BMP180_REG_CAL_MB、BMP180_REG_CAL_MC、 BMP180_REG_CAL_MD};
uint8_t bmpCalBytes[22];
uint8_t bmpCalCount=0;
UCB0CTL1 |= UCSWRST;
UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC;
UCB0CTL1 = UCSSEL_2;
UCB0BR0 = 0x12; // 100kHz
UCB0BR1 = 0x00;
UCB0I2CSA = BMP180_I2C_ADDRESS;
UCB0CTL1 &=~UCSWRST;
while (bmpCalCount < 11)
{
while (UCB0CTL1 & UCTXSTP);
UCB0CTL1 |= UCTR + UCTXSTT;
while (UCB0CTL1 & UCTXSTT);//程序在这里执行。
UCB0TXBUF = bmpCalRegs[bmpCalCount];
while (!(IFG2 & UCB0TXIFG));
UCB0CTL1 &=~UCTR;
UCB0CTL1 |= UCTXSTT;
while (UCB0CTL1 & UCTXSTT);
bmpCalBytes[2*bmpCalCount]= UCB0RXBUF;
while (!(IFG2 & UCB0RXIFG));
UCB0CTL1 |= UCTXSTT;
while (UCB0CTL1 & UCTXSTT);
bmpCalBytes[2*bmpCalCount+1]= UCB0RXBUF;
while (!(IFG2 & UCB0RXIFG));
UCB0CTL1 |= UCTXSTP;
BmpCalCount++;
UCB0CTL1 |= UCTR;
}
calInst->AC1 =(Int16_t)((bmpCalBytes[0]<<8)| bmpCalBytes[1]);
calInst->AC2 =(Int16_t)((bmpCalBytes[2]<<8)| bmpCalBytes[3]);
calInst->ac3 =(int16_t)((bmpCalBytes[4]<<8)| bmpCalBytes[5]);
calInst->AC4 =(uint16_t)((bmpCalBytes[6]<<8)| bmpCalBytes[7]);
calInst->AC5 =(uint16_t)((bmpCalBytes[8]<<8)| bmpCalBytes[9]);
calInst->AC6 =(uint16_t)((bmpCalBytes[10]<<8)| bmpCalBytes[11]);
calInst->b1 = (int16_t)((bmpCalBytes[12]<<8)|bmpCalBytes[13]);
calInst->b2= (Int16_t)((bmpCalBytes[14]<<8)|bmpCalBytes[15]);
calInst->MB = (int16_t)((bmpCalBytes[16]<<8)|bmpCalBytes[17]);
calInst->MC = (int16_t)((bmpCalBytes[18]<<8)|bmpCalBytes[19]);
calInst->MD = (int16_t)((bmpCalBytes[20]<<8)| bmpCalBytes[21]);
}
请仔细检查 我编写的 I2C 配置、如果 出现问题、请通过更正来帮助我。 我只想在 MSP430和传感器之间建立连接。 我在 SCL 和 SDA 线路之间使用了10k 上拉电阻器。
谢谢、此致、
Subash