CAN bus intermitent operation

Discussion to talk about software related topics only.
Post Reply
User avatar
mx270a
Posts: 80
Joined: Tue Jan 19, 2010 6:55 pm

CAN bus intermitent operation

Post by mx270a »

I have two NANO54415s on a dev carrier boards connected together via CAN. One has an app generating messages, the other receiving those messages. My issue is that the one generating message usually works fine if I upload firmware to it, but not if I do a cold boot or press the reset button.

Code: Select all

#include "predef.h"
#include <stdio.h>
#include <ctype.h>
#include <startnet.h>
#include <autoupdate.h>
#include <dhcpclient.h>
#include <netinterface.h>
#include <ucos.h>
#include <string.h>
#include <serial.h>
#include <taskmon.h>
#include <multican.h>
#include <pins.h>

extern "C" {
void UserMain( void *pd );
}

const char *AppName = "CAN Generator (Dev Board)";
#define CAN_MODULE (1)

void UserMain(void *pd) {
	InitializeStack();
	OSChangePrio( MAIN_PRIO );
	EnableAutoUpdate();
	EnableTaskMonitor();

	Pins[20].function(PIN_20_CAN1_RX );
	Pins[22].function(PIN_22_CAN1_TX );

	if (MultiCanInit(CAN_MODULE, 250000, 0, 4) == CAN_OK) {
		while (1) { // Infinite loop to listen for and send CAN messages
			OSTimeDly(2);
			char buffer[8];
			siprintf(buffer, "%i", Secs);

			int status = MultiCanSendMessage(CAN_MODULE, NormToNbId(106), (PBYTE)buffer, strlen(buffer), 50);
			iprintf("_%i", status);
		}
	} else {
		iprintf( "CAN init failed\r\n" );
	}
}
If I send this code to it, it reboots and starts sending messages 90% of the time. However, if I then pull power and reconnect it, or press the reset button, it will usually boot up and report a -5, which means CAN Timeout. If I press the reset button a few more times, eventually I will get it to send data.

I did come across this thread, which appears to be similar.
http://forum.embeddedethernet.com/viewt ... f=5&t=1167
That mentions reading the CAN registers, but the example is for flexcan, and I think the multican is some newer version for the 54415. I don't see anything about reading registers in the multican.h file.

Thanks,
Lance
User avatar
mx270a
Posts: 80
Joined: Tue Jan 19, 2010 6:55 pm

Re: CAN bus intermitent operation

Post by mx270a »

I've been able to confirm that I see the same behavior when use the Can2Serial example code. I have been reading the FlexCAN registers and found that when the issue occurs, I see the "BIT0ERR" bit set in the Error and Status register (sim2.can[1].errstat). The MCF manual offers these details:
Bit0 error. Indicates inconsistency between the transmitted and received bit in a message.
0 No transmit bit error
1 At least one bit sent as dominant was received as recessive
Progress continues...
User avatar
mx270a
Posts: 80
Joined: Tue Jan 19, 2010 6:55 pm

Re: CAN bus intermitent operation

Post by mx270a »

This appears to be a hardware issue with the dev carrier board. I could reproduce the issue without anything connected to the board, so I switched to a different carrier board and it all works fine. The board I was having trouble with is a v1.1 and the board that works is v1.3. Weird issue.
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: CAN bus intermitent operation

Post by rnixon »

Thanks for posting the follow up. One item with CAN though - its my understanding that you need at least 2 devices connected, otherwise the CAN h/w will generate an error. If that's true, a board should never work by itself. Has that been your experience?
User avatar
mx270a
Posts: 80
Joined: Tue Jan 19, 2010 6:55 pm

Re: CAN bus intermitent operation

Post by mx270a »

That's correct, you need two boards for communication. Any device sending a message on a CAN bus has a spot at the end of the message for remote nodes to acknowledge that the message was received. If the sender doesn't see the message ACK'd, it knows that the message wasn't received by anyone.

In my case, I was able to test this issue without any other boards connected because they are different errors. The lack of an acknowledgement on a message flags a different error than the BIT 0 error. I could upload firmware the module with this dev board and see ACK errors, reset it, and then I would see the BIT 0 errors. They both appear as a timeout, so I had to look at the registers to see what specific errors were being flagged.
Post Reply