Loading...
Pages: [1]   Go Down
Author Topic: Problem with CAN bus shield  (Read 713 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everybody,

I have a problem with Arduino Uno R3 and the Sparkfun Canbus-Shield

https://www.sparkfun.com/products/10039

I am using the library

http://www.seeedstudio.com/wiki/images/0/0c/CAN_BUS_Shield_Code.zip

So far, I have successfully uploaded the following sketch, which does nothing but send the same message on the bus repeatedly:

Code:
#include "mcp_can.h"
#include <SPI.h>

void setup()
{
  Serial.begin(115200);
  if(CAN.begin(CAN_500KBPS) ==CAN_OK) Serial.print("can init ok!!\r\n");
  else Serial.print("Can init fail!!\r\n");
}

unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};
void loop()
{
  if(CAN.sendMsgBuf(0x00, 0, 8, stmp)==CAN_OK)
  {
    Serial.println("OK.");
    Serial.println(CAN.sendMsgBuf(0x00, 0, 8, stmp));
  }
  else
  {
    Serial.println("ERROR.");
    Serial.println(CAN.sendMsgBuf(0x00, 0, 8, stmp));
  }
  delay(1000);
}

Uploading works without problems, but the serial output looks like this:

Quote
Enter setting mode success
set rate success!!
Enter Normal Mode Success!!
can init ok!!
OK.
0
OK.
6
ERROR.
6
ERROR.
6
ERROR.
6
ERROR.
6
ERROR.
6
ERROR.
6
ERROR.
6
ERROR.
6
...

So after the message is sent two times, the buffer is full and no more messages can be sent - at least that is my guess.

Does anybody have experience with the CAN bus shield and can tell me what the problem is? I also tried other libraries, but this problem always remained the same.

Thank you so much,

papillon
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 316
Posts: 35566
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So after the message is sent two times, the buffer is full and no more messages can be sent - at least that is my guess.
Perhaps if you told us what the messages are going to, you wouldn't have to guess.

If your guess is correct, then it implies that the other device is failing to remove the message from the queue. So, you need to have a stern talking to with it.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, problem solved: My device (PCAN-USB CAN analyzer) had a different D-9 pin layout, so the CAN Hi and CAN lo pins from the shield went nowhere...

In case anybody has similar problems:

Shield Pin 3 (CAN Low) <--> PCAN Pin 2 (CAN Low)
Shield Pin 5 (CAN High)<--> PCAN Pin 7 (CAN High)

Thanks anyway!!!
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 316
Posts: 35566
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Thanks anyway!!!
You're welcome. I like problems like this, where you are going to go do all the work.
Logged

Pages: [1]   Go Up
Print
 
Jump to: