-
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nano 33 BLE, Example locks up #53
Comments
Hi 👋 ☕ While I can't exclude that you might experience a locking-up due to the critical section code it seems implausible to me. At least you'd be the first to report that problem. I've got two questions for you:
|
Hi, thanks for your help.
We have a custom PCB. Chip select is on pin 10, interrupt is on pin 9, 8 MHz clock, the bus is running at 500 kbps. We also wired up a breakout board (https://copperhilltech.com/mcp2515-can-bus-breakout-board-with-spi-interface/). As I remeber we also had the same problem with that setup, I have to check on monday.
When running the loopback example, something similar happens. I have modified the test loop as follows: std::for_each(CAN_TEST_FRAME_ARRAY.cbegin(),
CAN_TEST_FRAME_ARRAY.cend(),
[](sCanTestFrame const frame)
{
if(!mcp2515.transmit(frame.id, frame.data, frame.len)) {
Serial.println("ERROR TX");
}
Serial.println("foo");
Serial.println("bar");
delay(10);
Serial.println("baz");
}); The code execution freezes up after printing "foo" once. When commenting out To narrow down where the problem occurs I have littered MCP2515_io.cpp with prints, and also added prints to the select/deselect/transfer functions. void select_()
{
Serial.print(__func__); Serial.println(" begin");
digitalWrite(MKRCAN_MCP2515_CS_PIN, LOW);
Serial.print(__func__); Serial.println(" end");
}
void deselect_()
{
Serial.print(__func__); Serial.println(" begin");
digitalWrite(MKRCAN_MCP2515_CS_PIN, HIGH);
Serial.print(__func__); Serial.println(" end");
}
uint8_t transfer_(const uint8_t d)
{
Serial.print(__func__); Serial.println(" begin");
uint8_t y = SPI.transfer(d);
Serial.print(__func__); Serial.println(" end");
return y;
}
ArduinoMCP2515 mcp2515(select_,
deselect_,
transfer_,
micros,
onReceiveBufferFull,
nullptr); The output looks like this:
So the last function that gets executed is I guess this means this ticket can be closed as my problem isn't caused by this library, but still I would be thankful for any insight you might have into this issue. Thanks for your help. |
I did a little further digging. The Arduino docs on external interrupts say that ISRs should not use delay or do any serial IO, and in general should be kept short. The loopback example does serial IO in the ISR, but removing it didn't fix the problem. However, when I moved the static volatile int haveInterrupt;
// in setup()
attachInterrupt(digitalPinToInterrupt(MKRCAN_MCP2515_INT_PIN), [](){ haveInterrupt = 1; }, FALLING);
void loop()
{
if (haveInterrupt) {
haveInterrupt = 0;
mcp2515.onExternalEventHandler();
}
delay(5);
} Now the output is
While the Arduino no longer locks up, the interrupt is only triggered once. I'm not sure if I have to set it manucally back to high. On monday I'll hook up a scope to the pin and see what's acutally going on. |
I have another update. It was pointed out to me that the interrupt will only be triggered once because all the messages are sent from After moving everything to void loop()
{
static unsigned i = 0;
if (i < CAN_TEST_FRAME_ARRAY.size()) {
sCanTestFrame frame = CAN_TEST_FRAME_ARRAY[i++];
if (!mcp2515.transmit(frame.id, frame.data, frame.len)) {
Serial.println("ERROR TX");
}
delay(10);
}
if (haveInterrupt) {
haveInterrupt = 0;
mcp2515.onExternalEventHandler();
}
delay(5);
} output:
|
Good debugging effort 👍
This is true in general but the usage in this example should be acceptable.
This is false. Which reason was given to you for this statement? In any case, moving everything to |
I transferred the issue over to 107-Arduino-MCP2515 since the problems clearly start with the MCP2515 library. |
This was when I tried #53 (comment) All seven messages are sent during setup. When the interrupt is raised, messages are not processed by ISR. The interrupt is not raised on subsequent mesasges because the receive buffers are not empty. I'm paraphrasing, but I think that was the gist.
Perhaps the 33 BLE has more restrictions on ISRs? If found this in the Arduino forums:
Again, thanks for you help. |
Thank you for clarification 👍 Bit on clarification on my end, I do work for Arduino so I know the codebase so I don't see any issue with sending all those messages in the ISR or writing those couple of Serial messages from within the ISR 😉 I guess I'll have to wire up a board myself, but this will not happen soon-ish. |
🐛 Bug Report
On a Nano 33 BLE with a MPC2515, the UAVCAN-Heartbeat-Publish example locks up. The problem appears to be related to locking and/or interrupts, as it hangs when trying to aquire a lock. I managed to get it work by commenting out the locking code and disabling the interrupt.
I'm not entirely certain if this is truely a software bug. Perhaps this could also be caused by a wiring issue or misconfiguration?
Minimum configuration to replicate the bug
The text was updated successfully, but these errors were encountered: