I can get the CAN shield to work on my UNO no problem but i can't get it to work on my Mega 2560. Physically i've wired the SPI lines to the CAN-Bus shield at the same pin locations as the UNO, but i can't find where to change the SPI pins in software? I've tried SPI.h and it's labeled fine on pins_arduino.h but i don't think it's looking at the correct pins_arduin.h.
Does anyone know how to get the CAN-BUS shield code to look at the correct SPI pins? I'm using the seed studio CAN-Bus Shield and code.
i've wired the SPI lines to the CAN-Bus shield at the same pin locations as the UNO, but i can't find where to change the SPI pins in software?
That's because you can't. They are wired in the hardware. You need to modify the shield, if it doesn't use SPI via the ICSP connector, like the Ethernet shield does.
Well here's the thing, it does work when wired like this. I simply clipped the header pins at location 10,11,12,13 and wired in 50,51,52, and 53 from the MEGA. Using modified code from the sparkfun can-shield the board works just fine like this. I can read and transmit CAN from the MEGA. The problem is i need 29bit CAN which the sparkfun code does not have provisions for, it only does 11bit.
That brings me to the original seed studio code which does support 29bit CAN. It works great on my UNO, but i need the extra serial ports on the MEGA for other stuff. I know this wiring works because it works with different code. I just can't see how to get the seed studio code to use the other pins for SPI. I tried following the code through SPI.H and i see where it references MISO, MOSI, SCK, and SS in the pins_arduino.h file. I see after i compile that it infact looks into the \variants\mega folder for this file. So everything should be right, i just don't understand why it's not working. Yet, the arduino UNO works fine?
OK, finally figured it out after following the code line by line. It was in the mcp_can_dfs.h file and wasn't readily apparent because of the way it was worded\coded.
As you can see above, the SPICS is worded funny, i would have made the variable SPI_CS to make it clear. A little underscore goes a long way. As you can see in the code, i changed the CS pin to 53 here.
It was in the mcp_can_dfs.h file and wasn't readily apparent because of the way it was worded\coded.
The compiler can figure out whether you are compiling for a Mega, or not, and should use the correct #define. It is simply laziness on the part of the library developer to require you to edit source files to use a different board.