Network Shield - CAN Bus - can't RX, but TX works

Post Reply
ddfndr
Posts: 2
Joined: Fri Dec 12, 2014 2:11 pm

Network Shield - CAN Bus - can't RX, but TX works

Post by ddfndr » Wed Dec 17, 2014 6:51 pm

Hi,

I am using the Chipkit Network Shield and the CAN Bus for my project. Currently I am having some issues to receive messages. Transmitting messages works. The transmitted messages appear on my PC.

My current Setup looks like this:
- Chipkit Network Shield connect to a CAN interface
- The CAN interface is logging received messages and generating messages for transmission

This is my initialization function of CAN1. I used the example code and modified it.

Code: Select all

void init_can1()
{
    CAN_BIT_CONFIG canBitConfig;

	/* Step 1: Switch the CAN module
	 * ON and switch it to Configuration
	 * mode. Wait till the switch is
	 * complete */

	CANEnableModule(CAN1,TRUE);

	CANSetOperatingMode(CAN1, CAN_CONFIGURATION);
	while(CANGetOperatingMode(CAN1) != CAN_CONFIGURATION);

	/* Step 2: Configure the CAN Module Clock. The
	 * CAN_BIT_CONFIG data structure is used
	 * for this purpose. The propagation,
	 * phase segment 1 and phase segment 2
	 * are configured to have 3TQ. The CANSetSpeed()
     * function sets the baud. */

	canBitConfig.phaseSeg2Tq            = CAN_BIT_3TQ;
	canBitConfig.phaseSeg1Tq            = CAN_BIT_3TQ;
	canBitConfig.propagationSegTq       = CAN_BIT_3TQ;
	canBitConfig.phaseSeg2TimeSelect    = TRUE;
	canBitConfig.sample3Time            = TRUE;
    canBitConfig.syncJumpWidth          = CAN_BIT_2TQ;

   CANSetSpeed(CAN1,&canBitConfig,SYS_FREQ,CAN_BUS_SPEED);

	/* Step 3: Assign the buffer area to the
     * CAN module.
     */
/* Note the size of each Channel area.
 * It is 2 (Channels) * 8 (Messages Buffers)
 * 16 (bytes/per message buffer) bytes. Each
 * CAN module should have its own message
 * area. */
	CANAssignMemoryBuffer(CAN1,CAN1MessageFifoArea,2 * 8 * 16);

	/* Step 4: Configure channel 0 for TX and size of
     * 8 message buffers with RTR disabled and low medium
     * priority. Configure channel 1 for RX and size
     * of 8 message buffers and receive the full message.
     */
CANConfigureChannelForTx(CAN1,CAN_CHANNEL0,8,CAN_TX_RTR_DISABLED,CAN_LOW_MEDIUM_PRIORITY);
    CANConfigureChannelForRx(CAN1,CAN_CHANNEL1,8,CAN_RX_FULL_RECEIVE);

	/* Step 5: Configure filters and mask.  */
    CANEnableFilter         (CAN1, CAN_FILTER0, FALSE);

	/* Step 6: Enable interrupt and events. Enable the receive
     * channel not empty event (channel event) and the receive
     * channel event (module event).
     * The interrrupt peripheral library is used to enable
     * the CAN interrupt to the CPU. */
    CANEnableChannelEvent(CAN1, CAN_CHANNEL1, CAN_RX_CHANNEL_NOT_EMPTY, TRUE);
    CANEnableModuleEvent(CAN1, CAN_RX_EVENT, TRUE);
		CANEnableChannelEvent(CAN1, CAN_CHANNEL1, CAN_INVALID_RX_MESSAGE_EVENT, TRUE);
		CANEnableChannelEvent(CAN1, CAN_CHANNEL1, CAN_RX_CHANNEL_ANY_EVENT, TRUE);

    /* These functions are from interrupt peripheral
     * library. */
    INTSetVectorPriority(INT_CAN_1_VECTOR, INT_PRIORITY_LEVEL_4);
    INTSetVectorSubPriority(INT_CAN_1_VECTOR, INT_SUB_PRIORITY_LEVEL_0);
    INTEnable(INT_CAN1, INT_ENABLED);

	/* Step 7: Switch the CAN mode
	 * to normal mode. */
	CANSetOperatingMode(CAN1, CAN_NORMAL_OPERATION);
	while(CANGetOperatingMode(CAN1) != CAN_NORMAL_OPERATION);

}
The problem is:
- TX works (at PC)
- RX works (at PC)
- TX works (at ChipKit)
- RX don't (at ChipKit)

The interrupt is not triggerd. I've tried to register for CAN_RX_CHANNEL_ANY_EVENT, but still nothing happens. Maybe the configuration of the interrupt ist done incorrect. Any problem regarding the bus speed can be excluded, because the transmission of a CAN message from the Network Shield to the PC works fine.

Do you have any idea what I am doing wrong?

Thanks
Dietrich

User avatar
Jacob Christ
Posts: 723
Joined: Sat May 28, 2011 6:34 am
Location: Southern California
Contact:

Re: Network Shield - CAN Bus - can't RX, but TX works

Post by Jacob Christ » Sun Jan 04, 2015 5:23 pm

Did you figure this out? We at PONTECH are about to embark on CAN with chipKIT and its murky water for us. I found some posts from people earlier that were having success.

Jacob
PONTECH Quick240 an industrial form factor platform for chipKIT and Arduino users.

ddfndr
Posts: 2
Joined: Fri Dec 12, 2014 2:11 pm

Re: Network Shield - CAN Bus - can't RX, but TX works

Post by ddfndr » Wed Jan 07, 2015 1:56 pm

Hi Jacob,

My configuration of the filter was wrong.To receive every message, I set it up like this:

Code: Select all

CANConfigureFilter (CAN1, CAN_FILTER0, 0x1, CAN_SID);
CANConfigureFilterMask (CAN1, CAN_FILTER_MASK0, 0x0, CAN_SID, CAN_FILTER_MASK_IDE_TYPE);
CANLinkFilterToChannel (CAN1, CAN_FILTER0, CAN_FILTER_MASK0, CAN_CHANNEL1);
CANEnableFilter (CAN1, CAN_FILTER0, TRUE);
Now I am receiving correctly.
Hope this helps.

Post Reply