CAn Signals getting skipped

For the discussion of Arduino related topics.

Moderator: phalanx

Post Reply
sameer_PSW
Posts: 2
Joined: Tue Jun 19, 2018 12:36 am

CAn Signals getting skipped

Post by sameer_PSW » Tue Jun 19, 2018 12:43 am

Hello everyone,

I am using two Arduino Uno Boards and a sparkfun CAN Shield and I am recieving signals from external Hardware over CAN Bus to one Arduino board and these signals are then send to other Arduino Board unsing I2C Communication.

But Sometimes CAN Signals are getting skipped and sometimes they are not. And when wire transmission is not involved then it's working perfectly fine.

Mostly Message id: 0x3 is getting skipped.

Can anyone please help me with this issue as I need to use wire transmission?

Code: Select all

#include <Canbus.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>
#include <stdlib.h>
#include <math.h>
#include <Wire.h>


byte Bot_1[8];
byte Bot_2[8];
byte Bot_3[8];
byte Bot_4[8];

//********************************Setup Loop*********************************//

void setup() {
   Wire.begin();
  Serial.begin(9600); // For debug use
  Serial.println("CAN Read - Testing receival of CAN Bus message");
  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");
}

//********************************Main Loop*********************************//

void loop()
{


  tCAN message;
  if (mcp2515_check_message())
  {
    if (mcp2515_get_message(&message))
    { 

      if (message.id == 0x2) //Botschaft 1
      {
      Bot_1[0]=message.data[0];
      Bot_1[1]=message.data[1];
      Bot_1[2]=message.data[2];
      Bot_1[3]=message.data[3];
      Bot_1[4]=message.data[4];
      Bot_1[5]=message.data[5];
      Bot_1[6]=message.data[6];
      Bot_1[7]=message.data[7];
      Serial.println("Bot_1");
      }
 
      if (message.id == 0x1) //Botschaft 2
      {
      Bot_2[0]=message.data[0];
      Bot_2[1]=message.data[1];
      Bot_2[2]=message.data[2];
      Bot_2[3]=message.data[3];
      Bot_2[4]=message.data[4];
      Bot_2[5]=message.data[5];
      Bot_2[6]=message.data[6];
      Bot_2[7]=message.data[7];

      Serial.println("Bot_2");
      }

      if (message.id == 0x0) //Botschaft 3
      {
      Bot_3[0]=message.data[0];
      Bot_3[1]=message.data[1];
      Bot_3[2]=message.data[2];
      Bot_3[3]=message.data[3];
      Bot_3[4]=message.data[4];
      Bot_3[5]=message.data[5];
      Bot_3[6]=message.data[6];
      Bot_3[7]=message.data[7];
      Serial.println("Bot_3");
      }
   
      if (message.id == 0x3) //Botschaft 4
      {
      Bot_4[0]=message.data[0];
      Bot_4[1]=message.data[1];
      Bot_4[2]=message.data[2];
      Bot_4[3]=message.data[3];
      Bot_4[4]=message.data[4];
      Bot_4[5]=message.data[5];
      Bot_4[6]=message.data[6];
      Bot_4[7]=message.data[7];
      Serial.println("Bot_4");
      }

  Wire.beginTransmission(8); // transmit to device #8
  Wire.write(Bot_1,8);
  Wire.write(Bot_2,8);
  Wire.write(Bot_3,8);
  Wire.write(Bot_4,8);
  Wire.endTransmission();    // stop transmitting
    }
  }

}



paulvha
Posts: 222
Joined: Sat Nov 11, 2017 2:39 am

Re: CAn Signals getting skipped

Post by paulvha » Thu Jun 21, 2018 9:47 am

could it be a timing problem ?

Why not "write.write()" only the received "botschaft": Make ONE Bot-array and ONE entry longer (9 instead of 8). Store the message_id in the extra entry (Bot[8] = message.id) Then just write.write (Bot, 9); The receiving Arduino can checked/ handle the message parsing.

sameer_PSW
Posts: 2
Joined: Tue Jun 19, 2018 12:36 am

Re: CanBus Signals getting skipped

Post by sameer_PSW » Thu Jun 28, 2018 4:41 am

Hello,

Thank you for the advice and I tried in the manner you proposed. But still the problem persists.
And regarding the timing problem, I can't make any statement as I am not able to figure it out. Is their any possibility to check if it is timing oriented?

Regards

Post Reply