-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
This was killing me to debug.
I started in this configuration:
No Pican installed on CAN bus
This is the code for the two feathers:
SENDING
# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries
#
# SPDX-License-Identifier: MIT
from time import sleep
import board
import busio
from digitalio import DigitalInOut
from adafruit_mcp2515.canio import Message, RemoteTransmissionRequest
from adafruit_mcp2515 import MCP2515 as CAN
from canmessage import CanMessage
cs = DigitalInOut(board.CAN_CS)
cs.switch_to_output()
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
can_bus = CAN(spi, cs,baudrate=1000000)
cm = CanMessage()
cm.next()
cm.reset()
while True:
with can_bus.listen() as listener:
cm.next()
message = Message(cm.id, data=cm.data)
cm.reset()
send_success = can_bus.send(message)
print("Send success:", send_success)
print(f"Send details: id{message.id} d{message.data}")
message_count = listener.in_waiting()
print(message_count, "messages available")
for _i in range(message_count):
msg = listener.receive()
print("Message from ", hex(msg.id))
if isinstance(msg, Message):
print("message data:", msg.data)
if isinstance(msg, RemoteTransmissionRequest):
print("RTR length:", msg.length)
sleep(1)RECEIVE ONLY:
import digitalio
import board
import busio
from adafruit_mcp2515.canio import RemoteTransmissionRequest, Message
from adafruit_mcp2515 import MCP2515 as CAN
cs = digitalio.DigitalInOut(board.CAN_CS)
cs.switch_to_output()
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
mcp = CAN(spi, cs, silent=True,baudrate=1000000)
mcp.restart()
neo_on = False
next_message = None
message_num = 0
while True:
# print occationally to show we're alive
with mcp.listen(timeout=1) as listener:
message_count = mcp.unread_message_count
if message_count == 0:
continue
print(message_count)
next_message = mcp.read_message()
message_num = 0
while not next_message is None:
message_num += 1
msg = next_message
print(f"mnum{message_num} ID:{hex(msg.id)}", end=",")
if isinstance(msg, Message):
if len(msg.data) > 0:
pass
print(f"Data:{msg.data}")
# message_str = ",".join(["0x{:02X}".format(i) for i in msg.data])
# print(message_str)
if isinstance(msg, RemoteTransmissionRequest):
print("RTR_LEN:", msg.length)
next_message = mcp.read_message()Without the pican hooked up this is what happens
putty output from send (left) // receive (right)
Connecting the pican and having it read the messages from the bus.
works as intended
photo of pican attached
What the pican is doing is simply reading the messages from the bus. without the pican attached the example programs provided on https://github.com/adafruit/Adafruit_CircuitPython_MCP2515/tree/1.1.2/examples do not work at any baudrate. With the pican attached and reading from the bus they work at 1000000 baud.
Metadata
Metadata
Assignees
Labels
No labels