CANBUS Receiving Hardware ID

Hello,

I am struggling to communicate with a CAN hardware device and receive back its hardware ID.

Program structure:

Send *IDN? to CAN hardware device and receive back ID and print to terminal.

Looking at my attached code, can you see any obvious mistakes?

Many thanks in advance.

Thanks,
Sparky84

// Required libraries
#include "variant.h"
#include <due_can.h>

//Leave defined if you use native port, comment if using programming port
#define Serial SerialUSB

void setup()
{

  Serial.begin(115200);
  
  // Initialize CAN0, Set the proper baud rates here
  Can0.begin(CAN_BPS_250K);
  
  Can0.watchFor();  
}

void sendData()
{
  CAN_FRAME outgoing;
  outgoing.id = 0x00;  // ***** 0x400
  outgoing.extended = false;
  outgoing.priority = 4; //0-15 lower is higher priority
  
  outgoing.data.byte[0] = 0x00;
  outgoing.data.byte[1] = 0x2a; // *
  outgoing.data.byte[2] = 0x49; // I
  outgoing.data.byte[3] = 0x44; // D
  outgoing.data.byte[4] = 0x4e; // N
  outgoing.data.byte[5] = 0x3f; // ?
  outgoing.data.byte[6] = 0x00;
  outgoing.data.byte[7] = 0x00;
  
  Can0.sendFrame(outgoing);
}

void loop(){
  CAN_FRAME incoming;
  static unsigned long lastTime = 0;


  if (Can0.available() > 0) 
  {
	   Can0.read(incoming);
    
     for (int count = 0; count < incoming.length; count++) 
     {
        Serial.print(incoming.data.bytes[count], HEX);  
     }

     Serial.print("\r\n");
 
  }


  if ((millis() - lastTime) > 1000) 
  {
     lastTime = millis(); 
     sendData();   
  }
}

I can see a lot of possible problems. Post an annotated schematic showing exactly how you have connected everything. Be sure to show all components, connections, power sources, grounds etc.

I have no clue as to what your hardware device is or if it can respond with its ID. Post links to its technical information.

Hello gilshultz,

Please see attached the schematic diagram of the Due, CAN breakout board, switch and wiring.

This switch has previously worked on an old PC system (windows xp), so I know the *IDN? command works with the switch. However the PC systems is long gone and I am trying to replicate the system with the attached schematic.

I am struggling to get any response from the switch (no datasheet available, but I am assured the 4 wire interface is correct), and I just require confirmation the code and schematic will enable the switch to operate correctly?

Lastly do you recommend an ICE to help debug future developments?

Many thanks,
Sparky84