adafruit / adafruit/Adafruit_CircuitPython_MCP2515

Must have another device read the bus.

Open
#21 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
29
Forks
16
PR merge metrics
No merged PRs in 30d

Description

This was killing me to debug.

I started in this configuration:
[No Pican installed on CAN bus](https://i.imgur.com/6oegs8l.jpg)

This is the code for the two feathers:

SENDING
```python
# 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:
```python
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)](https://i.imgur.com/egOrkBC.png)

Connecting the pican and having it read the messages from the bus.
[works as intended](https://i.imgur.com/I5i6okc.png)
[photo of pican attached](https://i.imgur.com/6oegs8l.jpg)

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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the example programs in the 1.1.2 examples directory and reproduce the sender and receive-only snippets at 1000000 baud, comparing the bus with and without the PiCAN attached. Determine the required CAN bus setup and whether the examples should operate without another device, then document or correct the behavior and verify it in both configurations.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
embedded-iot, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.