pierremolinaro / acan2517

Arduino CAN driver for MCP2517FD CAN Controller (in CAN 2.0B mode)
MIT License
22 stars 10 forks source link

RaspberryPi Pico(RP2040) with MCP2518FDClick #23

Open rn-ksheer opened 3 weeks ago

rn-ksheer commented 3 weeks ago

Hi Pierre,

I was successful in using acan2517 lib on Arduino nano with MCP2518FDClick board as sender and UNO with MCP2515 as receiver. I am unable to do the same with pico development board, The program compiles and uploads without any errors but not receiving any frames at UNO side. I have read your pdf document and made the changes to use custom SPI pins, still no success. Please point the necessary settings required to make pico work with MCP2518FDClick.

`SPI.setRX(16); SPI.setTX(19); SPI.setSCK(18); SPI.setCS(17); SPI.begin();

ACAN2517Settings settings (ACAN2517Settings::OSC_20MHz, 500UL * 1000UL) ; settings.mRequestedMode = ACAN2517Settings::Normal20B; // Select loopback mode`

Koryphon commented 3 weeks ago

Hello @rn-ksheer

These pins correspond to SPI1, not SPI (aka SPI0 according to the documentation)

Best regards

rn-ksheer commented 3 weeks ago

hi @Koryphon ,

The pins I have used are default SPI (SPI0), Ref- arduino-pico & pico pinout.

When i disconnect any one of the SPI pins from pico , i get Configuration error 0x1 & when all pins are connected the below info gets printed on serial monitor which confirms lib is communication with pico.

sizeof (ACAN2517Settings): 32 bytes
Configure ACAN2517
MCP2517FD RAM Usage: 1024 bytes
Bit Rate prescaler: 1
Phase segment 1: 31
Phase segment 2: 8
SJW:8
Actual bit rate: 500000 bit/s
Exact bit rate ? yes
Sample point: 80%
Sent: 1
Sent: 2

I must be missing some other setting. In ACAN2517.cpp, line 265 has _mSPISettings = SPISettings (800UL * 1000, MSBFIRST, SPIMODE0) ; Does pico need clock speed adjustment here?

Koryphon commented 3 weeks ago

Oups. Sorry. I checked the PIN number instead of the GPIO number.

rn-ksheer commented 3 weeks ago

Finally got it working !! Since i used default SPI pins, defining pin numbers in void setup was not required, SPI.begin handels it. Only if alternate pins are being used it has to be SET in void setup. VIO SEL is set to 3v3 , STBY & STBY SEL are in their default position. Tested with both 20MHz & 40MHz.

regards, π–±π–Ύπ—‡π—Ž π–ͺπ—Œπ—π—‚π—‹π—Œπ–Ίπ—€π–Ίπ—‹

pico | mcp2518FD -- | -- GP16 | SDO GP17 | CS GP18 | SCK GP19 | SDI GP20 | INT 3V3 | 3V3 VBUS | 5V GND | GND

pico_MCP2518FD