-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with dual canbus #23
Comments
Hello,
I never tried to connect 2 MCP2515, but it should work.
I suppose you have called SPI.begin () before CAN1.begin or CAN2.begin ?
What platform do you use ? Arduino Uno ? Can you post the sketch ?
Pierre
… Le 23 nov. 2020 à 10:13, ngochoangimsat ***@***.***> a écrit :
I tried to connect 2 MCP2515 to MCU via SPI but only first CAN can begin() successful, the second never run
.............
ACAN2515 CAN1(MCP2515_CS1, SPI, MCP2515_INT1);
ACAN2515 CAN2(MCP2515_CS2, SPI, MCP2515_INT2);
........
//This config will run CAN1 OK, CAN2 hang at begin()
const uint16_t errorCode1 = CAN1.begin (settings1, [] { CAN1.isr () ; }) ;
const uint16_t errorCode2 = CAN2.begin (settings2, [] { CAN2.isr () ; }) ;
//This config will run CAN2 OK, CAN1 hang at begin()
const uint16_t errorCode2 = CAN2.begin (settings2, [] { CAN2.isr () ; }) ;
const uint16_t errorCode1 = CAN1.begin (settings1, [] { CAN1.isr () ; }) ;
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub <#23>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AEWKZVBZSZWAH7PEL5QMZ2DSRIRTZANCNFSM4T7GVC4Q>.
|
Bellow is the sketch, i used arduino nano `#include <ACAN2515.h> static const byte MCP2515_CS2 = A3 ; // CS input of MCP2515 CAN2 static const uint32_t QUARTZ_FREQUENCY = 16UL * 1000UL * 1000UL; // 16 MHz void setup() { ACAN2515Settings settings2(QUARTZ_FREQUENCY, 500UL * 1000UL); } void loop() { }` |
Hello,
Thank you for your sketch, and I have noted you use an Arduino nano.
The Arduino nano MCU is an ATmega328, with 2 KB of SRAM. 2 KB, it's very little, may be you have a SRAM overflow. Internal receive and transmit buffers are dynamically allocated by the begin function.
The workaround is to decrease the receive and transmit buffer size. Can you try :
ACAN2515Settings settings (QUARTZ_FREQUENCY, 500UL * 1000UL); //CAN1 500kps
settings.mReceiveBufferSize = 1 ; // Default value 32, minimum is 1
settings.mTransmitBuffer0Size = 0 ; // Default value 16, 0 is safe
settings.mTransmitBuffer1Size = 0 ; // Useless, as default value is 0
settings.mTransmitBuffer2Size = 0 ; // Useless, as default value is 0
const uint16_t errorCode1 = CAN1.begin(settings, [] {CAN1.isr();}) ;
const uint16_t errorCode2 = CAN2.begin(settings, [] {CAN2.isr();}) ;
Hint : you can use the same settings variable, if both setting are the same.
Best regards,
Pierre
… Le 23 nov. 2020 à 17:10, ngochoangimsat ***@***.***> a écrit :
<https://user-images.githubusercontent.com/11856922/99985876-15b4e400-2de1-11eb-9048-8f7a057c3fdd.JPG>
<https://user-images.githubusercontent.com/11856922/99985884-18afd480-2de1-11eb-91c3-50dd817f6e22.JPG>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#23 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AEWKZVGX4ZLZ5P6QFPDHZX3SRKCRDANCNFSM4T7GVC4Q>.
|
Fine !
Now, you can try to increase the buffer sizes if you need so.
Note you can use the acan2515Tiny library, it requires less RAM and less Flash.
Best regards,
Pierre
… Le 23 nov. 2020 à 17:54, ngochoangimsat ***@***.***> a écrit :
Thank you very much sir! it work well now with your settings:
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#23 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AEWKZVHXJQHSUJH3ZC6QDATSRKHTFANCNFSM4T7GVC4Q>.
|
I tried to connect 2 MCP2515 to MCU via SPI but only first CAN can begin() successful, the second never run
.............
ACAN2515 CAN1(MCP2515_CS1, SPI, MCP2515_INT1);
ACAN2515 CAN2(MCP2515_CS2, SPI, MCP2515_INT2);
........
//This config will run CAN1 OK, CAN2 hang at begin()
const uint16_t errorCode1 = CAN1.begin (settings1, [] { CAN1.isr () ; }) ;
const uint16_t errorCode2 = CAN2.begin (settings2, [] { CAN2.isr () ; }) ;
//This config will run CAN2 OK, CAN1 hang at begin()
const uint16_t errorCode2 = CAN2.begin (settings2, [] { CAN2.isr () ; }) ;
const uint16_t errorCode1 = CAN1.begin (settings1, [] { CAN1.isr () ; }) ;
The text was updated successfully, but these errors were encountered: