Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAN transmission is working, but not the listening part #20

Open
Ipsitakoley opened this issue Sep 8, 2022 · 0 comments
Open

CAN transmission is working, but not the listening part #20

Ipsitakoley opened this issue Sep 8, 2022 · 0 comments

Comments

@Ipsitakoley
Copy link

Ipsitakoley commented Sep 8, 2022

We are using Sparkfun CAN shield and Arduino Uno to build a CAN network. We are observing the data in CAN network using KVaser Canking. When we send a data to the CAN bus, we can see the data in KVaser window. But, when we try to read something from the CAN bus, it is showing garbage values. Note that 120 ohm is also there. Here is the code:


`
#include <Canbus.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>

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

void setup() {
  Serial.begin(115200);
  Serial.println("CAN Write - Testing transmission of CAN Bus messages");
  delay(1000);
  
  if(Canbus.init(CANSPEED_250))  //Initialise MCP2515 CAN controller at the specified speed
    Serial.println("CAN Init ok");
  else
    Serial.println("Can't init CAN");
    
  delay(1000);
}
  
unsigned long now=0, prev=0; 
 
void loop() {
  mcp2515_bit_modify(CANCTRL, (1<<REQOP2)|(1<<REQOP1)|(1<<REQOP0), 0);
  tCAN message;  // message read from the bus
  tCAN amessage;

  // Attack message details
  amessage.id = 0x631; //formatted in HEX
  amessage.header.rtr = 0;
  amessage.header.length = 8; //formatted in DEC
  amessage.data[0] = 0x00;
  amessage.data[1] = 0x00;
  amessage.data[2] = 0x00;
  amessage.data[3] = 0x00; //formatted in HEX
  amessage.data[4] = 0x00;
  amessage.data[5] = 0x00;
  amessage.data[6] = 0x00;
  amessage.data[7] = 0x00;
  

   while(! mcp2515_check_message()){
    
   }
  
    if(mcp2515_get_message(&message) and message.id==0x630){ //wait for target message on the bus
      amessage.id = 0x630;
      mcp2515_send_message(&amessage);//this is not working
      Serial.println("Sending attack message");//this is not working
   }
  
       auto error_tec = mcp2515_read_register(TEC);
       Serial.print("TEC Count of adversary : "); //this is working
       Serial.println(error_tec);  //this is working
   
       
}

`Can some one help how to resolve this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant