Hello,
I am sending signals (8 signals) over CAN bus to Arduino Uno and trying to use these signals in a function but as soon as I am calling a function in loop, I am getting only half of the signals over CAN and when function is not called CAN bus communication is working perfectly fine.
I am struggling to find the problem, can anyone please provide some insights to solve this issue.
Thanking you in anticipation
Regards
/****************************************************************************
*************************************************************************/
#include <Canbus.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>
#include <stdlib.h>
#include <math.h>
int M1, M2, M3, M4, M5, M6, M7, M8;
//********************************Setup Loop*********************************//
void setup() {
Serial.begin(9600); // For debug use
Serial.println("CAN Read - Testing receival of CAN Bus message");
delay(1000);
if (Canbus.init(CANSPEED_500)) //Initialise MCP2515 CAN controller at the specified speed
Serial.println("CAN Init ok");
else
Serial.println("Can't init CAN");
delay(1000);
}
//********************************Main Loop*********************************//
void loop()
{
can_lesen();
Test_call(M1, M2, M3, M4, M5, M6);
}
//********************************CAN Read*********************************//
void can_lesen() {
tCAN message;
if (mcp2515_check_message())
{
if (mcp2515_get_message(&message))
{
if (message.id == 0xA) //Botschaft 1
{
M1 = String(message.data[0] + message.data[1] * 256, DEC).toInt();
M2 = String(message.data[2] + message.data[3] * 256, DEC).toInt();
M3 = String(message.data[4] + message.data[5] * 256, DEC).toInt();
M4 = String(message.data[6] + message.data[7] * 256, DEC).toInt();
Serial.println("Executed_1"); //for Debugging
}
if (message.id == 0xB) //Botschaft 2
{
M5 = String(message.data[0] + message.data[1] * 256, DEC).toInt();
M6 = String(message.data[2] + message.data[3] * 256, DEC).toInt();
M7 = String(message.data[4] + message.data[5] * 256, DEC).toInt();
M8 = String(message.data[6] + message.data[7] * 256, DEC).toInt();
Serial.println("Executed_2"); //for Debugging
}
}
}
}
//********************************Test Function*********************************//
void Test_call(int red, int green, int blue, int SpeedDelay, int ReturnDelay, int Batterieladung) {
Serial.print(red);
Serial.print(" ");
Serial.print(green);
Serial.print(" ");
Serial.print(blue);
Serial.print(" ");
Serial.print(SpeedDelay);
Serial.print(" ");
Serial.print(ReturnDelay);
Serial.print(" ");
Serial.print(Batterieladung);
Serial.println(" ");
}