m5stack / M5StickC

M5StickC Arduino Library
MIT License
476 stars 221 forks source link

Example for CAN (Controller Area Network) Unit (ca-is3050g) #137

Closed aldas closed 3 years ago

aldas commented 3 years ago

I am trying to get CAN unit working with M5StickC but failing at it. I own also M5Atom CAN which works fine when I modify example in that repository https://github.com/m5stack/M5Atom/blob/master/examples/ATOM_BASE/ATOM_CAN/ATOM_CAN.ino to use pins 26/32 (connecting with HY2.0 4P interface)

  CAN_cfg.tx_pin_id = GPIO_NUM_26;  // SDA
  CAN_cfg.rx_pin_id = GPIO_NUM_32;  // SCL

I have seen example of CAN in M5Stack repostory which seems to be pretty much same as M5Atom but I do not understand why M5StickC will not work

My initialization part is for M5StickC

#include <M5StickC.h>
#include "ESP32CAN.h"
#include "CAN_config.h"

...
...
...

void setup()
{
  M5.begin(false, true, true);
  Serial.println("CAN Unit Send");

  CAN_cfg.speed = CAN_SPEED_250KBPS;

  // CAN_cfg.tx_pin_id = GPIO_NUM_26;
  // CAN_cfg.rx_pin_id = GPIO_NUM_36;

  CAN_cfg.tx_pin_id = GPIO_NUM_32; // groove SDA (yellow)
  CAN_cfg.rx_pin_id = GPIO_NUM_33; // groove SCL (white)

  CAN_cfg.rx_queue = xQueueCreate(rx_queue_size, sizeof(CAN_frame_t));
  ESP32Can.CANInit();
}

...
...
...

I think I have correct pins. CAN unit LED is turned on but same code for sending can frames does not seem to produce packets in bus (I use USB can dongle to debug bus). Sending part is same as Atom/M5Stack has.

I have tryed to use also pins 26/36 on the top of M5StickC instead of groove (HY2.0 4P interface) but that also does not work for me.

aldas commented 3 years ago

nevermind - I had modified code and had a bug which blocked sending frames. These examples work fine if you do not modify them. closing