i2c通信 msp430g2553_在energia平台中利用MSP430G2553 LAUCHPAD 进行I2C通讯读取数据一直为0的困惑...

新手求助:使用energia平台和MSP430G2553 LaunchPad进行I2C通信时,无论目标板是否连接,读取数据始终为0。怀疑Wire库未正常工作。求解如何启动Wire库并解决读取问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在energia平台中利用MSP430G2553 LAUCHPAD 进行I2C通讯读取数据一直为0,就算目标板接入MSP430的I2C接口(P1.6;P1.7),在串口监视窗口中一直为0,貌似Wire库函数没有启动,不知道是怎么回事,请大神赐教,刚接触这个LAUCHPAD,下面是测试程序:

#include

#include

void setup()

{

Serial.begin(9600); // start serial communication at 9600bps

Wire.begin(); // join i2c bus (address optional for master)

}

unsigned int reading;

void loop()

{

// step 1: instruct sensor to read echoes

Wire.beginTransmission(byte(0xab));

Wire.write(byte(0x08));

Wire.endTransmission();

delay(100);

Wire.requestFrom(byte(0xab), 2);

if(Wire.available()<=2) // if two bytes were received

{

reading = Wire.read(); // receive high byte (overwrites previous reading)

reading = reading << 8; // shift high byte to be high 8 bits

reading |= Wire.read(); // receive low byte as lower 8 bits

Serial.println(reading); // print the reading

}

delay(500); // wait a bit since people have to read the output :)

}

按道理,没有接入目标板的时候,reading应该在串口窗口中打印出65535才对,但是也是一直为0.困惑啊

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值