NMEA2000_mcp icon indicating copy to clipboard operation
NMEA2000_mcp copied to clipboard

MCP_CAN library receive problem - simple solution

Open hellmutbrudny opened this issue 1 year ago • 2 comments

Hi. I've just been testing Longan CANBed 2040 board with integrated mcp2515. It didn't worked because https://github.com/ttlappalainen/CAN_BUS_Shield/blob/master/mcp_can.cpp -> MCP_CAN::mcp2515_read_canMsg() lacks SPI_HAS_TRANSACTION handling. All need to be done is adding SPI_BEGIN/END around:

#ifdef SPI_HAS_TRANSACTION SPI_BEGIN(); #endif MCP2515_SELECT(); ... MCP2515_UNSELECT(); #ifdef SPI_HAS_TRANSACTION SPI_END(); #endif

Apparently original SeedStudion library has the same problem. But it is specifically for their board while MCP_CAN probably can handle any board with mcp2515 (I have been testing it with Arduino Nano Every + cheap MCP2515 CAN module as well as with RPi Pico + Waveshare RS485 CAN HAT).

And by the way - big thank you @ttlappalainen for the great job! It gave me a lot of inspiration and help. I hope my comment will help somebody too ;).

hellmutbrudny avatar Feb 28 '23 13:02 hellmutbrudny

I do not use mcp_can anymore. Do you have any idea will that effect to other boards used with mcp_can?

ttlappalainen avatar Feb 28 '23 14:02 ttlappalainen

I guess it will affect any MCU board that needs/uses SPI transactions (to communicate with mcp2515) - on plus ;). But since it's under compiler condition which is widely used in this file I think it's rather safe. If that's what concerns you?

hellmutbrudny avatar Feb 28 '23 14:02 hellmutbrudny