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