NMEA 2000 Shield

Hi guys so I finally got a Mega 2560 and a MCP2515 & MCP2551 combo board. I cannot seem to get it to work with my Garmin GPSMAP742xs. I tried temperature monitor and looking in the NMEA2000 device list on GPSMAP unit. I also tried Actisense and don't pick up anything.

I have the libraries set up as per the instructions on Github. I do have both the MCP and Due libraries but I don't think that will make a difference. I then also add the line #define USE_MCP_CAN_CLOCK_SET 8 because my MCP board has a 8mhz crystal.

I am adding a rough connection diagram of how I got it wired.

Any help appreciated.

Mega2560 CAN.jpg

In the cockpit of my boat some analogue B&G displays are installed, but the analogue meters are all broken. I decided to digitize these meters with a tft screen.

I managed to write the program to translate the NMEA0183 messages coming from serial into screen pictures with needle and/or character presentation using a ESP32 (WROVER). I used the NMEA0183 library to parse the messages.

NMEA0183.Begin(&Serial2, 3, 115200);
Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);

tNMEA0183Msg NMEA0183Msg;
while (NMEA0183.GetMessage(NMEA0183Msg)) {......

Making all ship data available over WiFi was a previous project and is running some years now. For this project I would like to use the WiFi data in stead of Serial data. I wrote a separate program to recieve NMEA messages from WiFi using:

WiFiClient client;
if (client.available())
{
String line = client.readStringUntil('\r');
}

Now I have to combine these programs in order to use the WiFi Stream instead of the Serial Stream. I am using the Arduino IDE for programming so that should not be the biggest problem. But it appears different. The functions used in the NMEA0183 library are specifically writen for receiption through Serial Port.

Please help me by indicating which alterations/extensions should be made in the library or .....?

Thanks in advance

NMEA0183 can be opened either by hardware serial as in your code or just for stream NMEA0183.Begin(&);

JCW:
Hi guys so I finally got a Mega 2560 and a MCP2515 & MCP2551 combo board. I cannot seem to get it to work with my Garmin GPSMAP742xs. I tried temperature monitor and looking in the NMEA2000 device list on GPSMAP unit. I also tried Actisense and don't pick up anything.

I have the libraries set up as per the instructions on Github. I do have both the MCP and Due libraries but I don't think that will make a difference. I then also add the line #define USE_MCP_CAN_CLOCK_SET 8 because my MCP board has a 8mhz crystal.

I am adding a rough connection diagram of how I got it wired.

Any help appreciated.

Anyone have some advice for me? I used the MCP2515_Can library to determine that the device initializes correctly over the SPI bus.

There is not much to do. TemperatureMonitor example has been working with Mega. You could also wire int pin and add
#define N2k_CAN_INT_PIN xx
#define MCP_CAN_RX_BUFFER_SIZE 20
#define USE_MCP_CAN_CLOCK_SET 8
#include <NMEA2000_CAN.h>
...

But I am afraid that it does not help. You need to check wires, powering the bus, terminal resistor connection etc.

Loading different libraries does not make difference. #include <NMEA2000_CAN.h> selects necessary library according to selected processor. So you can have both NMEA2000_mch and _due loaded at same time.

I should move the Arduino connectiong to last and rise Teensy to the top - there is less trouble with it.

Thank you Timo, I appreciate the advice. I will try that, if that does not work I will try and find a scope and scope out the bus.

Regards,

Johan

Hi guys, I now have two Megas each with a MCP2515 set up. I am having success with the CAN_BUS_Shield-master library.

If I set #define USE_MCP_CAN_CLOCK_SET 8, I have the one Mega run the send example and I can then receive it with the other Mega using receive_check.

If I attach the correct interrupt then receive_interrupt also receives this data.

What would be the next logical step to move over to NMEA2000 to see where things go wrong? I am trying temperature monitor on the one and actisense listener on the other but still no luck. Obviously also setting #define USE_MCP_CAN_CLOCK_SET 8. I tried with interrupt on and off. Nothing.

Any help?

Did you use MCP_CAN library from my Git? If not, remove the other and install the one under my Git.

Do you have mcp CS (chip select) pin on NMEA2000 library default pin 53. If not use
#define N2k_SPI_CS_PIN cspin.

Remember to have termination resistors even it worked with your simple test.

Hi Timo,

Yes I followed your whole guide on Git to install the correct libraries. CS pin is correct. And I have both the termination resistors on the MCP modules on. Is it safe to say that since the MCP_CAN library works and I have comms between the two arduinos that the hardware is all good and that I should now look for my mistake in software?

Regards,

Johan

What examples you are using? USE_MCP_CAN_CLOCK_SET definition is on NMEA2000 library NMEA2000_CAN.h module and should not have any effect on CAN examples.

Which shields do you have?

Timo I use "Send" on the one Arduino Mega and "Receive_interupt" on the other. Both from the CAN_BUSMaster Libary as linked to in your github.

The data gets sent successfully from one to the other.

I am now trying to figure out what next to do to progress to the NMEA2000 library

On both samples there is definition const int SPI_CS_PIN = 9; Have you oveeride that? As I mentioned on NMEA2000 library default cs pin is 53. If your cs pin is 9, you have to add definition
#define N2k_SPI_CS_PIN 9
before calling NMEA2000_CAN.h
Also check right interupt pin, which is different on "Receive_interrupt"

Hi Timo,

I see what you mean the define for SPI speed makes no difference in the CAN bus examples. They work with or without this line

I have now again run NMEA2000 on the two Megas. One with temperature monitor example, correct interupt and cs pin defined and also SPI speed = 8.

On the other I have actisense listener also with parameter correctly configured.

I noticed that if I remove the arduino with actisense listener I get the following from the arduino running temp monitor:

CAN device ready
Start address claim for device 0
PGN 130312 send failed
PGN 130311 send failed
PGN 130310 send failed

If I connect the Mega with the actisense listener I get only

CAN device ready
Start address claim for device 0

This tells me that the messages do go pass through from one Mega to the other? I am not receiving anything at all out of the Mega running actisense though. Not even a init message.

Any more ideas?

If you get 'send failed' most likely you bus is not working. Either tranceiver is broken or misconnected, bus CAN L/H is misconnected or terminal resistor is missing.

Hi guys, this has by far been the most challenging arduino I ever had but I really want it to work.

I did more tests and had some progress. On all these test I made sure my bus resistance is 60ohms and I had messagesender on one board and actisense listener on the other board.

  1. I connected the two Megas to each other via the two MCP2515 boards. I noticed that when I load message sender on one and actisense listener on the other if work ONLY one way around. If I swop the two MCP2515 boards around if does NOT work anymore. When I swop back it works.

  2. While these two are in a working state (receiving messages on actisense listener) I then connect my Garmin 742xs (without termination resistor to the bus). The moment the Garmin device finishes booting the actisense listener no longer receives the messages from the other Mega. When I unplug the +12V from the garmin NMEA2000 connector it works again. So it looks like Garmin unit prevents the bus from working.

  3. I then take a Due wired in exactly the same config as on Timos Git except I use MCP2551 and a voltage divider on the RX to Mega for 3.3V comp. The moment I connect the Due CAN to the but it also stop working.

  4. I then put a termination resistor on the Garmin unit and connect it to each of the Megas individually after uploading message sender to both. Nothing in the device list. Upload temperature monitor to both and try again individually. Nothing.

I REALLY want to get this to work.

20200424_131135.jpg

20200424_131150.jpg

20200424_131304.jpg

20200424_140336.jpg

Update: The Due with MCP2551 works with the Garmin GPSMAP 742xs. I suspect that there is something wrong with these CAN modules. Or likely it is because they are running at 8MHz instead of 16MHz.

MCP2515 controller has been tested by some others with 8MHz and it should work.

In some pictures you had only modules with megas connected together. Did you had terminal resistor on that test? Modules has jumpers for enabling terminal resistor and at least on picture 20200424_131150 they were not enabled. In that case it may work or may not.

If you are sure and terminal resistors in case 1 then sounds like other module can not send anything. You could connect the module, which worked as actisense listener to bus with Garmin and Due. Then you should see data.

Hi Timo, sorry I did not mention the detail. Yes those had 120ohm resistors enabled by a solder short on the bottom of the board.

Ok I will try this test and see.

At least the Due now works with Garmin. :). Thx again for the library and all the help.

I can confirm the following:

  1. Due works with Garmin.
  2. Mega works with another Mega each with a 8MHz CAN module.
  3. Mega with module does NOT work with Garmin
  4. Mega with module does NOT work with Due.

I am convinced there is some compatibility issue with these modules. I read on the web that a lot of guys had problems with 8MHz crystals and some claim that changing to 16MHz solved the problem. I will try and find the posts.

For now I am happy. I can develop with the Due.

Are you sure you have definition right before including can library?

#define N2k_SPI_CS_PIN 53 // Pin for SPI Can Select
#define N2k_CAN_INT_PIN 21 // Use interrupt and it is connected to pin 21
#define USE_MCP_CAN_CLOCK_SET 8 // possible values 8 for 8Mhz and 16 for 16 Mhz clock
#include <NMEA2000_CAN.h>