我想轉換一些用於Arduino微控制器的C代碼與Raspberry Pi微控制器一起使用。他們都使用不同的庫,它可能是我遇到的問題,但我不確定希望我有幾個小錯誤,我沒有看到我一直在試圖解決這一段時間。我收到以下錯誤:隱式減速和未知類型的錯誤
temp.c: In function âloopâ:
temp.c:29:5: error: implicit declaration of function âgetGyroValuesâ [-Werror=implicit-function-declaration]
temp.c: At top level:
temp.c:37:6: error: conflicting types for âgetGyroValuesâ [-Werror]
temp.c:29:5: note: previous implicit declaration of âgetGyroValuesâ was here
temp.c: In function âgetGyroValuesâ:
temp.c:38:5: error: unknown type name âbyteâ
cc1: all warnings being treated as errors
這裏是我的代碼,我已經寫了:
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
#include <wiringPi.h>
#include <wiringPiI2C.h>
#define CTRL_REG1 0x20
#define CTRL_REG2 0x21
#define CTRL_REG3 0x22
#define CTRL_REG4 0x23
int fd,x,y,z;
void setup(){
fd = wiringPiI2CSetup(0x69); // I2C address of gyro
wiringPiI2CWriteReg8(fd, CTRL_REG1, 0x1F); //Turn on all axes, disable power down
wiringPiI2CWriteReg8(fd, CTRL_REG3, 0x08); //Enable control ready signal
wiringPiI2CWriteReg8(fd, CTRL_REG4, 0x80); // Set scale (500 deg/sec)
delay(100); // Wait to synchronize
}
void loop(){
getGyroValues();
// In following Divinding by 114 reduces noise
printf("Value of X is: %d\n", x/114);
printf("Value of Y is: %d\n", y/114);
printf("Value of Z is: %d\n", z/114);
delay(500);
}
void getGyroValues(){
byte MSB, LSB;
LSB = wiringPiI2CReadReg16(fd, 0x28);
MSB = wiringPiI2CReadReg16(fd, 0x29);
x = ((MSB << 8) | LSB);
MSB = wiringPiI2CReadReg16(fd, 0x2B);
LSB = wiringPiI2CReadReg16(fd, 0x2A);
y = ((MSB << 8) | LSB);
MSB = wiringPiI2CReadReg16(fd, 0x2D);
LSB = wiringPiI2CReadReg16(fd, 0x2C);
z = ((MSB << 8) | LSB);
}
這是我轉換的代碼:
#include <Wire.h>
#define CTRL_REG1 0x20
#define CTRL_REG2 0x21
#define CTRL_REG3 0x22
#define CTRL_REG4 0x23
int Addr = 105; // I2C address of gyro
int x, y, z;
void setup(){
Wire.begin();
Serial.begin(9600);
writeI2C(CTRL_REG1, 0x1F); // Turn on all axes, disable power down
writeI2C(CTRL_REG3, 0x08); // Enable control ready signal
writeI2C(CTRL_REG4, 0x80); // Set scale (500 deg/sec)
delay(100); // Wait to synchronize
}
void loop(){
getGyroValues(); // Get new values
// In following Dividing by 114 reduces noise
Serial.print("Raw X:"); Serial.print(x/114);
Serial.print(" Raw Y:"); Serial.print(y/114);
Serial.print(" Raw Z:"); Serial.println(z/114);
delay(500); // Short delay between reads
}
void getGyroValues() {
byte MSB, LSB;
MSB = readI2C(0x29);
LSB = readI2C(0x28);
x = ((MSB << 8) | LSB);
MSB = readI2C(0x2B);
LSB = readI2C(0x2A);
y = ((MSB << 8) | LSB);
MSB = readI2C(0x2D);
LSB = readI2C(0x2C);
z = ((MSB << 8) | LSB);
}
int readI2C (byte regAddr) {
Wire.beginTransmission(Addr);
Wire.write(regAddr); // Register address to read
Wire.endTransmission(); // Terminate request
Wire.requestFrom(Addr, 1); // Read a byte
while(!Wire.available()) { }; // Wait for receipt
return(Wire.read()); // Get result
}
void writeI2C (byte regAddr, byte val) {
Wire.beginTransmission(Addr);
Wire.write(regAddr);
Wire.write(val);
Wire.endTransmission();
}
減速=減速。 1個單詞中的2個錯誤完全改變了意思。 – 2013-03-03 10:45:25