• AVR Freaks

Hot!Re-initialization of CAN module during operation

Starting Member
  • Total Posts : 39
  • Reward points : 0
  • Joined: 2010/10/14 07:42:12
  • Location: 0
  • Status: offline
2019/06/19 01:22:27 (permalink)

Re-initialization of CAN module during operation

Hi all,

I'm working with PIC32MX and Microchip's CAN library. Almost everything works like expected, except re-initializing the CAN module during operation.
Given the following scenario:
1) CAN module setup with code shown below (CAN32OP_InitHardwareModule) --> normal operation, working.
2) Then re-initializing the module (again CAN32OP_InitHardwareModule) with e.g different can bus speed --> changes will not take place, still on old/initial can bus frequency.

That's how it appears to be with all changes made during re-initializing of the module. It seams only after power down, the module can be initialized properly with my setup. Is there anything I need to change to re-initialize the CAN module. I tried nearly everything, setting it to different CAN_OP_MODE or disabling it before re-init, none worked.

Any help would be highly appreciated!

Init function used to init as well as re-init the module:
 * Initializes the hardware CAN module.
 * @param CAN32OP_Module: Pointer to the CAN32OP_MODULE to
 * work with
 * @param SystemFreq: The system clock frequency
 * @param PhaseSeg1Tq: Phase Segment 1 (CAN_BIT_TQ)
 * @param PhaseSeg2Tq: Phase Segment 2 (CAN_BIT_TQ)
 * @param PropagationSegTq: Propagation Delay (CAN_BIT_TQ)
 * @param SyncJumpWidth: Syncro Jump Width (CAN_BIT_TQ)
static void CAN32OP_InitHardwareModule(CAN32OP_MODULE* CAN32OP_Module, UINT32 SystemFreq,
                                       CAN_BIT_TQ PhaseSeg1Tq, CAN_BIT_TQ PhaseSeg2Tq, CAN_BIT_TQ PropagationSegTq,
                                       CAN_BIT_TQ SyncJumpWidth)
    CAN_BIT_CONFIG canBitConfig;
    UINT32 i = 0;

    //Step 1: Switch the CAN module
    //ON and switch it to Configuration
    //mode. Wait till the mode switch is
    CANEnableModule(CAN32OP_Module->Module, TRUE);
    CANSetOperatingMode(CAN32OP_Module->Module, CAN_CONFIGURATION);
    while (CANGetOperatingMode(CAN32OP_Module->Module) != CAN_CONFIGURATION);

    //Step 2: Configure the Clock.The
    //CAN_BIT_CONFIG data structure is used
    //for this purpose. The propagation segment,
    //phase segment 1 and phase segment 2
    //are configured to have 3TQ. SYSTEM_FREQ
    //and CAN_BUS_SPEED are defined
    canBitConfig.phaseSeg1Tq = PhaseSeg1Tq;
    canBitConfig.phaseSeg2Tq = PhaseSeg2Tq;
    canBitConfig.propagationSegTq = PropagationSegTq;
    canBitConfig.phaseSeg2TimeSelect = TRUE;
    canBitConfig.sample3Time = TRUE;
    canBitConfig.syncJumpWidth = SyncJumpWidth;
    CANSetSpeed(CAN32OP_Module->Module, &canBitConfig, SystemFreq, CAN32OP_Module->CanBusSpeed);

    //Step 3: Assign the buffer area to the
    //CAN module.
    CANAssignMemoryBuffer(CAN32OP_Module->Module, CAN32OP_Module->FifoArea, CAN32OP_FIFO_SIZE);

    //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(CAN32OP_Module->Module, CAN32OP_Module->TxChannel,
                             CAN32OP_Module->TxQueueCap, CAN_TX_RTR_DISABLED, CAN_LOW_MEDIUM_PRIORITY);
    CANConfigureChannelForRx(CAN32OP_Module->Module, CAN32OP_Module->RxChannel,
                             CAN32OP_Module->RxQueueCap, CAN_RX_FULL_RECEIVE);

    //Step 5: Configure filters and mask. Configure
    //filter 0 to accept EID messages.
    //Configure filter mask 0 to compare all the ID
    //bits and to filter by the ID type specified in
    //the filter configuration. Messages accepted by
    //filter 0 should be stored in channel RX.
    CANConfigureFilter(CAN32OP_Module->Module, CAN_FILTER0, CAN32OP_Module->ID, CAN_EID);
    CANConfigureFilterMask(CAN32OP_Module->Module, CAN_FILTER_MASK0,
                           0x1FFE0, CAN_EID, CAN_FILTER_MASK_IDE_TYPE);
    CANLinkFilterToChannel(CAN32OP_Module->Module, CAN_FILTER0,
                           CAN_FILTER_MASK0, CAN32OP_Module->RxChannel);
    CANEnableFilter(CAN32OP_Module->Module, CAN_FILTER0, TRUE);

    //Configure the broadcast ID
    CANConfigureFilter(CAN32OP_Module->Module, CAN_FILTER1, CAN32OP_Module->ID, CAN_EID);
    CANConfigureFilterMask(CAN32OP_Module->Module, CAN_FILTER_MASK1,
                           0x1F000, CAN_EID, CAN_FILTER_MASK_IDE_TYPE);
    CANLinkFilterToChannel(CAN32OP_Module->Module, CAN_FILTER1,
                           CAN_FILTER_MASK1, CAN32OP_Module->RxChannel);
    CANEnableFilter(CAN32OP_Module->Module, CAN_FILTER1, TRUE);

    //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(CAN32OP_Module->Module, CAN32OP_Module->RxChannel,
                          CAN_RX_CHANNEL_NOT_EMPTY, TRUE);
    CANEnableModuleEvent(CAN32OP_Module->Module, CAN_RX_EVENT, TRUE);

    CANEnableChannelEvent(CAN32OP_Module->Module, CAN32OP_Module->TxChannel,
                          CAN_TX_CHANNEL_EMPTY, TRUE);
    CANEnableModuleEvent(CAN32OP_Module->Module, CAN_TX_EVENT, TRUE);

    //These functions are from interrupt peripheral
    if (CAN32OP_Module->Module == CAN1)
        INTSetVectorPriority(INT_CAN_1_VECTOR, INT_PRIORITY_LEVEL_4);
        INTSetVectorSubPriority(INT_CAN_1_VECTOR, INT_SUB_PRIORITY_LEVEL_0);
        INTEnable(INT_CAN1, INT_ENABLED);
        INTSetVectorPriority(INT_CAN_2_VECTOR, INT_PRIORITY_LEVEL_4);
        INTSetVectorSubPriority(INT_CAN_2_VECTOR, INT_SUB_PRIORITY_LEVEL_0);
        INTEnable(INT_CAN2, INT_ENABLED);

    //Step 7: Switch the CAN mode
    //to normal mode.


2 Replies Related Threads

    Super Member
    • Total Posts : 1696
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: online
    Re: Re-initialization of CAN module during operation 2019/06/19 03:06:14 (permalink)
    +1 (1)
    Start by looking at the power up state of the CAN registers and compare to their state between steps 1 and 2.
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2010/10/14 07:42:12
    • Location: 0
    • Status: offline
    Re: Re-initialization of CAN module during operation 2019/06/20 01:35:47 (permalink)
    Hi -
    Okay, I can do so. I was hoping someone has experience on this and can give a hint. Nevertheless, looking into the registers more in detail can always be helpful.
    post edited by Oliver - 2019/06/20 02:24:36
    Jump to:
    © 2019 APG vNext Commercial Version 4.5