circuitpython esp32-S3 N16R8固件:https://circuitpython.org/board/yd_esp32_s3_n16r8/
要下载bin格式的

文档:https://docs.circuitpython.org/en/latest/shared-bindings/canio/index.html

单片机和can收发器之间tx、rx不需要交叉接线!!!

刷固件

  1. 将esp32上的TTL口连接到电脑,使用esptool写入固件:
    esptool --chip esp32s3 --port COM13 erase_flash
    esptool --chip esp32s3 --port COM13 write_flash -z 0 adafruit-circuitpython-yd_esp32_s3_n16r8-zh_Latn_pinyin-9.2.1.bin
    端口要换成自己的
  2. 写入完成之后连接到esp32上的OTG口,电脑会多出一个盘,之后可以像micropython一样使用
    在这里插入图片描述
    在这里插入图片描述

代码

import board
import canio

print(dir(board)) # 查看所有接口名称

can = canio.CAN(rx=board.GPIO6, tx=board.GPIO5, baudrate=1000000, auto_restart=True) # 可以任选两个未使用的gpio口
listener = can.listen()

message = canio.Message(id=123, data='123') # 可选参数extended:是否使用扩展帧
can.send(message)
msg = listener.receive()
print(msg.id, msg.data, msg.extended)
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐