MCP CAN and MPU650 bite each other
Posted: Thu Aug 20, 2020 1:13 pm
Hi , im currently building a connection from stm32f4 via canbus to arduino mega. Actually it works well, i had made two different programms and programmed Can message Sending and MPU Data logging.But if i want to use them both in the same script, the MPU throws zeros insteadt of normal values. If i commentate the MCP code out, it works again. Did someone having same isues and give me a idea where to search?.
if i commentate this out it works:
Sry for my bad english, didnt wrote for a whole lot of time in english.
Would be verry thanksfull if someone has an idea
Code: Select all
#include <Wire.h>
#include <Arduino.h>
#include <TinyMPU6050.h>
#include <can.h>
#include <mcp2515.h>
#include <SPI.h>
MPU6050 mpu(Wire);
struct can_frame canMsg1;
struct can_frame canMsg2;
MCP2515 mcp2515(PC1); // Set CS to pin 10
int rpm = 2;
void setup()
{SPI.setMOSI(PA7);
SPI.setMISO(PA6);
SPI.setSCLK(PA5);
SPI.begin();
Serial.begin(9600);
mcp2515.reset();
mcp2515.setBitrate(CAN_500KBPS,MCP_8MHZ);
mcp2515.setNormalMode();
mpu.Initialize();
// Calibration
Serial.begin(9600);
Serial.println("=====================================");
Serial.println("Starting calibration...");
mpu.Calibrate();
Serial.println("Calibration complete!");
}
void loop()
{
mpu.Execute();
delay(100);
int a = ((int)((mpu.GetAccX())));
int b = (int)((mpu.GetAccY()));
int c = (int)((mpu.GetAccZ()));
int d = (int)((mpu.GetGyroX()));
int e = (int)((mpu.GetGyroY()));
int f = (int)((mpu.GetGyroZ()));
delay(100);
Serial.println(a);
Serial.println(b);
Serial.println(c);
Serial.println(d);
Serial.println(e);
Serial.println(f);
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;
}
if i commentate this out it works:
Code: Select all
MCP2515 mcp2515(PC1);
Sry for my bad english, didnt wrote for a whole lot of time in english.
Would be verry thanksfull if someone has an idea