我们将在春节假期期间对网站进行维护,可能暂时无法访问,同时工程师回复将有所延迟,敬请谅解.

This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MCF8316A: I2C通信程序无法通信问题

Part Number: MCF8316A

我用arduino Nano 控制MCF8316A,经过多次测试都未能成功,能帮帮我吗?谢谢!

#include <Wire.h>
#include <avr/wdt.h>
 const uint32_t address = 0x00000478; //12 位地址,不应超过 4095(0x0FFF)
 const uint32_t command = 0x0000043E; //12 位地址,不应超过 4095(0x0FFF)
byte buffer[30]; 
byte datav[10]={1,2,3,4,5,6,7,8,9,10}; 
 boolean flag=true;
 int i;
  byte dataOut[4];
 int data;
 void setup()
 {
    Wire.begin();
    Serial.begin(115200); 
    Serial.println("I2C OK");
    delay(10);
 }
 void loop()
 {
    //read
display(0x00000440);//写入地址
receiveEvent(4);//读取数据
  delay(2000);
  
 wdt_reset(); 
 
 }
 void display(const uint32_t data) {  //写入地址
  byte dataOut[4];
  dataOut[3] = (data >> 24) & 0xFF;
  dataOut[2] = (data >> 16) & 0xFF;
  dataOut[1] = (data >> 8) & 0xFF;
  dataOut[0] = data & 0xFF;
  Wire.beginTransmission(0x01);
  Wire.write(dataOut, 4);
  Wire.endTransmission();
  
    Serial.println("display:");
    Serial.println(dataOut[0]);
    Serial.println(dataOut[1]);
    Serial.println(dataOut[2]);
    Serial.println(dataOut[3]);
 }
 void receiveEvent(const uint32_t bytes) {//读取数据
  int data;
  while(Wire.available() > 0) {
    data += Wire.read();
    data = (data << 8);
  }
  Serial.println("receiveEvent:");
  Serial.println(data); 
}