-
Notifications
You must be signed in to change notification settings - Fork 17
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
Does the library support 2x 2518FD chips on same board? #53
Comments
Some update on this, I got the boards to initialize properly, but after running for a few seconds I get send_ok going bad, and buffer overflows. |
If you do this with an ESP32, pay attention to the selection of the INT pins. Two edge-triggered pins in the same group can cause problems here (in your example 34 and 35). I tested it with ESP32 and two MCP2518. |
Hi,
You can use two ACAN2517FDSettings objects :
//--- First one
ACAN2517FDSettings settings0 (ACAN2517FDSettings::OSC_4MHz10xPLL, 1000 * 1000, DataBitRateFactor::x8) ;
settings0.mRequestedMode = ACAN2517FDSettings::InternalLoopBack ; // Select loopback mode
uint32_t errorCode[2]={0};
errorCode[0] = can[0]->begin (settings0, [] { can[0]->isr () ; }) ;
...
//--- Second one
ACAN2517FDSettings settings1 (ACAN2517FDSettings::OSC_4MHz10xPLL, 1000 * 1000, DataBitRateFactor::x8) ;
settings1.mRequestedMode = ACAN2517FDSettings::InternalLoopBack ; // Select loopback mode
uint32_t errorCode[2]={0};
errorCode[1] = can[1]->begin (settings1, [] { can[1]->isr () ; }) ;
settings0 and settings1 can have different settings.
Pierre
… Le 23 janv. 2025 à 19:54, tomtom0707 ***@***.***> a écrit :
Hi, I would be interested in the topic just as much.
See the test program below, which is running. Is this the right way to use the library for 2 x MCP2518FD?
What I have to do to give the 2nd controller different settings? I'm not a master of programming...
Note, I left out the speed limit ;)
`//------------------------------------------------------------------------------
// ACAN2517FD Driver object
//------------------------------------------------------------------------------
SPIClass vspi (VSPI) ; // See ESP32 demo sketch: SPI_Multiple_Busses
ACAN2517FD can0 (MCP2517_CS0, vspi, MCP2517_INT0) ;
ACAN2517FD can1 (MCP2517_CS1, vspi, MCP2517_INT1) ;
ACAN2517FD *can[2];
CANFDMessage frame ;
uint8_t i;
//------------------------------------------------------------------------------
// SETUP
//------------------------------------------------------------------------------
void setup () {
//--- Start serial
Serial.begin (115200) ;
while (!Serial) {
delay (50) ;
}
can[0] = &can0;
can[1] = &can1;
//----------------------------------- Begin SPI
vspi.begin (MCP2517_SCK, MCP2517_MISO, MCP2517_MOSI) ;
//---------------------- CAN0 ----------------------------------------------------
Serial.print("sizeof (ACAN2517FDSettings): "); Serial.print(sizeof (ACAN2517FDSettings));
Serial.println(" bytes"); Serial.println("Configure CAN0:");
ACAN2517FDSettings settings (ACAN2517FDSettings::OSC_4MHz10xPLL, 1000 * 1000, DataBitRateFactor::x8) ;
settings.mRequestedMode = ACAN2517FDSettings::InternalLoopBack ; // Select loopback mode
uint32_t errorCode[2]={0};
errorCode[0] = can[0]->begin (settings, [] { can[0]->isr () ; }) ;
if (errorCode[0] == 0) {
Serial.print ("Bit Rate prescaler: ") ;
Serial.println (settings.mBitRatePrescaler) ;
Serial.print ("Arbitration Phase segment 1: ") ;
Serial.println (settings.mArbitrationPhaseSegment1) ;
Serial.print ("Arbitration Phase segment 2: ") ;
Serial.println (settings.mArbitrationPhaseSegment2) ;
Serial.print ("Arbitration SJW:") ;
Serial.println (settings.mArbitrationSJW) ;
Serial.print ("Actual Arbitration Bit Rate: ") ;
Serial.print (settings.actualArbitrationBitRate ()) ;
Serial.println (" bit/s") ;
Serial.print ("Exact Arbitration Bit Rate ? ") ;
Serial.println (settings.exactArbitrationBitRate () ? "yes" : "no") ;
Serial.print ("Arbitration Sample point: ") ;
Serial.print (settings.arbitrationSamplePointFromBitStart ()) ;
Serial.println ("%") ;
}else{
Serial.print ("ConfigCAN0 error 0x") ;
Serial.println (errorCode[0], HEX) ;
}
// ---------------------- CAN1 ----------------------------------------------------
//Config CAN1 - settings ???
errorCode[1] = can[1]->begin (settings, [] { can[1]->isr () ; }) ;
if (errorCode[1] == 0) {
Serial.print ("Bit Rate prescaler: ") ;
Serial.println (settings.mBitRatePrescaler) ;
Serial.print ("Arbitration Phase segment 1: ") ;
Serial.println (settings.mArbitrationPhaseSegment1) ;
Serial.print ("Arbitration Phase segment 2: ") ;
Serial.println (settings.mArbitrationPhaseSegment2) ;
Serial.print ("Arbitration SJW:") ;
Serial.println (settings.mArbitrationSJW) ;
Serial.print ("Actual Arbitration Bit Rate: ") ;
Serial.print (settings.actualArbitrationBitRate ()) ;
Serial.println (" bit/s") ;
Serial.print ("Exact Arbitration Bit Rate ? ") ;
Serial.println (settings.exactArbitrationBitRate () ? "yes" : "no") ;
Serial.print ("Arbitration Sample point: ") ;
Serial.print (settings.arbitrationSamplePointFromBitStart ()) ;
Serial.println ("%") ;
}else{
Serial.print ("ConfigCAN1 error 0x") ;
Serial.println (errorCode[1], HEX) ;
}
Serial.println ("los gehts...");
}
//------------------------------------------------------------------------------
// LOOP
//------------------------------------------------------------------------------
static uint32_t gReceivedFrameCount[2] = {0};
static uint32_t gSentFrameCount[2] = {0};
static const uint32_t MESSAGE_COUNT = 10000 ;
uint8_t stopp[2] = {0};
//------------------------------------------------------------------------------
void loop () {
for(i=0;i<2;i++)
{
if (gSentFrameCount[i] < MESSAGE_COUNT)
{
const bool ok = can[i]->tryToSend (frame) ;
if (ok) {
gSentFrameCount[i]++;
}
}
else
{
if(stopp[i] == 0){
stopp[i] = 1;
Serial.print ("CAN"); Serial.print (i);
Serial.print (" Sent: ") ;
Serial.print (gSentFrameCount[i]) ;
Serial.print ("; Received: ") ;
Serial.println (gReceivedFrameCount[i]) ;
}
}
}
for(i=0;i<2;i++)
{
if (can[i]->available())
{
CANFDMessage frame ;
can[i]->receive(frame) ;
gReceivedFrameCount[i] ++ ;
}
}
}
`
—
Reply to this email directly, view it on GitHub <#53 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AEWKZVCOVFGNJJTSQO7OJUT2ME3FHAVCNFSM6AAAAABSVP5YDCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMJQG43TCMZXGE>.
You are receiving this because you are subscribed to this thread.
|
Working with some custom PCBs that have 2x MCP2518 chips on the same SPI
Has anyone been able to use this library with two chips at the same time? One of the chips start, but the second fails to start with errorCode 1
The text was updated successfully, but these errors were encountered: