Skip to content
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

Open
ngochoangimsat opened this issue Nov 23, 2020 · 6 comments
Open

Problem with dual canbus #23

ngochoangimsat opened this issue Nov 23, 2020 · 6 comments

Comments

@ngochoangimsat
Copy link

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 () ; }) ;

@pierremolinaro
Copy link
Owner

pierremolinaro commented Nov 23, 2020 via email

@ngochoangimsat
Copy link
Author

ngochoangimsat commented Nov 23, 2020

Bellow is the sketch, i used arduino nano
I am sure that i connected everything correctly in schematic. If i comment to CAN1 then CAN2 is "Configuration CAN2 OK!" but if i uncomment CAN.begin(..) then only "Configuration CAN1 OK!"

`#include <ACAN2515.h>
static const byte MCP2515_CS1 = 10 ; // CS input of MCP2515 CAN1
static const byte MCP2515_INT1 = 2 ; // INT output of MCP2515 CAN1
ACAN2515 CAN1(MCP2515_CS1, SPI, MCP2515_INT1);

static const byte MCP2515_CS2 = A3 ; // CS input of MCP2515 CAN2
static const byte MCP2515_INT2 = 3 ; // INT output of MCP2515 CAN2
ACAN2515 CAN2(MCP2515_CS2, SPI, MCP2515_INT2);

static const uint32_t QUARTZ_FREQUENCY = 16UL * 1000UL * 1000UL; // 16 MHz

void setup() {
Serial.begin (9600);
while (!Serial) {
delay (50) ;
}
SPI.begin();
ACAN2515Settings settings1 (QUARTZ_FREQUENCY, 500UL * 1000UL);
settings1.mRequestedMode = ACAN2515Settings::NormalMode;
const uint16_t errorCode1 = CAN1.begin (settings1, [] { CAN1.isr () ; }) ;
if (errorCode1 != 0) {
Serial.print ("Configuration CAN1 error 0x") ;
Serial.println (errorCode1, HEX) ;
} else {
Serial.println ("Configuration CAN1 OK!") ;
}

ACAN2515Settings settings2(QUARTZ_FREQUENCY, 500UL * 1000UL);
settings2.mRequestedMode = ACAN2515Settings::NormalMode;
const uint16_t errorCode2 = CAN2.begin (settings2, [] { CAN2.isr () ; }) ;
if (errorCode2 != 0) {
Serial.print ("Configuration CAN2 error 0x") ;
Serial.println (errorCode2, HEX) ;
} else {
Serial.println ("Configuration CAN2 OK!") ;
}

}

void loop() {

}`

@ngochoangimsat
Copy link
Author

1
2

@pierremolinaro
Copy link
Owner

pierremolinaro commented Nov 23, 2020 via email

@ngochoangimsat
Copy link
Author

ngochoangimsat commented Nov 23, 2020

Thank you very much sir! it work now with your settings:
3

@pierremolinaro
Copy link
Owner

pierremolinaro commented Nov 23, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants