Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

TMS320F28075: CAN acceptance filtering - Setup sometimes not successful

$
0
0

Part Number:TMS320F28075

Hi all

Currently I have a problem setting up the CAN acceptance filtering. Under certain conditions (it seems, when setting the CAN registers  and there is traffic on the bus at the same time), I still receive unwanted messages. Note: most of the times the acceptance filtering works, only sometimes it doesn't.

I found in the reference manual (SPRUHM9B), section 21.14, the note, that one should take care of ongoing bus traffic while setting the CAN registers by resetting the MsgVal bit to 0. I did not consider this before and so I added the MsgVal reset. Unfortunately the behaviour didn't change.

My code before the MsgVal reset looked like this:

#define HWREGH(x)	(*((volatile UInt16 *)(x)))
#define HWREG(x)	(*((volatile UInt32 *)(x)))

void CanDriver::setupReceiveMailbox(const MailboxDefinition& mbxDef) const
{
	// Message parameters
	UInt32 messageBoxIndex;		//!< Message Object ID (number)
	UInt32 ui32MsgID;		//!< The CAN message identifier used for 11 or 29 bit identifiers.
	UInt32 ui32MsgIDMask;		//!< The message identifier mask used when identifier filtering is enabled.
	// register buffers
	UInt32 ui32CmdMaskReg;
	UInt32 ui32MaskReg;
	UInt32 ui32ArbReg;
	UInt32 ui32MsgCtrl;

	messageBoxIndex = mbxDef.m_iMailboxNr;		//!< Message Object ID (number)
	ui32MsgID = mbxDef.m_canIdentifier;		//!< The CAN message identifier used for 11 or 29 bit identifiers.
	ui32MsgIDMask = 0x7FF &~ mbxDef.m_canMask;	//!< The message identifier mask used when identifier filtering is enabled.

	ui32CmdMaskReg = (CAN_IF1CMD_DIR | 			// Write message box object
			  CAN_IF1CMD_DATA_A | CAN_IF1CMD_DATA_B |	// Set CAN Data
			  CAN_IF1CMD_MASK |				// Set ID Mask
			  CAN_IF1CMD_ARB |				// Set arbitraton value
			  CAN_IF1CMD_CONTROL				// Set Control
					  );

	// Configure the Mask Registers.
	// Put the 11 bit Mask Identifier into the upper bits of the field
	// in the register.
	ui32MaskReg = ((ui32MsgIDMask << CAN_IF1ARB_STD_ID_S) & CAN_IF1ARB_STD_ID_M);

	// Set the UMASK bit to enable using the mask register.
	ui32MsgCtrl = CAN_IF1MCTL_UMASK;

	// Configure the Arbitration registers.
	// Set the 11 bit version of the Identifier for this message object.
	// The lower 18 bits are set to zero.
	// Mark the message box as valid.
	ui32ArbReg = ((ui32MsgID << CAN_IF1ARB_STD_ID_S) & CAN_IF1ARB_STD_ID_M) | CAN_IF1ARB_MSGVAL;

	if (!mbxDef.m_bOverwriteProtection) {
		// Mark this as the last entry if this is not the last entry in a FIFO.
		ui32MsgCtrl |= CAN_IF1MCTL_EOB;
	}
	
	DINT;
	// Wait for busy bit to clear
	while(HWREGH(CAN_BASE + CAN_O_IF1CMD) & CAN_IF1CMD_BUSY)
	{
	}
	// Enable receive interrupts
	ui32MsgCtrl |= CAN_IF1MCTL_RXIE;

	// Write out the registers to program the message object.
	HWREGH(CAN_BASE + CAN_O_IF1CMD + 2) = ui32CmdMaskReg >> 16;

	HWREGH(CAN_BASE + CAN_O_IF1MSK) 	= ui32MaskReg & 0xFFFF;
	HWREGH(CAN_BASE + CAN_O_IF1MSK + 2) = ui32MaskReg >> 16;

	HWREGH(CAN_BASE + CAN_O_IF1ARB) 	= ui32ArbReg & 0xFFFF;
	HWREGH(CAN_BASE + CAN_O_IF1ARB + 2) = ui32ArbReg >> 16;

	HWREGH(CAN_BASE + CAN_O_IF1MCTL) 	= ui32MsgCtrl & 0xFFFF;

	// Transfer the message object to the message object specific by ui32ObjID.
	HWREGH(CAN_BASE + CAN_O_IF1CMD) 	= messageBoxIndex & CAN_IF1CMD_MSG_NUM_M;
	EINT;
}

With the reset of MsgVal it looks like:

#define HWREGH(x)	(*((volatile UInt16 *)(x)))
#define HWREG(x)	(*((volatile UInt32 *)(x)))

void CanDriver::setupReceiveMailbox(const MailboxDefinition& mbxDef) const
{
	// Message parameters
	UInt32 messageBoxIndex;		//!< Message Object ID (number)
	UInt32 ui32MsgID;		//!< The CAN message identifier used for 11 or 29 bit identifiers.
	UInt32 ui32MsgIDMask;		//!< The message identifier mask used when identifier filtering is enabled.
	// register buffers
	UInt32 ui32CmdMaskReg;
	UInt32 ui32MaskReg;
	UInt32 ui32ArbReg;
	UInt32 ui32MsgCtrl;

	messageBoxIndex = mbxDef.m_iMailboxNr;		//!< Message Object ID (number)
	ui32MsgID = mbxDef.m_canIdentifier;		//!< The CAN message identifier used for 11 or 29 bit identifiers.
	ui32MsgIDMask = 0x7FF &~ mbxDef.m_canMask;	//!< The message identifier mask used when identifier filtering is enabled.

	ui32CmdMaskReg = (CAN_IF1CMD_DIR | 			// Write message box object
			  CAN_IF1CMD_DATA_A | CAN_IF1CMD_DATA_B |	// Set CAN Data
			  CAN_IF1CMD_MASK |				// Set ID Mask
			  CAN_IF1CMD_ARB |				// Set arbitraton value
			  CAN_IF1CMD_CONTROL				// Set Control
					  );

	// Configure the Mask Registers.
	// Put the 11 bit Mask Identifier into the upper bits of the field
	// in the register.
	ui32MaskReg = ((ui32MsgIDMask << CAN_IF1ARB_STD_ID_S) & CAN_IF1ARB_STD_ID_M);

	// Set the UMASK bit to enable using the mask register.
	ui32MsgCtrl = CAN_IF1MCTL_UMASK;

	// Configure the Arbitration registers.
	// Set the 11 bit version of the Identifier for this message object.
	// The lower 18 bits are set to zero.
	// Mark the message box as valid.
	ui32ArbReg = ((ui32MsgID << CAN_IF1ARB_STD_ID_S) & CAN_IF1ARB_STD_ID_M) | CAN_IF1ARB_MSGVAL;

	if (!mbxDef.m_bOverwriteProtection) {
		// Mark this as the last entry if this is not the last entry in a FIFO.
		ui32MsgCtrl |= CAN_IF1MCTL_EOB;
	}
	
	DINT;
	// Wait for busy bit to clear
	while(HWREGH(CAN_BASE + CAN_O_IF1CMD) & CAN_IF1CMD_BUSY)
	{
	}

	// Clear MsgVal bit to avoid bus traffic to interfere with write access
	HWREGH(CAN_BASE + CAN_O_IF1CMD + 2) = (CAN_IF1CMD_DIR | CAN_IF1CMD_ARB) >> 16;

	HWREGH(CAN_BASE + CAN_O_IF1ARB) 	= 0;
	HWREGH(CAN_BASE + CAN_O_IF1ARB + 2) = 0;

	// Transfer the message object to the message object specific by ui32ObjID.
	HWREGH(CAN_BASE + CAN_O_IF1CMD) 	= (messageBoxIndex & CAN_IF1CMD_MSG_NUM_M);
	// Wait for busy bit to clear
	while(HWREGH(CAN_BASE + CAN_O_IF1CMD) & CAN_IF1CMD_BUSY)
	{
	}

	// Enable receive interrupts
	ui32MsgCtrl |= CAN_IF1MCTL_RXIE;

	// Write out the registers to program the message object.
	HWREGH(CAN_BASE + CAN_O_IF1CMD + 2) = ui32CmdMaskReg >> 16;

	HWREGH(CAN_BASE + CAN_O_IF1MSK) 	= ui32MaskReg & 0xFFFF;
	HWREGH(CAN_BASE + CAN_O_IF1MSK + 2) = ui32MaskReg >> 16;

	HWREGH(CAN_BASE + CAN_O_IF1ARB) 	= ui32ArbReg & 0xFFFF;
	HWREGH(CAN_BASE + CAN_O_IF1ARB + 2) = ui32ArbReg >> 16;

	HWREGH(CAN_BASE + CAN_O_IF1MCTL) 	= ui32MsgCtrl & 0xFFFF;

	// Transfer the message object to the message object specific by ui32ObjID.
	HWREGH(CAN_BASE + CAN_O_IF1CMD) 	= messageBoxIndex & CAN_IF1CMD_MSG_NUM_M;
	EINT;
}

As I said, it didn't change the behaviour and acceptance filltering is still not working all the time.
Any ideas? Did I miss something? Consider there might be bus traffic while calling the setupReceiveMailbox method...

Cheers benjo


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>