pierremolinaro / acan2515

MCP2515 CAN Controller Driver for Arduino
MIT License
74 stars 29 forks source link

can.begin crashes when using rpi pico, with offical mbed rp2040 board #31

Open qwec01 opened 2 years ago

qwec01 commented 2 years ago

Hi I have a raspberry pi pico, using Arduino offical mbed rp2040 board. When I test the LoopBackDemoRaspberryPiPICO sketch, my pico crashes and the LED blinks 4 short and 4 long and repeat. With some digging in(insert Serial.println into src/ACAN2515.cpp), I found that it crashes at the mSPI.beginTransaction (mSPISettings) ; line in fuction ACAN2515::beginWithoutFilterCheck, then I checked this line: mSPISettings (10UL * 1000UL * 1000UL, MSBFIRST, SPI_MODE0),, after reading the comment, I think maybe the "UL suffix" is incompatible with offical mbed rp2040 board, so I simply changed the frequency to 10000000, and uploaded the sketch, my pico never crashes! I don't know how to edit the cpp to adapt both AVR arduino and rpi pico, so I just report this bug. Thanks for your hardwork. qwec01

pierremolinaro commented 2 years ago

Hi,

Integer type literal values are very confusing in C / C++, and unsigned is a 16 bit unsigned integer value on 8 bit microcontrollers, and 32-bit unsigned integer value on. 32 bit ones.

Use uint32_t type, it is always a 32 bit unsigned value, on every platform.

Trick: declare a constant: const uint32_t SPI_speed = uint32_t (10) 1000 1000 ; or const uint32_t SPI_speed = uint32_t (10) uint32_t (1000) uint32_t (1000) ;

and print it with Serial.print for checking its value. Serial.print (SPI_speed) ;

Pierre

Le 21 févr. 2022 à 14:43, qwec01 @.***> a écrit :

Hi I have a raspberry pi pico, using Arduino offical mbed rp2040 board. When I test the LoopBackDemoRaspberryPiPICO sketch, my pico crashes and the LED blinks 4 short and 4 long and repeat. With some digging in(insert Serial.println into src/ACAN2515.cpp), I found that it crashes at the mSPI.beginTransaction (mSPISettings) ; line in fuction ACAN2515::beginWithoutFilterCheck, then I checked this line: mSPISettings (10UL 1000UL 1000UL, MSBFIRST, SPI_MODE0),, after reading the comment, I think maybe the "UL suffix" is incompatible with offical mbed rp2040 board, so I simply changed the frequency to 10000000, and uploaded the sketch, the crash went away! I don't know how to edit the cpp to adapt both AVR arduino and rpi pico, so I just report this bug. Thanks for your hardwork.

— Reply to this email directly, view it on GitHub https://github.com/pierremolinaro/acan2515/issues/31, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEWKZVGTVESYT3XKBYJOQ3TU4I6Q7ANCNFSM5O6UMOKQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you are subscribed to this thread.