pierremolinaro / acan2515

MCP2515 CAN Controller Driver for Arduino
MIT License
74 stars 29 forks source link

Acan2515 bitrate problem #41

Closed Algosistaken closed 1 year ago

Algosistaken commented 1 year ago

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.

pierremolinaro commented 1 year ago

Hello,

Strange, can you post the code ?

Le 15 mars 2023 à 15:59, Algosistaken @.***> a écrit :

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.

— Reply to this email directly, view it on GitHub https://github.com/pierremolinaro/acan2515/issues/41, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEWKZVBGCDJABXQT5MFLC7DW4HKNXANCNFSM6AAAAAAV36QNSY. You are receiving this because you are subscribed to this thread.

Algosistaken commented 1 year ago

`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 commented 1 year ago

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 commented 1 year ago

Ok, what is your microcontroller and how do you define the QUARTZ_FREQUENCY constant ?

Le 17 mars 2023 à 21:20, Algosistaken @.***> a écrit :

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 oscillator. 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.

— Reply to this email directly, view it on GitHub https://github.com/pierremolinaro/acan2515/issues/41#issuecomment-1474365827, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEWKZVBYRWTRMF3GKARHVTDW4TBPXANCNFSM6AAAAAAV36QNSY. You are receiving this because you commented.

Algosistaken commented 1 year ago

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 commented 1 year ago

Ok, the QUARTZ_FREQUENCY definition is ok.

The MCP2515 is powered under 3.3V ?

Le 17 mars 2023 à 22:18, Algosistaken @.***> a écrit :

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.

— Reply to this email directly, view it on GitHub https://github.com/pierremolinaro/acan2515/issues/41#issuecomment-1474411905, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEWKZVEETGTYDUOQGCQQAL3W4TIK3ANCNFSM6AAAAAAV36QNSY. You are receiving this because you commented.

pierremolinaro commented 1 year ago

And what is the result of the print instructions ?

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 ("%") ;

Le 17 mars 2023 à 22:18, Algosistaken @.***> a écrit :

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.

— Reply to this email directly, view it on GitHub https://github.com/pierremolinaro/acan2515/issues/41#issuecomment-1474411905, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEWKZVEETGTYDUOQGCQQAL3W4TIK3ANCNFSM6AAAAAAV36QNSY. You are receiving this because you commented.

Algosistaken commented 1 year ago

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 commented 1 year ago

Ok for 3.3V power supply.

The bit settings are ok :

actual_bit_rate (PS + PS1 + PS2 + 1) bit_rate_prescaler * 2 = quartz_frequency

125 000 (5 + 5 + 5 + 1) 4 * 2 = 16 000 000

62.5kbps is just the half of 125kbps.

I think it is an hardware problem. Are you sure that the quartz frequency is 16 MHz ? Can you check the frquency at pin #8 of the MCP2515 ?

Le 21 mars 2023 à 07:27, Algosistaken @.***> a écrit :

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

— Reply to this email directly, view it on GitHub https://github.com/pierremolinaro/acan2515/issues/41#issuecomment-1477340717, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEWKZVAEXKQPYOPLGT6I3PTW5FC4NANCNFSM6AAAAAAV36QNSY. You are receiving this because you commented.

Algosistaken commented 1 year ago

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 commented 1 year ago

Ok, but I have no Arduino Due, I am sorry, but I can't help you.

Le 26 mars 2023 à 10:10, Algosistaken @.***> a écrit :

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.

— Reply to this email directly, view it on GitHub https://github.com/pierremolinaro/acan2515/issues/41#issuecomment-1484027074, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEWKZVBIFKC4JWO44SZOU2TW572YJANCNFSM6AAAAAAV36QNSY. You are receiving this because you commented.

Algosistaken commented 1 year ago

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