107-systems / 107-Arduino-MCP2515

Arduino library for controlling the MCP2515 in order to receive/transmit CAN frames.
https://107-systems.org
MIT License
88 stars 14 forks source link

Fix: Only enable receive interrupts when a onReceive callback has been provided. #63

Closed aentinger closed 2 years ago

aentinger commented 2 years ago

This reduces the amount of SPI transactions in a network with heavy CAN traffic where no reception by a CAN node is required.

@generationmake can you please test?

github-actions[bot] commented 2 years ago

Memory usage change @ e535768351387a80a6f2c2b892e8d0dcc5959797

Board flash % RAM for global variables %
arduino:mbed_edge:edge_control 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_nano:nano33ble 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_nano:nanorp2040connect :small_red_triangle: +6 - +6 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m4 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m7 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkr1000 :small_red_triangle: +4 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrfox1200 :small_red_triangle: +4 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrgsm1400 :small_red_triangle: +4 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrnb1500 :small_red_triangle: +4 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrvidor4000 :small_red_triangle: +4 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrwan1300 :small_red_triangle: +4 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrwan1310 :small_red_triangle: +4 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrwifi1010 :small_red_triangle: +4 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrzero :small_red_triangle: +4 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
esp32:esp32:esp32 :small_red_triangle: +4 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
rp2040:rp2040:rpipico 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
Click for full report table Board|examples/MCP2515-CAN-Sniffer
flash|%|examples/MCP2515-CAN-Sniffer
RAM for global variables|%|examples/MCP2515-Loopback
flash|%|examples/MCP2515-Loopback
RAM for global variables|% -|-|-|-|-|-|-|-|- arduino:mbed_edge:edge_control|0|0.0|0|0.0|0|0.0|0|0.0 arduino:mbed_nano:nano33ble|0|0.0|0|0.0|0|0.0|0|0.0 arduino:mbed_nano:nanorp2040connect|6|0.0|0|0.0|6|0.0|0|0.0 arduino:mbed_portenta:envie_m4|0|0.0|0|0.0|0|0.0|0|0.0 arduino:mbed_portenta:envie_m7|0|0.0|0|0.0|0|0.0|0|0.0 arduino:samd:mkr1000|4|0.0|0|0.0|4|0.0|0|0.0 arduino:samd:mkrfox1200|4|0.0|0|0.0|4|0.0|0|0.0 arduino:samd:mkrgsm1400|4|0.0|0|0.0|4|0.0|0|0.0 arduino:samd:mkrnb1500|4|0.0|0|0.0|4|0.0|0|0.0 arduino:samd:mkrvidor4000|4|0.0|0|0.0|4|0.0|0|0.0 arduino:samd:mkrwan1300|4|0.0|0|0.0|4|0.0|0|0.0 arduino:samd:mkrwan1310|4|0.0|0|0.0|4|0.0|0|0.0 arduino:samd:mkrwifi1010|4|0.0|0|0.0|4|0.0|0|0.0 arduino:samd:mkrzero|4|0.0|0|0.0|4|0.0|0|0.0 esp32:esp32:esp32|4|0.0|0|0.0|4|0.0|0|0.0 rp2040:rp2040:rpipico|0|0.0|0|0.0|0|0.0|0|0.0
Click for full report CSV ``` Board,examples/MCP2515-CAN-Sniffer
flash,%,examples/MCP2515-CAN-Sniffer
RAM for global variables,%,examples/MCP2515-Loopback
flash,%,examples/MCP2515-Loopback
RAM for global variables,% arduino:mbed_edge:edge_control,0,0.0,0,0.0,0,0.0,0,0.0 arduino:mbed_nano:nano33ble,0,0.0,0,0.0,0,0.0,0,0.0 arduino:mbed_nano:nanorp2040connect,6,0.0,0,0.0,6,0.0,0,0.0 arduino:mbed_portenta:envie_m4,0,0.0,0,0.0,0,0.0,0,0.0 arduino:mbed_portenta:envie_m7,0,0.0,0,0.0,0,0.0,0,0.0 arduino:samd:mkr1000,4,0.0,0,0.0,4,0.0,0,0.0 arduino:samd:mkrfox1200,4,0.0,0,0.0,4,0.0,0,0.0 arduino:samd:mkrgsm1400,4,0.0,0,0.0,4,0.0,0,0.0 arduino:samd:mkrnb1500,4,0.0,0,0.0,4,0.0,0,0.0 arduino:samd:mkrvidor4000,4,0.0,0,0.0,4,0.0,0,0.0 arduino:samd:mkrwan1300,4,0.0,0,0.0,4,0.0,0,0.0 arduino:samd:mkrwan1310,4,0.0,0,0.0,4,0.0,0,0.0 arduino:samd:mkrwifi1010,4,0.0,0,0.0,4,0.0,0,0.0 arduino:samd:mkrzero,4,0.0,0,0.0,4,0.0,0,0.0 esp32:esp32:esp32,4,0.0,0,0.0,4,0.0,0,0.0 rp2040:rp2040:rpipico,0,0.0,0,0.0,0,0.0,0,0.0 ```
generationmake commented 2 years ago

hi @aentinger I made a small test with the aux controller: the code is still compiling and it seems to be working. I havent tested the reception of any can frames but i will do tomorrow.

aentinger commented 2 years ago

I havent tested the reception of any can frames but i will do tomorrow.

No reception should be possible anymore. But also the number of SPI transactions should be considerably smaller, which may be relevant in a high CAN bus traffic scenario. In any case, this is just a temporary band-aid. A better solution would be to put up filters.