ttlappalainen / NMEA2000_mcp

Inherited object for use NMEA2000 library for Arduino Boards with MCP2515 CAN bus controller.
20 stars 19 forks source link

MCP_CAN library receive problem - simple solution #8

Open hellmutbrudny opened 1 year ago

hellmutbrudny commented 1 year ago

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 ;).

ttlappalainen commented 1 year ago

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

hellmutbrudny commented 1 year ago

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?