ieb / nmea2000

Collection of Arduino and Linux code to integrate with a NMEA2000 Can bus.
7 stars 0 forks source link

MCP 2515 and Arduino DUE recieve #1

Open Gcaravell0 opened 3 years ago

Gcaravell0 commented 3 years ago

Hi to everybody and tanks a lot for this magnific library!! I'm replaicing my iTC-5 device with an arduino DUE. With this opportunity I also want to export some data to my PC via serial interface. I performed different communication tests with two arduino, as shown below. 44c8eaca-f85e-4d69-9a76-230e28c16ef5 03475308-813f-42e7-9209-deef62495067 a38dda21-54e1-48a6-bcb8-14d4c3be32c5 Observing the oscilloscope I'm able to see that there is a message in the bus. I am also sure that the transimitting node is working because when I disconnect one of the two bus I see a message sending error... However, trying to use the examples "Datadisplay 2" or "Actisense Listener" I cannot see any message on the listener node. :( I attached the following preamble to the code: _

#include <Arduino.h>
#define N2k_SPI_CS_PIN 53    // Pin for SPI select for mcp_can
#define N2k_CAN_INT_PIN 2   // Interrupt pin for mcp_can
#define USE_MCP_CAN_CLOCK_SET 8  // Uncomment this, if your mcp_can shield has 8MHz 
#define USE_N2K_CAN 1 // Force mcp_can
#include <NMEA2000_CAN.h>  // This will automatically choose right CAN library and create suitable NMEA2000 object
#include <SPI.h>
#include <mcp_can.h>
#include <NMEA2000_mcp.h>
#include <N2kMessagesEnumToStr.h>
#include <N2kMaretron.h>
#include <N2kMessages.h>
#include <math.h>   // these are necessary for my code
#include <DueTimer.h>

_ Someone could tell me what the mistake could be? Thank you in advance for your time and consideration

Giuseppe

ieb commented 3 years ago

I haven't tried using the Due over SPI talking to a MCP2515 with MCP2551 transceiver. The Due has 2 Can ports built in so you don't need to use a driver (MCP2515) only a transceiver. Also It only operates at 3.3v so you cant use the MCP2515 over SPI without a level shifter to convert Due logic at 3.3v to MCP2515 at 5v.

If you do want to use the Due can ports then you will need a Can transceiver that operates at 3.3v logic but can drive the Can bus at the correct levels. Most of the 3.3v Can transceiver use a charge pump and dont interface well to most NMEA2000 buses as the other drivers on the bus tend to be 5v devices and have a higher common mode voltage. Using a MCP2562 tranciever which is a 5v device on the CAN side, but a 3.3v device on the logic side does work well. That is the setup I use. A Due using its internal Can drivers and a MCP2562 trancerver.

That said, if I was doing this again, I would connect the Pi over SPI directly to a MCP2515/MCP2551 through a level shifter and use socketCan eliminating the Due completely. See https://dayba.wordpress.com/2017/05/25/connecting-socket-can-adapter-to-signalk/ https://www.skpang.co.uk/products/pican2-can-bus-board-for-raspberry-pi-2-3?_pos=9&_sid=583288f2c&_ss=r or you could use a cheap ebay MCP2515 driver with level shifter eg https://www.ebay.co.uk/itm/154316486567 + https://www.ebay.co.uk/itm/251742375561

If you want to replace an ITC-5, then the ESP32 modules also have 2x Can bus drivers, and are much more powerful than a Due. They will drive MCP2562 trancevers. Take a look at https://github.com/ttlappalainen/NMEA2000_esp32 for the original library and https://github.com/ieb/WindSensorBase or https://github.com/ieb/EngineMonitor for examples of code doing something similar. The only hard part of the ITC5 will be the depth sounder which is going to need some form of high voltage ultrasonic pulse driver. The rest is ADC+pulse measurements. You might also be interested in https://github.com/SignalK/SensESP which has some of the capabilities, but doesnt interface to a CAN Bus.