在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.困惑啊
shuffer chen:
下载的时候这样装跳线。
仿真的时候这样装跳线,按道理都没有错啊,而且这个程序在Aduino里面就很正常了,没有接从机的时候,reading就是输出65535,接入从机了,就输出正常的数据。但是放在energia里面就不行,不管怎么弄输出都是0
Susan Yang:
您现在是用TI例程测的?dev.ti.com/…/
Susan Yang:
回复 shuffer chen:
我记得I2C的所用到的P1.6管脚还经过一个跳线帽连接到LED上,在进行I2C通信之前,要将这个跳线帽去掉。很抱歉,我手头上暂时没有这个板子,无法亲测
shuffer chen:
回复 Susan Yang:
是的这个P1.6的跳线帽已经摘了,但是还是不行
shuffer chen:
回复 shuffer chen:
#include <Wire.h>
#define BQ34Z100G1_address 0xaa>>1
void setup()
{Serial.begin(9600);// start serial communication at 9600bpsWire.begin();// join i2c bus (address optional for master)
}unsigned intreading;
void loop()
{// step 1: instruct sensor to read echoesWire.beginTransmission(BQ34Z100G1_address); Wire.write(byte(0x08));Wire.endTransmission();delay(100);Wire.requestFrom(BQ34Z100G1_address, 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 bitsreading |= Wire.read(); // receive low byte as lower 8 bitsSerial.println(reading);// print the reading}delay(500);// wait a bit since people have to read the output 🙂
}这个程序在arduino中能很好的读取到数据,或者没有从机的时候直接输出65535,但是在energia中编译完成后,串口输出不管有没有从机都是0,很是莫名其妙
shuffer chen:
回复 shuffer chen:
请问还有哪里没处理好?或者还有哪里要注意的地方呢?
灰小子:
回复 shuffer chen:
建议先看下Wire库的实现,看是否支持msp430g2553
shuffer chen:
回复 灰小子:
可以看看,但是既然是energia自身带的Wire库,按道理应该可以直接用,难道还需要个人自己修改验证?
shuffer chen:
回复 shuffer chen:
#define USCI_ERROR "\n*********\nI2C Slave is not implemented for this MSP430. \nConsider using using a MSP430 with USCI peripheral e.g. MSP430G2553.\n*********\n"
#if defined(__MSP430_HAS_USCI__) || defined(__MSP430_HAS_EUSCI_A0__) || defined(__MSP430_HAS_USCI_B0__) || defined(__MSP430_HAS_USCI_B1__)void onReceive( void (*)(int) );void onRequest( void (*)(void) );
#elsevoid onReceive( void (*)(int) ) __attribute__ ((error(USCI_ERROR)));void onRequest( void (*)(void) ) __attribute__ ((error(USCI_ERROR)));
#endifMSP430 Wire库中这段话是什么意思呢?难道不支持MSP430G2553?
如果要支持到G2553这个芯片,需要怎么改这个库呢?请大神解读一下哦,谢谢哈
灰小子:
回复 shuffer chen:
从这段代码看,应该是支持g2553的。
g2553有USCI A0和USCI B0