-------------------- Tech Support Tips/Troubleshooting/Common Issues --------------------
CAN-Bus Shield w/ an Arduino Mega 2560
Software Defined SPI pins
Using the example code , you will probably see this output on the Arduino serial monitor
If you see this output on the Arduino serial monitor when using the CAN-Bus shield on an Arduino Mega 2560 [uploaded with the SparkFun_CAN_Demo.ino - https://github.com/sparkfun/CAN-Bus_Shield/blob/master/Libraries/Arduino/examples/SparkFun_CAN_Demo/SparkFun_CAN_Demo.ino ]:
CAN-Bus Demo
Can’t init CAN
Please choose a menu option.
1.Speed
2.RPM
3.Throttle
4.Coolant Temperature
5.O2 Voltage
6.MAF Sensor
You need to modify the defined SPI pins in the default file located in the "CAN-Bus_Shield" library [ https://github.com/sparkfun/CAN-Bus_Shield/blob/master/Libraries/Arduino/src/defaults.h ] as explained by Memphomaniac the SparkFun forum [ https://forum.sparkfun.com/viewtopic.php?f=14&t=25535&start=30c ]. Just change lines 4-12 from:
#define P_MOSI B,3
#define P_MISO B,4
#define P_SCK B,5
//#define MCP2515_CS D,3 // Rev A
#define MCP2515_CS B,2 // Rev B
#define MCP2515_INT D,2
#define LED2_HIGH B,0
#define LED2_LOW B,0
to
// Arduino Uno (Atmega 168/328 pin mapping)
//#define P_MOSI B,3 // pin 11
//#define P_MISO B,4 // pin 12
//#define P_SCK B,5 // pin 13
//#define MCP2515_CS B,2 // pin 10
//#define MCP2515_INT D,2 // pin 2
//#define LED2_HIGH B,0 // pin 8
//#define LED2_LOW B,0 // pin 8
// Pins remapped to Arduino Mega 2560
#define P_MOSI B,2 // pin 51
#define P_MISO B,3 // pin 50
#define P_SCK B,1 // pin 52
#define MCP2515_CS B,0 // pin 53
#define MCP2515_INT E,4 // pin 2
#define LED2_HIGH H,5 // pin 8
#define LED2_LOW H,5 // pin 8
Hardware Connections
After redefining pins, make sure that you bend the header pins of the shield so that it is not in the Arduino Mega2560’s sockets (pins 10-13). Then, make sure to reroute the pins to the correct SPI pins:
SPI Pins <=> Arduino Uno <=> Arduino Mega 2560
SCK <=> 13 <=> 52
MISO <=> 12 <=> 50
MOSI <=> 11 <=> 51
SS <=> 10 <=> 53
Try looking at this tutorial [ http://mcukits.com/2009/04/06/arduino-ethernet-shield-mega-hack/ ] as an example. With the correct pins defined and rerouted, I was able to receive this correct output:
CAN-Bus Demo
CAN Init ok
Please choose a menu option.
1.Speed
2.RPM
3.Throttle
4.Coolant Temperature
5.O2 Voltage
6.MAF Sensor
If you are seeing this serial output on the monitor:
CAN-Bus Demo
it's possible that the software pins are not defined correctly, there is a loose connection, or you are not connecting the wires properly. Make sure the pins are defined properly and check your connections.
Bit Rate?
I have not tried changing the bit rate but try looking at this article on step 2 to determine the bit segment => [ http://www.analog.com/en/analog-dialogue/articles/configure-can-bit-timing.html ]. The article seems to indicate that you would need to adjust the crystal oscillator and the Baud Rate Prescaler (BRP) bits.
Baud Rate?
If you are trying to add additional baud rates for the CAN BUS, I recommend looking at the library here [ https://github.com/sparkfun/SparkFun_CAN-Bus_Arduino_Library/blob/ffcd67b7f4d5112f747f7c74a8677ef82a4ee202/src/Canbus.h#L10 ] to add additional baud rates. I’m not sure of the exact details of how to do this since I have not tried calculating a value outside of the example code. You would probably need to define your baud rate constant by determining your baud rate prescaler. Try looking at the MCP2515’s datasheet for more information [pg 38 - https://www.sparkfun.com/datasheets/DevTools/Arduino/MCP2515.pdf ]. I did a quick search online and this tutorial might be of some use [ http://www.normalexception.net/index.php/code-development/arduino-mcp2515-library ] .
Examples
For more examples, maybe you can look at the MCP_CAN library [ https://github.com/coryjfowler/MCP_CAN_lib ] by coryjfowler . It looks like the Arduino library is compatible with any shield or board that uses a MCP2515 CAN.
This tutorial on Instructables is useful for reading any device outputting serial data on the CAN bus line => [ http://www.instructables.com/id/CAN-Bus-Sniffing-and-Broadcasting-with-Arduino/?ALLSTEPS] .
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4