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

Acan2515 bitrate problem #41

Closed
Algosistaken opened this issue Mar 15, 2023 · 12 comments
Closed

Acan2515 bitrate problem #41

Algosistaken opened this issue Mar 15, 2023 · 12 comments

Comments

@Algosistaken
Copy link

Hello.
I am working on mcp2515 with this library. But when i try to send can massage at 16mhz quartz frequency it reduces the bitrate with half of i try to send. If i sen at 1 mbps it sends messages at 500kbps. Also with 10 MHz quartz frequency i saw that when i try to send message with 1 MHz it sends it with 800kbps. While 8 MHz frequency is running, I can send my messages with exactly the bitrate I want. What I want is to reach 1 mbps speed. 8 mhz frequency doesn't support it either. I couldn't solve this problem, can you help me? Sorry for my bad english.

@Algosistaken Algosistaken changed the title Acan2515 bitrqte problem Acan2515 bitrate problem Mar 15, 2023
@pierremolinaro
Copy link
Owner

pierremolinaro commented Mar 17, 2023 via email

@Algosistaken
Copy link
Author

Algosistaken commented Mar 17, 2023

`void setup () {
//--- Switch on builtin led
pinMode (LED_BUILTIN, OUTPUT) ;
digitalWrite (LED_BUILTIN, HIGH) ;
//--- Start serial
Serial.begin (9600) ;
//--- Wait for serial (blink led at 10 Hz during waiting)
while (!Serial) {
delay (50) ;
digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN)) ;
}
//--- Begin SPI
SPI.begin () ;
//--- Configure ACAN2515
Serial.println ("Configure ACAN2515") ;
ACAN2515Settings settings (QUARTZ_FREQUENCY, 125UL * 1000UL) ; // CAN bit rate 125 kb/s
const uint16_t errorCode = can.begin (settings, [] { can.isr () ; }) ;
if (errorCode == 0) {
Serial.print ("Bit Rate prescaler: ") ;
Serial.println (settings.mBitRatePrescaler) ;
Serial.print ("Propagation Segment: ") ;
Serial.println (settings.mPropagationSegment) ;
Serial.print ("Phase segment 1: ") ;
Serial.println (settings.mPhaseSegment1) ;
Serial.print ("Phase segment 2: ") ;
Serial.println (settings.mPhaseSegment2) ;
Serial.print ("SJW: ") ;
Serial.println (settings.mSJW) ;
Serial.print ("Triple Sampling: ") ;
Serial.println (settings.mTripleSampling ? "yes" : "no") ;
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 error 0x") ;
Serial.println (errorCode, HEX) ;
}
}

void loop () {
CANMessage frame ;
frame.id = 0x123;
frame.len = 8;
frame.data[0] = 0;
frame.data[1] = 1;
frame.data[2] = 2;
frame.data[3] = 3;
if (gBlinkLedDate < millis ()) {
gBlinkLedDate += 2000 ;
digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN)) ;
const bool ok = can.tryToSend (frame) ;
if (ok) {
gSentFrameCount += 1 ;
Serial.print ("Sent: ") ;
Serial.println (gSentFrameCount) ;
}else{
Serial.println ("Send failure") ;
}
}`

@Algosistaken
Copy link
Author

Algosistaken commented Mar 17, 2023

Sorry for miss click on close button. I use your example loopback code and changed it with normal mode and i tried to send some frames. But when i try to use this code i get 62.5 kBps bitrate in oscilloscope. Also i can read the frames with Kvaser in 62.5 kBps only. I am using arduino due. May be it can be because of Due.

@pierremolinaro
Copy link
Owner

pierremolinaro commented Mar 17, 2023 via email

@Algosistaken
Copy link
Author

I am using Arduino Due and it has Atmel SAM3X8E ARM Cortex-M3 on it. I defined exactly same in the loopback example.

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

I tried different frequencies and got different bitrates.

@pierremolinaro
Copy link
Owner

pierremolinaro commented Mar 17, 2023 via email

@pierremolinaro
Copy link
Owner

pierremolinaro commented Mar 18, 2023 via email

@Algosistaken
Copy link
Author

Yes I use 3.3V.
Print results are:

Bit Rate prescaler: 4
Propagation Segment: 5
Phase Segment 1: 5
Phase Segment 2: 5
SJW:4
Triple Sampling: yes
Actual Bit Rate: 125000
Exact bit rate ? yes
Sample point: 62%

This results are for 125kbps but my measurements are 62.5kbps

@pierremolinaro
Copy link
Owner

pierremolinaro commented Mar 22, 2023 via email

@Algosistaken
Copy link
Author

I don't think it is a hardware problem. I have 2 MCP2515 modules, and both of them are the same. I tried using another library with Arduino Due, but it didn't work. However, when I used an Arduino Mega, it worked. Therefore, I think the issue may be related to the Arduino Due.

@pierremolinaro
Copy link
Owner

pierremolinaro commented Mar 27, 2023 via email

@Algosistaken
Copy link
Author

Ok, thanks anyway. If I find anything i will post here.

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