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

CAN extended send,but not receiv #15

Closed
yuranikspb opened this issue Mar 26, 2020 · 24 comments
Closed

CAN extended send,but not receiv #15

yuranikspb opened this issue Mar 26, 2020 · 24 comments

Comments

@yuranikspb
Copy link

yuranikspb commented Mar 26, 2020

` CANMessage Message ;
Message.ext=true;

if (gBlinkLedDate < millis ()) {
gBlinkLedDate += 1000 ;
digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN)) ;
Message.id = 0x542;
const bool ok = can.tryToSend (Message) ;
if (ok) {
gSentFrameCount += 1 ;
Serial.print ("Sent: ") ;
Serial.println (gSentFrameCount) ;
}else{
Serial.println ("Send failure") ;
}
}
// if (can.available ()) {
Message.ext=true;
if (can.receive (Message)){
gReceivedFrameCount ++ ;
Serial.println ("Received: ") ;
Serial.print ("id: ");Serial.println (Message.id,HEX);
Serial.print ("ext: ");Serial.println (Message.ext);
Serial.print ("rtr: ");Serial.println (Message.rtr);
Serial.print ("len: ");Serial.println (Message.len);
Serial.print ("data: ");
for(int x=0;x<Message.len;x++)
{
Serial.print(Message.data[x],HEX);Serial.print(":");
}
Serial.println ("");
Serial.println (gReceivedFrameCount) ;
}
}`

standart frame work good (sending and receving)
29bit frame work sending but not receving
can.available method return false and can.receive method return false

@yuranikspb
Copy link
Author

i am test another library (autowp/arduino-canhacker)
and it work ok

@jaguar1975cn
Copy link

I have the same problem, I am using Pi Pico.

Extended message can be sent out, but cannot receive.

Have you found any workaround?

Thanks!

@pierremolinaro
Copy link
Owner

pierremolinaro commented Feb 2, 2022 via email

@jaguar1975cn
Copy link

jaguar1975cn commented Feb 2, 2022

Thanks Pierre, for your great library and your quick reply.

Regarding the issue, yes, I am sure I actually sent out the extended message. As I mentioned above, I am using acan2515 library on a Raspberry Pi Pico. To test it, I connected another Raspberry Pi 4B to the CAN bus via controller/tranceiver. When I am sending out the extended message from the Pico side, I can receive the message in the Pi 4B via candump command, e.g.:

$ candump can0
can0       10101010   [8]  11 22 33 44 55 66 77 88

Also, if I send standard message via cansend command from the Pi 4B, I can receive it on the Pico side, e.g.

cansend can0 371#1122334455667788

On the Pico side, I got:

Pico Received: 1 371 (len=8) [ 11 22 33 44 55 66 77 88 ]

But if I send extended message from cansend:

cansend can0 10101010#1122334455667788

The Pico can never receive it. (But the candump on the same Pi 4B actually received it)

Regarding the code, yes, I set Message.ext = true before calling can.tryToSend (Message) as you suggested.

@pierremolinaro
Copy link
Owner

pierremolinaro commented Feb 2, 2022 via email

@jaguar1975cn
Copy link

Thanks Pierre, tried the above sketch, got this:

Configure ACAN2515
Bit Rate prescaler: 4
Propagation Segment: 6
Phase segment 1: 6
Phase segment 2: 7
SJW: 4
Triple Sampling: yes
Actual bit rate: 125000 bit/s
Exact bit rate ? yes
Sample point: 60%
Sent: 1
Sent: 2
Sent: 3
Sent: 4
Sent: 5
Sent: 6
Sent: 7

If I modify the sketch to send the standard frames:

//    frame.ext = true ;
//    frame.id = 0x10101010 ;
    frame.id = 0x101 ;

Then I can receive the message as expected:

Configure ACAN2515
Bit Rate prescaler: 4
Propagation Segment: 6
Phase segment 1: 6
Phase segment 2: 7
SJW: 4
Triple Sampling: yes
Actual bit rate: 125000 bit/s
Exact bit rate ? yes
Sample point: 60%
Sent: 1
Sent: 2
  id: 101
  ext: 0
  rtr: 0
  len: 8
  data: 11:22:33:44:55:66:77:88:
Received: 1
  id: 101
  ext: 0
  rtr: 0
  len: 8
  data: 11:22:33:44:55:66:77:88:
Received: 2

Could it be related to the hardware itself? I am using MCP2515+TJA1050.

@pierremolinaro
Copy link
Owner

pierremolinaro commented Feb 3, 2022 via email

@jaguar1975cn
Copy link

jaguar1975cn commented Feb 3, 2022

Stupid question : do you use the last library release (2.0.9) ?

Yes, double checked. I am using 2.0.9.
image

Is it possible to change the MCP2515 ?

Yes, I tried three modules (but they came in the same batch). The result are same.

I am using this module: https://www.amazon.co.uk/ALAMSCN-MCP2515-Receiver-Compatible-Raspberry/dp/B091DXBT6F

Apart from the above module, I also test it on a production PCB. On the actual hardware, it also got the same result.

@pierremolinaro
Copy link
Owner

pierremolinaro commented Feb 3, 2022 via email

@jaguar1975cn
Copy link

jaguar1975cn commented Feb 3, 2022

Yes, I understand the module cannot be used directly with Pi Pico. I didn't mention but I have already modified the PCB manually a bit, to power the MCP2515 with 3.3V, and 5V to TJA1050.

There is no such problem either on the production PCB. Power are correctly supplied to both chips.

Also, with this kind of modification, the PI 4B can correctly send/receive extended frames. So, it looks like the hardware side has no problem.

@pierremolinaro
Copy link
Owner

pierremolinaro commented Feb 4, 2022 via email

@jaguar1975cn
Copy link

Yes, the above result I posted was from Pico with MCP2515 powered at 3.3V. The loopback result is not fully right, the extended frames cannot be received, but standard frames works perfectly fine.

Thanks again for your time. I understood it is hard, because on your side, you have no problem at all. I wonder what's different in your environment. I probably will do some further investigation on my side too.

@pierremolinaro
Copy link
Owner

pierremolinaro commented Feb 4, 2022 via email

@jaguar1975cn
Copy link

Hi, Pierre,

Just let you know, as yuranikspb mentioned in his second message. I also tried the arduino-mcp2515 lib (https://github.com/autowp/arduino-mcp2515). It worked fine with both standard and extended frames.

I will see if I can find out what's the difference between your implementation and arduino-mcp2515's.

Thanks again!

@pierremolinaro
Copy link
Owner

pierremolinaro commented Feb 7, 2022 via email

@pierremolinaro
Copy link
Owner

pierremolinaro commented Feb 9, 2022 via email

@jaguar1975cn
Copy link

Thanks Pierre, I will test it tomorrow.

@jaguar1975cn
Copy link

jaguar1975cn commented Feb 10, 2022

Hi, Pierre,

I spent a few hours testing your new function. Unfortunately, it didn't make any difference.

But, because I am cross testing both ACAN2515 lib and arduino-mcp2515 lib, I noticed an interesting thing during my test. It seems indicates it is some initialisation problem. Here is my found:

  1. If I power off the whole thing, use ACAN2515 lib directly, it won't work.
  2. If I switch to arduino-mcp2515 lib, power off the whole thing, it works perfectly fine
  3. I use arduino-mcp2515 lib first, then switch to ACAN2515 lib without powering off the CAN module. (Only upload the new uf2 to RP2040 without powering off, I have a push button to switch RP2040 to BOOTSEL mode). Then ACAN2515 lib also started to work: it can receive ext frames now.
  4. Once I power everything off, it will stop working again.

BTW, I am not testing the loopback mode, I am testing it against the Pi 4B module as I mentioned earlier.

Also, FYI, I used poll mode and interrupt mode with arduino-mcp2515 lib, all works fine.

Best regards,
James

@pierremolinaro
Copy link
Owner

pierremolinaro commented Feb 12, 2022 via email

@pierremolinaro
Copy link
Owner

pierremolinaro commented Feb 14, 2022 via email

@pierremolinaro
Copy link
Owner

pierremolinaro commented Feb 14, 2022 via email

@jaguar1975cn
Copy link

Hi, Pierre,

I have good news, you nailed it!

Both standard and extended frames works perfectly now. I only changed the above three lines based on 2.0.9.

diff --git a/src/ACAN2515.cpp b/src/ACAN2515.cpp
index aa5c7b6..022597a 100644
--- a/src/ACAN2515.cpp
+++ b/src/ACAN2515.cpp
@@ -365,8 +365,9 @@ uint16_t ACAN2515::internalBeginOperation (const ACAN2515Settings & inSettings,
   //----------------------------------- Set TXnRTS as inputs
     write2515Register (TXRTSCTRL_REGISTER, 0);
   //----------------------------------- RXBnCTRL
-    write2515Register (RXB0CTRL_REGISTER, ((uint8_t) inSettings.mRolloverEnable) << 2) ;
-    write2515Register (RXB1CTRL_REGISTER, 0x00) ;
+    const uint8_t acceptAll = (inAcceptanceFilterCount == 0) ? 0x60 : 0x00 ;
+    write2515Register (RXB0CTRL_REGISTER, acceptAll | (uint8_t (inSettings.mRolloverEnable) << 2)) ;
+    write2515Register (RXB1CTRL_REGISTER, acceptAll) ;
   //----------------------------------- Setup mask registers
     setupMaskRegister (inRXM0, RXM0SIDH_REGISTER) ;
     setupMaskRegister (inRXM1, RXM1SIDH_REGISTER) ;

Thank you very much for your time, really appreciated!

All the best,
James

@pierremolinaro
Copy link
Owner

pierremolinaro commented Feb 15, 2022 via email

@jaguar1975cn
Copy link

That's brilliant! All the best!

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

3 participants