-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Node with MCP2515 disappears when another devices begins transmitting #5
Comments
But what happens on main loop. According you brakepoints no-one puts data to Tx buffer and thats why they have not been fired anymore. This happens if main loop stops. |
There may be problem with buffers. MessageSender does not set any receive buffer size, which causes it to use for mcp_can default buffer size 2. Now in interrupt routine there seem to be small feature that if buffer is full, interrupt flag will not be cleared and so it start to loop. To fix interrupt routine, add: Then it should work. Anyway for any real device you need some receive buffer. You can define that in setup with: |
Thx for this advice. I tried out, but the symptoms stay the same.
As soon as second device (e.g. WindMonitor example, which I consider being a low bus load) is attached, controller gets loaded by the interrupt routine, which is re-entered immediately. Now I forcefully cleared CANINTF.MCP_RX0IF | CANINTF.MCP_RX1IF flags in MCP2515 inside the frame skip routine:
This makes the controller no more locked by the interupt routine. I think, I will ditch the experiment with MCP2515. Might not be worth the effort with digging through layers of unknown code, when an easy solution is to simply use different (and equally cheap) hardware. Thx for your support and for your great work on the NMEA2000 libraries! |
Hi Sending: Receiving: I have tried the setup wing the MCP_shields "receive_check" and "send" sketches,with success. Data was seen being sent over the CAN bus so I know the hardware is OK and wired correctly. I have bubble and triple check termination and wiring. I have a 120 ohm terminator/resistor at each en of the bus. Between CAN_H ans CAN_L I measures 60 ohm so termination should not be an issue. I have up to date library's from downloaded from https://github.com/ttlappalainen I have only added the flowing lines as documented (of cause the pin is adjusted for the different boards) in the library. Now hear is the kicker I have had this working intermittently with NMEA2000 messages but for the past 3 moths I have not bean able to get a single NMEA2000 message thou. Regular CAN works fine. Any help or advice would be greatly appreciated. |
Do you have those defines before #include <NMEA2000_CAN.h>? Have you added NMEA2000.SetN2kCANReceiveFrameBufSize(70); before NMEA2000.Open();? Try to leave interrupt pin undefined to work without interrupt. So comment #define N2k_CAN_INT_PIN 16 |
Thanks ttlappalainen for the quick reply. Yes, the defines are before #include <NMEA2000_CAN.h> However, I took a trip down to the boat today and just for kicks and giggles I connected my ESPs expecting no positive out come. What I connected to my Seatalk NG network: Wemos lolin32 with MCP2515 8MHz crystal and tja1050 can transceiver. Running MessageSender example sketch. Wemos lolin32 with MCP2515 8MHz crystal and tja1050 can transceiver. Running DataDisplay2 example sketch. My Raymarine MDF and ST60 instruments all picked up the data being send from the WindMonitor and MessageSender example sketches. But DataDisplay2 example sketch picked up nothing. Nuthing from WindMonitor, MessageSender or any of the Raymarine equipment transmitting on the network. So, it is definitely something on the receiving side. I'm going back to the boat tomorrow to see if the the WindMonitor and MessageSender sketches stop working when adding NMEA2000.SetMode(tNMEA2000::N2km_ListenAndNode,); I have also tryed adding NMEA2000.SetMode(tNMEA2000::N2km_ListenOnly,32); before NMEA2000.Open(); on the DataDisplay2 example sketch, this made no difference. I'm defensibly running low on ides. |
Why do you use MCP2515 with Wemos lolin32? It is based on ESP32-WROOM and has internal CAN controller. Then you just need MCP2562 or ISO1050 for isolated systems. Have you tried to enable bus data printing on WindMonitor with I do not use mcp anymore in my devices. The ones I used has 16MHz chrystal and never had any problems with them. People have lots of problems with these 8MHz chrystals - do not know why, since it shoud not make any difference. |
I'm using the MCP2515 with the lolin32 as that just happened to be what i had. Yes, I have tried to enable bus data printing on WindMonitor. It prints out the PNG nicely. This weekend I tried merging NMEA2000ToWiFiAsSeaSmart and WindMonitor, so that NMEA2000ToWiFiAsSeaSmart not just listened but also sent something to the CAN bus. The MFD picked up the wind data being sent, but NMEA2000ToWiFiAsSeaSmart received nothing from the network (on the network there is tempter sensor, depth sensor, AIS, speed sensor, and more). This proves at least that the TX part of MCP2515 is working as expected. I've been scratching my head all day and trying to understand the layers. To me it seems that NMEA2000_MCP.h is a driver that calls functions in the class of MCP_CAN library. Witch makes my very novis brane wonder why the added layer of NMEA2000_MCP.h? I've been reading the data sheet for the MCP2515. If I have understood the information correctly the crystal is only used as a synchronization clock on incoming messages. If that is the case can there be something wrong in the driver MCP_CAN.h NMEA2000_MCP.h or the crystal it self. Then as the MCP_CAN library's examples receiving works nicely, that would indicate that the crystal is working to. I'v tryed to use MCP_CAN.h from Seeed-Studio with the same result. But the MCP_CAN.h from ttlappalainen must work with 8MHz crystals @ 250 KB/s as I can receive when using the example sketches from that library. I'm so puzzled!!! Is it worth to try with 16 MHz crystal. From what I have managed to read the crystal should be tuned to the desired baud rate. I have not been able to find any recommended frequency for MCP2515 using 250 KB/s that NMEA 2000 uses. |
Does WindMonitor print also received data or only sent data? Alo take care that you do not have any other mcp_can library installed at same time. Only the one from my git. As I said I do not use mcp_can anymore and have never tested it with ESP32, since it has its own internal CAN. I prefer to use ESP32 internal CAN ot Teensies. |
WindMonitor only prints data like below: So it dose not look like it receives ether. |
I hooked up my MCP2515+MCP2551 to ESP32. I feed it with 5V and added voltage divider to MISO line. I did not add interrupt line, since it was messy enough. So I have |
Hi Timo So ether the tja1050 is not compatible with the NMEA protocol or I have counterfeit chips on my MCP2515. Once again a massive thank you for you time and leased an excellent library. |
You can not use MCP2551, since it is 5V device and ESP:s can only handle 3.3V. Voltage deviders for inputs is just fors testing not for permanent solution. You can use MSC2562, which has one pin for io level definition. |
Hi But it only worked with After a lot of digging on the github issues pages I found the magic line hiding in a dark corner, to get ListenAndNode to work with my cheap china MCP2515 module. After adding this section to the top of my code, it all works nicely. Thanks Timo for an excellent peace library. |
I prefer to also use interrupt, which will automatically fill rx buffer, even you would have some delay on polling. |
I have a strange problem with a NMEA2000 device built with STM32F103 "blue pill" and MCP2515 board:
The device disappears from the bus when another device sends for the first time.
The device does not re-appear (start sending) when other devices disconnect or stop sending.
Code is taken from the example "MessageSender".
A dump of the NMEA2000 data looks as follows:
candump can0 | candump2analyzer | analyzer -raw
Now another device is switched on (here an ESP32 with WindMonitor example, but Garmin GPSmap behaves similar):
Transmission of the MCP2515 MultiSender device is now stopped and device is not visible to others on the bus.
Debugging the STM32 shows that the device is still live under this condition:
I have set 3 breakpoints in tNMEA2000_mcp::InterruptHandler()
if ( (frame=pRxBuffer->GetWriteFrame())!=0 ) {
if ( (status=N2kCAN.checkClearTxStatus(&tempRxTxStatus,N2kCAN.getLastTxBuffer()))!=0 ) {
while ( (status=N2kCAN.checkClearTxStatus(&tempRxTxStatus))!=0 && ...
As soon as another device is active on the bus, only breakpoint 1 kicks in.
Code in Breakpoints 2 and 3 are not reached any more, and no sending takes place.
I also tried with
NMEA2000.EnableForward(false);
, to make sure it is not a problem with blocking output of forwared data, but no change (also USB disabled).MCP2515 and STM32F103 is an awkward combo, but I had no other STM32 laying around which is capable of both CAN and USB.
It would be great if somebody had some hints or fixes to my problem...
The text was updated successfully, but these errors were encountered: