Sending INT over CAN_SHIELD not Possible

hey guys,

i have the problem since two days.

First i show you what i got:

void UpdatePointer(void) {
  if (initComplete == 9) {
    digitalWrite(ncs, LOW);
    xydat[0] = (int)adns_read_reg(REG_Delta_X_L);
    xydat[1] = (int)adns_read_reg(REG_Delta_Y_L);
    digitalWrite(ncs, HIGH);
    //sendMsg(0x01, 1, 1, 1, xydat[0]);
    //const int SPI_CS_PIN = 5;
    //MCP_CAN CAN(SPI_CS_PIN);        // Set CS pin
    //byte sndStat = CAN.sendMsgBuf(0x1CFF01F2, 1, 2, xydat[0]);
    //CAN.sendMsgBuf(0x01, 0, 2, xydat[0]);
    Serial.println(xydat[0]);
    Serial.println(xydat[1]);
    movementflag = 1;
  }
}

you can see, how much i change something to get an solution.
You should also know, the programm works with the serial.println fine.

libary is included

Any Suggestions?

mcp_can.h (8.54 KB)

mcp_can_dfs.h (13.4 KB)

What do you receive from the send line? Is it only one byte of the integer? Have you tried to send the two bytes individually and then reconstitute them?

        xydat[0] = (int)adns_read_reg(REG_Delta_X_L);
        xydat[1] = (int)adns_read_reg(REG_Delta_Y_L);

since you're casting the adns_read_reg() to an int, suggests that xydat is at least an array of integers.

presumably you need to pass sendMsgBuf() a pointer to the data and the size should be the total number of bytes, at least 4, 2 bytes/integer

        byte sndStat = CAN.sendMsgBuf(0x1CFF01F2, 1, sizeof(xydat), & xydat[0]);

adwsystems:
What do you receive from the send line? Is it only one byte of the integer? Have you tried to send the two bytes individually and then reconstitute them?

I can't get it working. I try everything. If it will be compiled.. I'm sure I can received them with a professional measurement equipment. That is Not the problem.

Furthermore I get a cheaper Adns sensor to work and send it also before over can.

nitecmusic:
I can't get it working.

What is not working? We can only help with specific issues and details. Lots of information has been provided. What have you tried? How did it fail?

adwsystems:
What is not working? We can only help with specific issues and details. Lots of information has been provided. What have you tried? How did it fail?

Sry adwsystems,

i try this now

byte sndStat = CAN.sendMsgBuf(0x01, 1, sizeof(xydat), & xydat[0]);

and i get

no matching function for call to 'MCP_CAN::sendMsgBuf(int, int, unsigned int, volatile int*)'

do you need to cast the pointer to a byte ?

byte sndStat = CAN.sendMsgBuf(0x01, 1, sizeof(xydat), (uint8_t*)& xydat[0]);

Here is how I break down a int into a byte to send over CAN

 // prep item for sending over CAN buss
        if (!PassTwo)
        {
          rx_frame.FIR.B.FF = CAN_frame_std;
          rx_frame.MsgID = 1;
          rx_frame.FIR.B.DLC = 8;
          rx_frame.data.u8[0] = *item & 0xFF;
          rx_frame.data.u8[1] = (*item >> 8) & 0xFF;
          rx_frame.data.u8[2] = (*item >> 16) & 0xFF;
          rx_frame.data.u8[3] = (*item >> 24) & 0xFF;
          PassTwo = true;
        } else {
          rx_frame.data.u8[4] = *item & 0xFF;;
          rx_frame.data.u8[5] = (*item >> 8) & 0xFF;
          rx_frame.data.u8[6] = (*item >> 16) & 0xFF;
          rx_frame.data.u8[7] = (*item >> 24) & 0xFF;
          ESP32Can.CANWriteFrame(&rx_frame); // send items over CAN buss
          PassTwo = false;
        }

there no need ....

just pass a pointer to your data (e.g. long) case as a byte pointer (i.e. (byte *) & longVar and specify the size of the data in bytes (e.g. sizeof(longVar) or sizeof(longVarArray))