Hi i tried myself by searching.
First i threw out the MPU Librarie and hardcoded the mpu part
So actual code is:
Code: Select all
#include <can.h>
#include <mcp2515.h>
#include <SPI.h>
int gyro_x, gyro_y, gyro_z;
long acc_x, acc_y, acc_z, acc_total_vector;
int temperature;
long gyro_x_cal, gyro_y_cal, gyro_z_cal;
long loop_timer;
int lcd_loop_counter;
float angle_pitch, angle_roll, angle_yaw;
int angle_pitch_buffer, angle_roll_buffer, angle_yaw_buffer;
//boolean set_gyro_angles;
float angle_roll_acc, angle_pitch_acc, angle_yaw_acc;
float angle_pitch_output, angle_roll_output, angle_yaw_output;
struct can_frame canMsg1;
struct can_frame canMsg2;
MCP2515 mcp2515(PC1); // Set CS to pin 10
int rpm = 2;
void setup() {
wire.begin();
}
void loop() {
delay(1000);
}
{
Serial.begin(9600);//not needed
Wire.begin();
delay(250);
SPI.setMOSI(PA7);
SPI.setMISO(PA6);
SPI.setSCLK(PA5);
SPI.begin();
setup_mpu_6050_registers();
}
void read_mpu_6050_data() { //Subroutine for reading the raw gyro and accelerometer data
Wire.beginTransmission(0x68); //Start communicating with the MPU-6050
Wire.write(0x3B); //Send the requested starting register
Wire.endTransmission(); //End the transmission
Wire.requestFrom(0x68, 14); //Request 14 bytes from the MPU-6050
while (Wire.available() < 14); //Wait until all the bytes are received
acc_x = Wire.read() << 8 | Wire.read(); //Add the low and high byte to the acc_x variable
acc_y = Wire.read() << 8 | Wire.read(); //Add the low and high byte to the acc_y variable
acc_z = Wire.read() << 8 | Wire.read(); //Add the low and high byte to the acc_z variable
temperature = Wire.read() << 8 | Wire.read(); //Add the low and high byte to the temperature variable
gyro_x = Wire.read() << 8 | Wire.read(); //Add the low and high byte to the gyro_x variable
gyro_y = Wire.read() << 8 | Wire.read(); //Add the low and high byte to the gyro_y variable
gyro_z = Wire.read() << 8 | Wire.read(); //Add the low and high byte to the gyro_z variable
}
void setup_mpu_6050_registers() {
//Activate the MPU-6050
wire.beginTransmission(0x68); //Start communicating with the MPU-6050
wire.write(0x6B); //Send the requested starting register
wire.write(0x00); //Set the requested starting register
wire.endTransmission(); //End the transmission
//Configure the accelerometer (+/-8g)
wire.beginTransmission(0x68); //Start communicating with the MPU-6050
wire.write(0x1C); //Send the requested starting register
wire.write(0x10); //Set the requested starting register
wire.endTransmission(); //End the transmission
//Configure the gyro (500dps full scale)
wire.beginTransmission(0x68); //Start communicating with the MPU-6050
wire.write(0x1B); //Send the requested starting register
wire.write(0x08); //Set the requested starting register
wire.endTransmission(); //End the transmission
}
void loop()
{
read_mpu_6050_data();
int a = (int)(acc_x);
int b = (int)(acc_y);
int c = (int)(acc_z);
int d = (int)(gyro_x);
int e = (int)(gyro_y);
int f = (int)(gyro_z);
delay(100);
Serial.print("X = ");
Serial.println(gyro_x);
Serial.print("Y = ");
Serial.println(gyro_y);
Serial.print("Z = ");
Serial.println();
delay(250);
canMsg1.can_id = 0x0F6;
canMsg1.can_dlc = 8;
canMsg1.data[0] = a;
canMsg1.data[1] = b;
canMsg1.data[2] = c;
canMsg1.data[3] = d;
canMsg1.data[4] = e;
canMsg1.data[5] = f;
canMsg1.data[6] = 0xBE;
canMsg1.data[7] = 0x86;
canMsg2.can_id = 0x036;
canMsg2.can_dlc = 8;
canMsg2.data[2] = a;
canMsg2.data[6] = 0x00;
canMsg2.data[7] = 0xA0;
mcp2515.sendMessage(&canMsg1);
delay(1000); // send dat int b = (int)a;
}
For me it looks like the mcp can library deactivates the i2c interface
Cause if i commentate the
out, the imu is giving data which are plausible. With this in, the imu doesnt throw any changing data.
MCP Library :
https://github.com/autowp/arduino-mcp2515
Or is it that kind of problem:
viewtopic.php?f=18&t=630&p=4101&hilit=i2c+spi#p4101 --> I tryed to redefine , but nothing changend