TWAI custom speed calculation
Posted: Fri Jul 19, 2024 10:06 pm
by JurajK123
Hello,
I tried to understand documentation for TWAI custom speeds but I still don't get it. I am trying to migrate the project from MCP2515 to native TWAI.
My problem is creating definition for custom speed 83K3 CAN speed. I cannot understand how to calculate values (brp , tseg1 , tseg2 and sjw) for the speed.
Can somebody help me?
Thank you
Re: TWAI custom speed calculation
Posted: Thu Jul 25, 2024 5:51 am
by EarlVadim
I'm using the library ACAN_ESP32
v.1.1.2
there is automatic setting of parameters
Code: Select all
ACAN_ESP32_Settings settings (83333);
settings.mRequestedCANMode = ACAN_ESP32_Settings::NormalMode ;
const uint32_t errorCode = ACAN_ESP32::can.begin (settings) ;
if (errorCode == 0) {
Serial.println ("Configuration ESP32 83333 OK!");
Serial.print ("Bit Rate prescaler: ") ;
Serial.println (settings.mBitRatePrescaler) ;
Serial.print ("Phase segment 1: ") ;
Serial.println (settings.mTimeSegment1) ;
Serial.print ("Phase segment 2: ") ;
Serial.println (settings.mTimeSegment2) ;
Serial.print ("SJW:") ;
Serial.println (settings.mRJW) ;
Serial.print ("Actual bit rate: ") ;
Serial.print (settings.actualBitRate ()) ;
Serial.println (" bit/s") ;
Serial.print ("Exact bit rate ? ") ;
Serial.println (settings.exactBitRate () ? "yes" : "no") ;
Serial.print ("Sample point: ") ;
Serial.print (settings.samplePointFromBitStart ()) ;
Serial.println ("%") ;
}else{
Serial.print ("Configuration 83333 error 0x") ;
Serial.println (errorCode, HEX) ;
}
LOG
Code: Select all
11:20:50.403 -> Configuration ESP32 83333 OK!
11:20:50.403 -> Bit Rate prescaler: 20
11:20:50.403 -> Phase segment 1: 16
11:20:50.403 -> Phase segment 2: 7
11:20:50.403 -> SJW:4
11:20:50.403 -> Actual bit rate: 83333 bit/s