CAN BUS Problem bei stmp!

Hallo.
Bitte um tips! Bei einfache Programm ist ein fehler aber ich kann ihm nicht finden!
Can Bus soll nachricht senden. Er sendet kein "stmp"

#include <Wire.h>

#include <SPI.h>

#define CAN_2515

#if defined(SEEED_WIO_TERMINAL) && defined(CAN_2518FD)

const int SPI_CS_PIN = BCM8;

const int CAN_INT_PIN = BCM25;

#else

const int SPI_CS_PIN = 10;

const int CAN_INT_PIN = 2;

#endif

#ifdef CAN_2518FD

#include "mcp2518_can.h"

mcp2518fd CAN(SPI_CS_PIN); // Set CS pin

#endif

#ifdef CAN_2515

#include "mcp2515_can.h"

mcp2515_can CAN(SPI_CS_PIN); // Set CS pin

#endif

void setup() {

SERIAL_PORT_MONITOR.begin(9600);

while(!Serial){};

while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k

    SERIAL_PORT_MONITOR.println("CAN init fail");

    delay(100);

}

}

unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};

void loop() {

  • stmp[0] = 0x01; // 1 = Laden ON*

  • stmp[1] = 0xE8; // 3E8 = 1000 = 100% liefern*

** stmp[2] = 0x03;**

** stmp[3] = 0x0E; //F6E = 3950 = 395V maximal**

** stmp[4] = 0xF6;**

** stmp[5] = 0x50; //50 = 80 = 8A maximal**


** stmp[6] = 0x00;**

** stmp[7] = 0x00;**

CAN.sendMsgBuf(0x2ff,0,0,0,stmp); // stmp sendet nicht!!!!

delay(950);

}

Where did you get the library from?

I found this...

Maybe you need?

CAN.sendMsgBuf(0x2ff,0,8,stmp);

Hy. From ther: CAN-BUS Shield V2.0 - Seeed Wiki

Da sehe ich:

grafik

Arduino: 1.8.18 (Windows 10), Board: "Arduino Uno"

C:\Users\adamn\OneDrive\Dokumente\Arduino\CANladen\CANladen.ino: In function 'void loop()':

CANladen:98:34: error: no matching function for call to 'mcp2515_can::sendMsgBuf(int, int, int, unsigned char [8])'

 CAN.sendMsgBuf(0x2ff,0,8,stmp);

                              ^

In file included from C:\Users\adamn\OneDrive\Dokumente\Arduino\CANladen\CANladen.ino:44:0:

C:\Users\adamn\OneDrive\Dokumente\Arduino\libraries\Seeed_Arduino_CAN-master\src/mcp2515_can.h:93:18: note: candidate: virtual byte mcp2515_can::sendMsgBuf(byte, long unsigned int, byte, byte, byte, const volatile byte*)

 virtual byte sendMsgBuf(byte status, unsigned long id, byte ext, byte rtrBit, byte len, volatile const byte *buf);                                  // send message buf by using parsed buffer status

              ^~~~~~~~~~

C:\Users\adamn\OneDrive\Dokumente\Arduino\libraries\Seeed_Arduino_CAN-master\src/mcp2515_can.h:93:18: note: candidate expects 6 arguments, 4 provided

C:\Users\adamn\OneDrive\Dokumente\Arduino\libraries\Seeed_Arduino_CAN-master\src/mcp2515_can.h:94:18: note: candidate: virtual byte mcp2515_can::sendMsgBuf(long unsigned int, byte, byte, byte, const byte*, bool)

 virtual byte sendMsgBuf(unsigned long id, byte ext, byte rtrBit, byte len, const byte *buf, bool wait_sent = true);                                 // send buf

              ^~~~~~~~~~

C:\Users\adamn\OneDrive\Dokumente\Arduino\libraries\Seeed_Arduino_CAN-master\src/mcp2515_can.h:94:18: note: candidate expects 6 arguments, 4 provided

exit status 1

no matching function for call to 'mcp2515_can::sendMsgBuf(int, int, int, unsigned char [8])'

Ich glaube das library hat ein problem

Wenn Du Dein Programm in #1 ordentlich formatierst, könnte ich es mal in meine IDE kopieren und schauen, was bei mir passiert.

Mir fällt gerade auf, wenn Du die Anzahl der zu sendenden Bytes auf Null setzt, wird wohl nichts gesendet. Also mal so probieren:

CAN.sendMsgBuf(0x2ff, 0, 0, 8, stmp);
#include <Wire.h>

#include <SPI.h>

#define CAN_2515

#if defined(SEEED_WIO_TERMINAL) && defined(CAN_2518FD)

const int SPI_CS_PIN  = BCM8;

const int CAN_INT_PIN = BCM25;

#else

const int SPI_CS_PIN = 10;

const int CAN_INT_PIN = 2;

#endif
 

#ifdef CAN_2518FD

#include "mcp2518_can.h"

mcp2518fd CAN(SPI_CS_PIN); 

#endif

#ifdef CAN_2515

#include "mcp2515_can.h"

mcp2515_can CAN(SPI_CS_PIN);

#endif

const int LED        = 8;
boolean ledON        = 1;
 

void setup() {

 

    SERIAL_PORT_MONITOR.begin(9600);
    pinMode(LED, OUTPUT);
    while(!Serial){};

    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k

        SERIAL_PORT_MONITOR.println("CAN init fail");
        delay(1000);

    }
SERIAL_PORT_MONITOR.println("CAN init ok!");
}


unsigned char stmp[8] = {0,1, 2, 3, 4};

void loop() {


    stmp[0] = 0x01;     // 1 = Laden ON

    stmp[1] = 0xE8;     

    stmp[2] = 0x03;

    stmp[3] = 0x74;     

    stmp[4] = 0x04;

    stmp[5] = 0x64;     
    
    stmp[6] = 0x00;

    stmp[7] = 0x00;
 

    CAN.sendMsgBuf(0x2ff,0,0,8,stmp); //(long unsigned int, byte, byte, byte, const byte*, bool)
    

   
    unsigned char len = 0;
    unsigned char buf[8];

    if (CAN_MSGAVAIL == CAN.checkReceive()) {         // check if data coming
        CAN.readMsgBuf(&len, buf);    // read data,  len: data length, buf: data buf

        unsigned long canId = CAN.getCanId();

        SERIAL_PORT_MONITOR.println("-----------------------------");
        SERIAL_PORT_MONITOR.println("get data from ID: 0x");
        SERIAL_PORT_MONITOR.println(canId, HEX);

        for (int i = 0; i < len; i++) { // print the data
            SERIAL_PORT_MONITOR.print(buf[i]);
            SERIAL_PORT_MONITOR.print("\t");
            if (ledON && i == 0) {

                digitalWrite(LED, buf[i]);
                ledON = 0;
                delay(950);
            } else if ((!(ledON)) && i == 4) {

                digitalWrite(LED, buf[i]);
                ledON = 1;
            }
        }
        SERIAL_PORT_MONITOR.println();
    }
    delay(950);
}

ich weiß nicht was los aber jetzt ghet's nur ich bekomme 3 can nachrichten zusammen

Mit delay den Datenempfang zu blockieren, halte ich für keine gute Idee.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.