MPU9150 erreur code

Bonsoir

Désolé de vous déranger encore, quelqu’un peut m’aider à trouver l’erreur dans ce code svp :slight_smile:
(Code tags added by moderator)

#define MPU9150_DEFAULT_ADDRESS 0x68
#define MPU9150_ACCEL_XOUT_H 0x3B
#define MPU9150_TEMP_OUT_H 0x41
#define MPU9150_GYRO_XOUT_H 0x43
#define MPU9150_PWR_MGMT_1 0x6B

void
mpu9150_setup(void)
{
 /* clear the SLEEP bit to start the sensor */
 uint8_t reg[2] = {MPU9150_PWR_MGMT_1, 0};

 twi_master_setup(); /* i2c to master mode */
 twi_write_bytes((MPU9150_DEFAULT_ADDRESS << 1), 2, reg);
}

/*
* @return temperature in degrees C = (TEMP_OUT signed / 340) + 35
* */
int16_t
mpu9150_read_temperature(void)
{
 volatile uint8_t buffer[2] = { 0, 0 };
 uint8_t reg = MPU9150_TEMP_OUT_H;

 twi_read_bytes(MPU9150_DEFAULT_ADDRESS << 1, &reg, 2, buffer);

 int16_t temperature;
 temperature = ((buffer[0] << 8) + buffer[1]);
 temperature /= 340;
 temperature += 35;
 return temperature;
}


typedef struct
{
 int16_t x;
 int16_t y;
 int16_t z;
} x_y_z;


x_y_z
mpu9150_read_gyroscope(void)
{
 volatile uint8_t buffer[6];
 uint8_t reg = MPU9150_GYRO_XOUT_H;

 twi_read_bytes(MPU9150_DEFAULT_ADDRESS << 1, &reg, 6, buffer);

 x_y_z gyro;
 gyro.x = (buffer[0] << 8) + buffer[1];
 gyro.y = (buffer[2] << 8) + buffer[3];
 gyro.z = (buffer[4] << 8) + buffer[5];
 return gyro;
}

x_y_z
mpu9150_read_accelerometer(void)
{
 volatile uint8_t buffer[6];
 uint8_t reg = MPU9150_ACCEL_XOUT_H;

 twi_read_bytes(MPU9150_DEFAULT_ADDRESS << 1, &reg, 6, buffer);

 x_y_z accel;
 accel.x = (buffer[0] << 8) + buffer[1];
 accel.y = (buffer[2] << 8) + buffer[3];
 accel.z = (buffer[4] << 8) + buffer[5];
 return accel;
}

void
setup(void)
{
 usart_0_setup();
 usart_0_transmitter_enable();
 mpu9150_setup();
}

int
main(void)
{
 setup();
 _delay_ms(1000);

 while (1)
   {
     _delay_ms(1000);
     int16_t t = mpu9150_read_temperature();

     usart_0_transmit(t >> 8);
     usart_0_transmit(t);

     _delay_ms(1000);

     x_y_z gyro = mpu9150_read_gyroscope();

     usart_0_transmit(gyro.x >> 8);
     usart_0_transmit(gyro.x);
     usart_0_transmit(gyro.y >> 8);
     usart_0_transmit(gyro.y);
     usart_0_transmit(gyro.z >> 8);
     usart_0_transmit(gyro.z);

 _delay_ms(1000);

     x_y_z acc = mpu9150_read_accelerometer();

     usart_0_transmit(acc.x >> 8);
     usart_0_transmit(acc.x);
     usart_0_transmit(acc.y >> 8);
     usart_0_transmit(acc.y);
     usart_0_transmit(acc.z >> 8);
     usart_0_transmit(gyro.z);
   }
}

Mets ton code entre balise stp, c'est difficilement lisible

Voilà:

" #define MPU9150_DEFAULT_ADDRESS 0x68
#define MPU9150_ACCEL_XOUT_H 0x3B
#define MPU9150_TEMP_OUT_H 0x41
#define MPU9150_GYRO_XOUT_H 0x43
#define MPU9150_PWR_MGMT_1 0x6B

void
mpu9150_setup(void)
{
/* clear the SLEEP bit to start the sensor */
uint8_t reg[2] = {MPU9150_PWR_MGMT_1, 0};

twi_master_setup(); /* i2c to master mode */
twi_write_bytes((MPU9150_DEFAULT_ADDRESS << 1), 2, reg);
}

/*

  • @return temperature in degrees C = (TEMP_OUT signed / 340) + 35
  • */
    int16_t
    mpu9150_read_temperature(void)
    {
    volatile uint8_t buffer[2] = { 0, 0 };
    uint8_t reg = MPU9150_TEMP_OUT_H;

twi_read_bytes(MPU9150_DEFAULT_ADDRESS << 1, &reg, 2, buffer);

int16_t temperature;
temperature = ((buffer[0] << 8) + buffer[1]);
temperature /= 340;
temperature += 35;
return temperature;
}

typedef struct
{
int16_t x;
int16_t y;
int16_t z;
} x_y_z;

x_y_z
mpu9150_read_gyroscope(void)
{
volatile uint8_t buffer[6];
uint8_t reg = MPU9150_GYRO_XOUT_H;

twi_read_bytes(MPU9150_DEFAULT_ADDRESS << 1, &reg, 6, buffer);

x_y_z gyro;
gyro.x = (buffer[0] << 8) + buffer[1];
gyro.y = (buffer[2] << 8) + buffer[3];
gyro.z = (buffer[4] << 8) + buffer[5];
return gyro;
}

x_y_z
mpu9150_read_accelerometer(void)
{
volatile uint8_t buffer[6];
uint8_t reg = MPU9150_ACCEL_XOUT_H;

twi_read_bytes(MPU9150_DEFAULT_ADDRESS << 1, &reg, 6, buffer);

x_y_z accel;
accel.x = (buffer[0] << 8) + buffer[1];
accel.y = (buffer[2] << 8) + buffer[3];
accel.z = (buffer[4] << 8) + buffer[5];
return accel;
}

void
setup(void)
{
usart_0_setup();
usart_0_transmitter_enable();
mpu9150_setup();
}

int
main(void)
{
setup();
_delay_ms(1000);

while (1)
{
_delay_ms(1000);
int16_t t = mpu9150_read_temperature();

usart_0_transmit(t >> 8);
usart_0_transmit(t);

_delay_ms(1000);

x_y_z gyro = mpu9150_read_gyroscope();

usart_0_transmit(gyro.x >> 8);
usart_0_transmit(gyro.x);
usart_0_transmit(gyro.y >> 8);
usart_0_transmit(gyro.y);
usart_0_transmit(gyro.z >> 8);
usart_0_transmit(gyro.z);

_delay_ms(1000);

x_y_z acc = mpu9150_read_accelerometer();

usart_0_transmit(acc.x >> 8);
usart_0_transmit(acc.x);
usart_0_transmit(acc.y >> 8);
usart_0_transmit(acc.y);
usart_0_transmit(acc.z >> 8);
usart_0_transmit(gyro.z);
}

} "

Je suis désolé il m'a mit des smiley partout

Svp help me :S

Bonjour,

Yasso92: Je suis désolé il m'a mit des smiley partout

Svp help me :S

Ce n'est pour rien que l'on te dit de mettre le code entre balises : Voir ici

Si tu nous dit pas le message d'erreur on pourra pas faire grand chose.

Merci, je ne le savais pas :S

Voilà l’erreur:

Arduino : 1.6.5 (Windows 8.1), Carte : "Arduino Uno"

xbee_pro_servo_motor:12: error: 'x_y_z' does not name a type
xbee_pro_servo_motor:14: error: 'x_y_z' does not name a type
xbee_pro_servo_motor.ino: In function 'void mpu9150_setup()':
xbee_pro_servo_motor:13: error: 'twi_master_setup' was not declared in this scope
xbee_pro_servo_motor:14: error: 'twi_write_bytes' was not declared in this scope
xbee_pro_servo_motor.ino: In function 'int16_t mpu9150_read_temperature()':
xbee_pro_servo_motor:26: error: 'twi_read_bytes' was not declared in this scope
xbee_pro_servo_motor.ino: In function 'x_y_z mpu9150_read_gyroscope()':
xbee_pro_servo_motor:50: error: 'twi_read_bytes' was not declared in this scope
xbee_pro_servo_motor.ino: In function 'x_y_z mpu9150_read_accelerometer()':
xbee_pro_servo_motor:65: error: 'twi_read_bytes' was not declared in this scope
xbee_pro_servo_motor.ino: In function 'void setup()':
xbee_pro_servo_motor:77: error: 'usart_0_setup' was not declared in this scope
xbee_pro_servo_motor:78: error: 'usart_0_transmitter_enable' was not declared in this scope
xbee_pro_servo_motor.ino: In function 'int main()':
xbee_pro_servo_motor:93: error: 'usart_0_transmit' was not declared in this scope
'x_y_z' does not name a type

  Ce rapport contiendrait plus d'informations si l'option
  "Montrer les informations de sortie pendant la compilation"
  était activée dans Fichier > Préférences.

ça c’est le code:

#define MPU9150_DEFAULT_ADDRESS 0x68
#define MPU9150_ACCEL_XOUT_H 0x3B
#define MPU9150_TEMP_OUT_H 0x41
#define MPU9150_GYRO_XOUT_H 0x43
#define MPU9150_PWR_MGMT_1 0x6B

void
mpu9150_setup(void)
{
 /* clear the SLEEP bit to start the sensor */
 uint8_t reg[2] = {MPU9150_PWR_MGMT_1, 0};

 twi_master_setup(); /* i2c to master mode */
 twi_write_bytes((MPU9150_DEFAULT_ADDRESS << 1), 2, reg);
}

/*
* @return temperature in degrees C = (TEMP_OUT signed / 340) + 35
* */
int16_t
mpu9150_read_temperature(void)
{
 volatile uint8_t buffer[2] = { 0, 0 };
 uint8_t reg = MPU9150_TEMP_OUT_H;

 twi_read_bytes(MPU9150_DEFAULT_ADDRESS << 1, &reg, 2, buffer);

 int16_t temperature;
 temperature = ((buffer[0] << 8) + buffer[1]);
 temperature /= 340;
 temperature += 35;
 return temperature;
}


typedef struct
{
 int16_t x;
 int16_t y;
 int16_t z;
} x_y_z;


x_y_z
mpu9150_read_gyroscope(void)
{
 volatile uint8_t buffer[6];
 uint8_t reg = MPU9150_GYRO_XOUT_H;

 twi_read_bytes(MPU9150_DEFAULT_ADDRESS << 1, &reg, 6, buffer);

 x_y_z gyro;
 gyro.x = (buffer[0] << 8) + buffer[1];
 gyro.y = (buffer[2] << 8) + buffer[3];
 gyro.z = (buffer[4] << 8) + buffer[5];
 return gyro;
}

x_y_z
mpu9150_read_accelerometer(void)
{
 volatile uint8_t buffer[6];
 uint8_t reg = MPU9150_ACCEL_XOUT_H;

 twi_read_bytes(MPU9150_DEFAULT_ADDRESS << 1, &reg, 6, buffer);

 x_y_z accel;
 accel.x = (buffer[0] << 8) + buffer[1];
 accel.y = (buffer[2] << 8) + buffer[3];
 accel.z = (buffer[4] << 8) + buffer[5];
 return accel;
}

void
setup(void)
{
 usart_0_setup();
 usart_0_transmitter_enable();
 mpu9150_setup();
}

int
main(void)
{
 setup();
 _delay_ms(1000);

 while (1)
   {
     _delay_ms(1000);
     int16_t t = mpu9150_read_temperature();

     usart_0_transmit(t >> 8);
     usart_0_transmit(t);

     _delay_ms(1000);

     x_y_z gyro = mpu9150_read_gyroscope();

     usart_0_transmit(gyro.x >> 8);
     usart_0_transmit(gyro.x);
     usart_0_transmit(gyro.y >> 8);
     usart_0_transmit(gyro.y);
     usart_0_transmit(gyro.z >> 8);
     usart_0_transmit(gyro.z);

 _delay_ms(1000);

     x_y_z acc = mpu9150_read_accelerometer();

     usart_0_transmit(acc.x >> 8);
     usart_0_transmit(acc.x);
     usart_0_transmit(acc.y >> 8);
     usart_0_transmit(acc.y);
     usart_0_transmit(acc.z >> 8);
     usart_0_transmit(gyro.z);
   }
}

Merci encore!

Déjà le nom x_y_z ne lui plait pas. donc change de nom dans ton code et essaye de recompiler. Tu verras de ou viens ta deuxième erreur. Il suffit de lire le rapport d erreur. Et de corriger les erreurs une par une.

Justement le problème est que je ne sais par quoi le remplacer

Merci quand même :)

Pierre, Paul ou Jacques!
Peut importe… Temps que tu remplace x_y_z PARTOUT dans ton code par exemple par cliors (par ce que j en ai une) et tu verras que tu ne serras plus dérangé. Ce qui dérange dans le nom c est les “_” tout simplement.

Merci de votre réponse

Donc je dois supprimer tous les "_"??

Parce que j'ai changer le "x_y_z" mais c'est encore pire ;/