M5StampS3 / M5Dial and CAN
-
Has anyone got the CAN unit to work with the ESP32 S3 devices?
I end up with a load of compiled messages when I try using the ported Atom examples using Platformio
It looks like the problem is in CAN.c and the TWAI driver
see
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/twai.htmlError Messages
"In file included from C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_reg.h:21,
from src/CAN.c:38:
src/CAN.c: In function 'CAN_init':
src/CAN.c:169:29: error: 'DPORT_PERIP_CLK_EN_REG' undeclared (first use in this function); did
you mean 'SYSTEM_PERIP_CLK_EN1_REG'?
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_CAN_CLK_EN);
^~~~~~~~~~~~~~~~~~~~~~
C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:75:67: note: in definition of macro '_DPORT_WRITE_PERI_REG'
#define _DPORT_WRITE_PERI_REG(addr, val) (*((volatile uint32_t )(addr))) = (uint32_t)(val)
^~~~
C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:88:46: note: in expansion of macro 'DPORT_WRITE_PERI_REG'
#define DPORT_SET_PERI_REG_MASK(reg, mask) DPORT_WRITE_PERI_REG((reg), (DPORT_READ_PERI_REG(reg)|(mask)))
^~~~~~~~~~~~~~~~~~~~
src/CAN.c:169:5: note: in expansion of macro 'DPORT_SET_PERI_REG_MASK'
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_CAN_CLK_EN);
^~~~~~~~~~~~~~~~~~~~~~~
src/CAN.c:169:29: note: each undeclared identifier is reported only once for each function it appears in
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_CAN_CLK_EN);
^~~~~~~~~~~~~~~~~~~~~~
C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:75:67: note: in definition of macro '_DPORT_WRITE_PERI_REG'
#define _DPORT_WRITE_PERI_REG(addr, val) (((volatile uint32_t )(addr))) = (uint32_t)(val)
^~~~
C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:88:46: note: in expansion of macro 'DPORT_WRITE_PERI_REG'
#define DPORT_SET_PERI_REG_MASK(reg, mask) DPORT_WRITE_PERI_REG((reg), (DPORT_READ_PERI_REG(reg)|(mask)))
^~~~~~~~~~~~~~~~~~~~
src/CAN.c:169:5: note: in expansion of macro 'DPORT_SET_PERI_REG_MASK'
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_CAN_CLK_EN);
^~~~~~~~~~~~~~~~~~~~~~~
src/CAN.c:169:53: error: 'DPORT_CAN_CLK_EN' undeclared (first use in this function); did you mean 'DPORT_REG_CLR_BIT'?
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_CAN_CLK_EN);
^~~~~~~~~~~~~~~~
C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:75:88: note: in definition of macro '_DPORT_WRITE_PERI_REG'
#define _DPORT_WRITE_PERI_REG(addr, val) (((volatile uint32_t )(addr))) = (uint32_t)(val)
^~~
C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:88:46: note: in expansion of macro 'DPORT_WRITE_PERI_REG'
#define DPORT_SET_PERI_REG_MASK(reg, mask) DPORT_WRITE_PERI_REG((reg), (DPORT_READ_PERI_REG(reg)|(mask)))
^~~~~~~~~~~~~~~~~~~~
src/CAN.c:169:5: note: in expansion of macro 'DPORT_SET_PERI_REG_MASK'
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_CAN_CLK_EN);
^~~~~~~~~~~~~~~~~~~~~~~
src/CAN.c:170:31: error: 'DPORT_PERIP_RST_EN_REG' undeclared (first use in this function); did
you mean 'SYSTEM_PERIP_RST_EN0_REG'?
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_CAN_RST);
^~~~~~~~~~~~~~~~~~~~~~
C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:75:67: note: in definition of macro '_DPORT_WRITE_PERI_REG'
#define _DPORT_WRITE_PERI_REG(addr, val) (((volatile uint32_t )(addr))) = (uint32_t)(val)
^~~~
C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:85:46: note: in expansion of macro 'DPORT_WRITE_PERI_REG'
#define DPORT_CLEAR_PERI_REG_MASK(reg, mask) DPORT_WRITE_PERI_REG((reg), (DPORT_READ_PERI_REG(reg)&(~(mask))))
^~~~~~~~~~~~~~~~~~~~
src/CAN.c:170:5: note: in expansion of macro 'DPORT_CLEAR_PERI_REG_MASK'
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_CAN_RST);
^~~~~~~~~~~~~~~~~~~~~~~~~
src/CAN.c:170:55: error: 'DPORT_CAN_RST' undeclared (first use in this function); did you mean
'DPORT_DATE_REG'?
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_CAN_RST);
^~~~~~~~~~~~~
C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:75:88: note: in definition of macro '_DPORT_WRITE_PERI_REG'
#define _DPORT_WRITE_PERI_REG(addr, val) (((volatile uint32_t )(addr))) = (uint32_t)(val)
^~~
C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:85:46: note: in expansion of macro 'DPORT_WRITE_PERI_REG'
#define DPORT_CLEAR_PERI_REG_MASK(reg, mask) DPORT_WRITE_PERI_REG((reg), (DPORT_READ_PERI_REG(reg)&(~(mask))))
^~~~~~~~~~~~~~~~~~~~
src/CAN.c:170:5: note: in expansion of macro 'DPORT_CLEAR_PERI_REG_MASK'
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_CAN_RST);
^~~~~~~~~~~~~~~~~~~~~~~~~
src/CAN.c:175:40: error: 'CAN_TX_IDX' undeclared (first use in this function); did you mean 'TWAI_TX_IDX'?
gpio_matrix_out(CAN_cfg.tx_pin_id, CAN_TX_IDX, 0, 0);
^~~~~~~~~~
TWAI_TX_IDX
src/CAN.c:180:39: error: 'CAN_RX_IDX' undeclared (first use in this function); did you mean 'TWAI_RX_IDX'?
gpio_matrix_in(CAN_cfg.rx_pin_id, CAN_RX_IDX, 0);
^~~~~~~~~~
TWAI_RX_IDX
src/CAN.c:252:20: error: 'ETS_CAN_INTR_SOURCE' undeclared (first use in this function)
esp_intr_alloc(ETS_CAN_INTR_SOURCE, 0, CAN_isr, NULL, NULL);
^~~~~~~~~~~~~~~~~~~
Compiling .pio\build\m5stack-stamps3\src\main.cpp.o
Compiling .pio\build\m5stack-stamps3\lib421\ESP32CAN\CAN.c.o
In file included from .pio/libdeps/m5stack-stamps3/ESP32CAN/src/CAN.c:37:
C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/esp_hw_support/include/esp_intr.h:8:2: warning: #warning esp_intr.h is deprecated, please include esp_intr_alloc.h instead [-Wcpp]
#warning esp_intr.h is deprecated, please include esp_intr_alloc.h instead
^~~~~~~
In file included from C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_reg.h:21,
from .pio/libdeps/m5stack-stamps3/ESP32CAN/src/CAN.c:38:
.pio/libdeps/m5stack-stamps3/ESP32CAN/src/CAN.c: In function 'CAN_init':
.pio/libdeps/m5stack-stamps3/ESP32CAN/src/CAN.c:173:26: error: 'DPORT_PERIP_CLK_EN_REG' undeclared (first use in this function); did you mean 'SYSTEM_PERIP_CLK_EN1_REG'?
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_CAN_CLK_EN);
^~~~~~~~~~~~~~~~~~~~~~
C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:75:67: note: in definition of macro '_DPORT_WRITE_PERI_REG'
#define _DPORT_WRITE_PERI_REG(addr, val) (((volatile uint32_t )(addr))) = (uint32_t)(val)
^~~~
C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:88:46: note: in expansion of macro 'DPORT_WRITE_PERI_REG'
#define DPORT_SET_PERI_REG_MASK(reg, mask) DPORT_WRITE_PERI_REG((reg), (DPORT_READ_PERI_REG(reg)|(mask)))
^~~~~~~~~~~~~~~~~~~~
.pio/libdeps/m5stack-stamps3/ESP32CAN/src/CAN.c:173:2: note: in expansion of macro 'DPORT_SET_PERI_REG_MASK'
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_CAN_CLK_EN);
^~~~~~~~~~~~~~~~~~~~~~~
.pio/libdeps/m5stack-stamps3/ESP32CAN/src/CAN.c:173:26: note: each undeclared identifier is reported only once for each function it appears in
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_CAN_CLK_EN);
^~~~~~~~~~~~~~~~~~~~~~
C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:75:67: note: in definition of macro '_DPORT_WRITE_PERI_REG'
#define _DPORT_WRITE_PERI_REG(addr, val) (((volatile uint32_t )(addr))) = (uint32_t)(val)
^~~~
C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:88:46: note: in expansion of macro 'DPORT_WRITE_PERI_REG'
#define DPORT_SET_PERI_REG_MASK(reg, mask) DPORT_WRITE_PERI_REG((reg), (DPORT_READ_PERI_REG(reg)|(mask)))
^~~~~~~~~~~~~~~~~~~~
.pio/libdeps/m5stack-stamps3/ESP32CAN/src/CAN.c:173:2: note: in expansion of macro 'DPORT_SET_PERI_REG_MASK'
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_CAN_CLK_EN);
^~~~~~~~~~~~~~~~~~~~~~~
.pio/libdeps/m5stack-stamps3/ESP32CAN/src/CAN.c:173:50: error: 'DPORT_CAN_CLK_EN' undeclared (first use in this function); did you mean 'DPORT_REG_CLR_BIT'?
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_CAN_CLK_EN);
^~~~~~~~~~~~~~~~
C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:75:88: note: in definition of macro '_DPORT_WRITE_PERI_REG'
#define _DPORT_WRITE_PERI_REG(addr, val) (((volatile uint32_t )(addr))) = (uint32_t)(val)
^~~
C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:88:46: note: in expansion of macro 'DPORT_WRITE_PERI_REG'
#define DPORT_SET_PERI_REG_MASK(reg, mask) DPORT_WRITE_PERI_REG((reg), (DPORT_READ_PERI_REG(reg)|(mask)))
^~~~~~~~~~~~~~~~~~~~
.pio/libdeps/m5stack-stamps3/ESP32CAN/src/CAN.c:173:2: note: in expansion of macro 'DPORT_SET_PERI_REG_MASK'
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_CAN_CLK_EN);
^~~~~~~~~~~~~~~~~~~~~~~
.pio/libdeps/m5stack-stamps3/ESP32CAN/src/CAN.c:174:28: error: 'DPORT_PERIP_RST_EN_REG' undeclared (first use in this function); did you mean 'SYSTEM_PERIP_RST_EN0_REG'?
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_CAN_RST);
^~~~~~~~~~~~~~~~~~~~~~
C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:75:67: note: in definition of macro '_DPORT_WRITE_PERI_REG'
#define _DPORT_WRITE_PERI_REG(addr, val) (((volatile uint32_t )(addr))) = (uint32_t)(val)
^~~~
C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:85:46: note: in expansion of macro 'DPORT_WRITE_PERI_REG'
#define DPORT_CLEAR_PERI_REG_MASK(reg, mask) DPORT_WRITE_PERI_REG((reg), (DPORT_READ_PERI_REG(reg)&(~(mask))))
^~~~~~~~~~~~~~~~~~~~
.pio/libdeps/m5stack-stamps3/ESP32CAN/src/CAN.c:174:2: note: in expansion of macro 'DPORT_CLEAR_PERI_REG_MASK'
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_CAN_RST);
^~~~~~~~~~~~~~~~~~~~~~~~~
.pio/libdeps/m5stack-stamps3/ESP32CAN/src/CAN.c:174:52: error: 'DPORT_CAN_RST' undeclared (first use in this function); did you mean 'DPORT_DATE_REG'?
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_CAN_RST);
^~~~~~~~~~~~~
C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:75:88: note: in definition of macro '_DPORT_WRITE_PERI_REG'
#define _DPORT_WRITE_PERI_REG(addr, val) (((volatile uint32_t *)(addr))) = (uint32_t)(val)
^~~
C:/Users/simon/.platformio/packages/framework-arduinoespressif32@src-e2e946657dbcd16e4aabb8a644a06175/tools/sdk/esp32s3/include/soc/esp32s3/include/soc/dport_access.h:85:46: note: in expansion of macro 'DPORT_WRITE_PERI_REG'
#define DPORT_CLEAR_PERI_REG_MASK(reg, mask) DPORT_WRITE_PERI_REG((reg), (DPORT_READ_PERI_REG(reg)&(~(mask))))
^~~~~~~~~~~~~~~~~~~~
.pio/libdeps/m5stack-stamps3/ESP32CAN/src/CAN.c:174:2: note: in expansion of macro 'DPORT_CLEAR_PERI_REG_MASK'
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_CAN_RST);
^~~~~~~~~~~~~~~~~~~~~~~~~
.pio/libdeps/m5stack-stamps3/ESP32CAN/src/CAN.c:179:37: error: 'CAN_TX_IDX' undeclared (first use in this function); did you mean 'TWAI_TX_IDX'?
gpio_matrix_out(CAN_cfg.tx_pin_id, CAN_TX_IDX, 0, 0);
^~~~~~~~~~
TWAI_TX_IDX
.pio/libdeps/m5stack-stamps3/ESP32CAN/src/CAN.c:184:36: error: 'CAN_RX_IDX' undeclared (first use in this function); did you mean 'TWAI_RX_IDX'?
gpio_matrix_in(CAN_cfg.rx_pin_id, CAN_RX_IDX, 0);
^~~~~~~~~~
TWAI_RX_IDX
.pio/libdeps/m5stack-stamps3/ESP32CAN/src/CAN.c:254:17: error: 'ETS_CAN_INTR_SOURCE' undeclared (first use in this function)
esp_intr_alloc(ETS_CAN_INTR_SOURCE, 0, CAN_isr, NULL, NULL);
^~~~~~~~~~~~~~~~~~~
*** [.pio\build\m5stack-stamps3\src\CAN.c.o] Error 1
*** [.pio\build\m5stack-stamps3\lib421\ESP32CAN\CAN.c.o] Error 1
================================= [FAILED] Took 16.27 seconds ================================="Source code
"
/**- @file encoder.ino
- @author SeanKwok (shaoxiang@m5stack.com)
- @brief M5Dial Encoder Test
- @version 0.2
- @date 2023-10-18
- @Hardwares: M5Dial
- https://shop.m5stack.com/products/m5stack-dial-esp32-s3-smart-rotary-knob-w-1-28-round-touch-screen
- https://docs.m5stack.com/en/core/M5Dial
- https://github.com/m5stack/M5Dial
- @Platform Version: Arduino M5Stack Board Manager v2.0.7
- @Dependent Library:
- M5GFX: https://github.com/m5stack/M5GFX
- M5Unified: https://github.com/m5stack/M5Unified
- CANBus Unit(CA-IS3050G) Grove cable connected
- https://shop.m5stack.com/products/canbus-unitca-is3050g
- https://docs.m5stack.com/en/unit/can?ref=kmjp2x8a
- https://github.com/m5stack/M5Stack/tree/master/examples/Unit/CAN
*/
#include "M5Dial.h"
#include <M5Unified.h>
#include <M5GFX.h>
#include <ESP32CAN.h>
#include <CAN_config.h>
#include "driver/twai.h"/****** comment out to make sender ********/
#define CAN_RECIEVER // Remove to make sender#define Use_PortB // Remove to use Port A (Red)
#define CAN_MSG_ID 0x001
CAN_device_t CAN_cfg; // CAN Config.
unsigned long previousMillis = 0; // will store last time a CAN Message was sent // send. 将存储上次发送CAN消息的时间。
const int interval = 80; // interval at which send CAN Messages (milliseconds).const int rx_queue_size = 10; // Receive Queue size.
int LedNumberCount = 0;
int waitCANData = 0;uint8_t msgcnt = 0;
void setup()
{auto cfg = M5.config(); M5Dial.begin(cfg, true, false); M5Dial.Display.setTextColor(GREEN); M5Dial.Display.setTextDatum(middle_center); M5Dial.Display.setFont(&fonts::Orbitron_Light_32); M5Dial.Display.setTextSize(1); M5Dial.Display.drawString(String("Dial CAN"), M5Dial.Display.width() / 2, M5Dial.Display.height() / 2); M5.Lcd.println("M5Stack Core2 and CAN Bus adaptor"); // Print a string on the screen. M5.Lcd.setTextColor(ORANGE);
// M5.Lcd.println("* sending a string to be converted to upper case, ");
// M5.Lcd.println(" receiving response and display it on Terminal. *");Serial.println("Basic Demo - ESP32-Arduino-CAN"); Serial.println("M5Stack CoreS3 and CAN Bus adaptor"); Serial.println("* sending a string to be converted to upper case, *"); Serial.println("* receiving response and display it on a Terminal. *"); /* set CAN pins */ // GROVE connector GPIO pins
#ifdef Use_PortB
// Port B
CAN_cfg.tx_pin_id = GPIO_NUM_1; //
CAN_cfg.rx_pin_id = GPIO_NUM_2;
#else
// Port A Red Port (Shared with I2C)
CAN_cfg.tx_pin_id = GPIO_NUM_15; // SCL
CAN_cfg.rx_pin_id = GPIO_NUM_13; // SDA
#endifCAN_cfg.speed = CAN_SPEED_500KBPS; CAN_cfg.rx_queue = xQueueCreate(rx_queue_size, sizeof(CAN_frame_t)); ESP32Can.CANInit(); Serial.println("CAN Installed");
#ifdef CAN_RECIEVER
Serial.println("Set as RECIEVER");
//M5.Lcd.println("* Set as RECIEVER ");
#else
Serial.println("Set as SENDER");
M5.Lcd.println(" Set as SENDER *");
#endif}
void loop()
{
unsigned long currentMillis = millis();#ifdef CAN_RECIEVER
// recieve CAN Message CAN_frame_t rx_frame; if (xQueueReceive(CAN_cfg.rx_queue, &rx_frame, 3 * portTICK_PERIOD_MS) == pdTRUE) { if (rx_frame.FIR.B.FF == CAN_frame_std) { Serial.printf("New standard frame"); } else { Serial.printf("New extended frame"); } if (rx_frame.FIR.B.RTR == CAN_RTR) { Serial.printf(" RTR from 0x%08X, DLC %d\r\n", rx_frame.MsgID, rx_frame.FIR.B.DLC); } else { Serial.printf(" from 0x%08X, DLC %d, Data ", rx_frame.MsgID, rx_frame.FIR.B.DLC); for (int i = 0; i < rx_frame.FIR.B.DLC; i++) { Serial.printf("0x%02X ", rx_frame.data.u8[i]); } Serial.printf("\n"); if (rx_frame.data.u8[0] == 0x01) { CAN_frame_t tx_frame; tx_frame.FIR.B.FF = CAN_frame_std; tx_frame.MsgID = CAN_MSG_ID; tx_frame.FIR.B.DLC = 8; tx_frame.data.u8[0] = 0x02; tx_frame.data.u8[1] = rx_frame.data.u8[1]; tx_frame.data.u8[2] = 0x00; tx_frame.data.u8[3] = 0x00; tx_frame.data.u8[4] = 0x00; tx_frame.data.u8[5] = 0x00; tx_frame.data.u8[6] = 0x00; tx_frame.data.u8[7] = 0x00; ESP32Can.CANWriteFrame(&tx_frame); } } }
#else
// Send CAN Message
if (currentMillis - previousMillis >= interval)
{
ESP32Can.CANInit();
previousMillis = currentMillis;
CAN_frame_t tx_frame;
tx_frame.FIR.B.FF = CAN_frame_std;
tx_frame.MsgID = CAN_MSG_ID;
tx_frame.FIR.B.DLC = 8;
tx_frame.data.u8[0] = 0x01;
tx_frame.data.u8[1] = msgcnt;
tx_frame.data.u8[2] = 0x00;
tx_frame.data.u8[3] = 0x00;
tx_frame.data.u8[4] = 0x00;
tx_frame.data.u8[5] = 0x00;
tx_frame.data.u8[6] = 0x00;
tx_frame.data.u8[7] = 0x00;ESP32Can.CANWriteFrame(&tx_frame); ESP32Can.CANStop(); msgcnt++; if (msgcnt > 29) { msgcnt = 0; } } CAN_frame_t rx_frame; if (xQueueReceive(CAN_cfg.rx_queue, &rx_frame, 3 * portTICK_PERIOD_MS) == pdTRUE) { if (rx_frame.FIR.B.FF == CAN_frame_std) { Serial.printf("New standard frame"); } else { Serial.printf("New extended frame"); } if (rx_frame.FIR.B.RTR == CAN_RTR) { Serial.printf(" RTR from 0x%08X, DLC %d\r\n", rx_frame.MsgID, rx_frame.FIR.B.DLC); } else { Serial.printf(" from 0x%08X, DLC %d, Data ", rx_frame.MsgID, rx_frame.FIR.B.DLC); for (int i = 0; i < rx_frame.FIR.B.DLC; i++) { Serial.printf("0x%02X ", rx_frame.data.u8[i]); } Serial.printf("\n"); if (rx_frame.data.u8[0] == 0x02) { if (rx_frame.data.u8[1] < 25) { Serial.println("x"); //M5.dis.drawpix(rx_frame.data.u8[1], CRGB(100, 0, 0)); } else if (rx_frame.data.u8[1] > 27) { Serial.println("y"); //M5.dis.fillpix(CRGB(0, 0, 20)); } waitCANData = 0; } } }
#endif
// waitCANData
M5.update();
if (M5.BtnA.isPressed())
{
M5.Lcd.fillScreen(YELLOW);
esp_restart();
}
delay(10);
}
"Platformio.ini
"
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html[env:m5stack-stamps3]
platform = espressif32
board = m5stack-stamps3
framework = arduino
lib_deps =
m5stack/M5Dial@^1.0.2
m5stack/M5Unified@^0.1.11
m5stack/M5GFX@^0.1.11
miwagner/ESP32CAN@^0.0.1
platform_packages = framework-arduinoespressif32@https://github.com/espressif/arduino-esp32/archive/refs/tags/2.0.14.zip
lib_ldf_mode = deep+
upload_speed = 1500000
upload_port = COM7
monitor_speed = 115200
monitor_port = COM7
" -
-
Hi Felix
Do you know if there is any plan to develop/recommend one as the M5Dial is perfect for Automotive applications?Yours Simon M.
-