Microchip
直播中

王学超

7年用户 207经验值
私信 关注
[问答]

CANBUS掩码/过滤器无法正常工作

我用和声来配置可以收听所有消息。我知道我的设备有3个不同的消息地址;但是,我无法检索任何更高的寻址消息。从CANBUS分析器,我收到以下地址:DATA0x0CEEFD2:3200 000 000 000 000 0x10FFAAD2:184300 10Ccc9009000X10FFA9D2:000 0301AA0B00 00这是很漂亮的T。典型的,现在和谐。我一直在听所有的信息,因为我不知道为什么我看到一个问题。和声结构如下。没关系,我不能附加一个屏幕截图,但是基本上MAX和过滤器是0x0,我在听所有的东西。在上面的例子中,我只看到来自0x0CEFED2的消息,我认为这是因为它是最低的地址。如果我将过滤器改为0x10FFAAD2和我的掩码到0x1FFFFFF,我想我会看到来自频道1的设备0x10FFAAD2的消息。我看到的不是消息。事实上,如果我将过滤器设置为BEXX100000,并且掩码为0x100000,我仍然看不到更高的地址消息,即使我通过分析器看到总线上的数据。我的中断例程如下:在上面的代码中,UsARTARI命令只是我用来通过USAT获取数据的实用工具。正如你所看到的,我基本上进入了数据结构,因为我无法弄清楚为什么我没有通过抽象函数看到数据。我对CANBUS屏蔽/过滤器设置有什么基本的缺陷吗?(我使用PIC32 MZ)任何指导都将不胜感激。

以上来自于百度翻译


      以下为原文

    I am using HARMony to configure CAN to listen to all messages.  I know that my device has 3 different message addresses; however, I've been unable to retrieve any of the higher addressed messages.

From the CANBUS analyzer, I receive the following:
ADDRESS  :  DATA
0x0CEEFFD2 : 3200000000000000
0x10FFAAD2 : 18430010CC090000
0x10FFA9D2 : 000301AA0B000000
These are pretty typical, and now to Harmony.  I've been listening to all messages because I have no idea of why I am seeing an issue.  The Harmony configuration is as follows.  


In the case above, I see only the message from 0x0CEEFFD2, and I assume that's because it's the lowest address.  If I change my filter to: 0x10FFAAD2 and my mask to 0x1FFFFFFF, I thought that I would see the message from device 0x10FFAAD2 on channel 1.  What I see is no messages.  In fact, if I set the filter to be 0x10000000, and the mask to be 0x1000000, I still see none of the higher address messages, even though I see the data on the bus via the analyzer.  My interrupt routine is as follows.

void __ISR(_CAN1_VECTOR, IPL3AUTO) _IntHandlerDrvCANInstance0(void) {
    char stringa[64];
    CAN_RX_MSG_BUFFER *RxMessage;
    unsigned int tempAddress = 0;
    unsigned int r_event = PLIB_CAN_ModuleEventGet(CAN_ID_1);

    switch (r_event) {
        case CAN_RX_EVENT:
            RxMessage = (CAN_RX_MSG_BUFFER *) PLIB_CAN_ReceivedMessageGet(CAN_ID_1, 1);
            if (RxMessage != NULL) {
                if (RxMessage->msgEID.ide) //EID Address
                {
                    tempAddress = (RxMessage->msgSID.sid << 18);
                    tempAddress |= ((0x3FFFF)&(RxMessage->msgEID.eid));
                } else {
                    tempAddress = RxMessage->msgSID.sid;
                }
                sprintf(stringa, "0x%x", tempAddress);
                WRT_USART_WriteLine(appData.handleUSART6, stringa, strlen(stringa));
                WRT_USART_WriteBinArray(appData.handleUSART6,RxMessage->data,RxMessage->msgEID.data_length_code);
            } else {
                WRT_USART_WriteLine(appData.handleUSART6, "null", strlen("null"));
            }
            PLIB_CAN_ChannelUpdate(CAN_ID_1, 1);
            break;
    }
    PLIB_CAN_ModuleEventClear(CAN_ID_1, r_event);
    PLIB_INT_SourceFlagClear(INT_ID_0, INT_SOURCE_CAN_1);
}

In the code above, the USART_  commands are just utilities that I use to get the data out via USART.  As you can see, I basically went into the data structures because I was unable to sort out why I wasn't seeing data through the abstracted functions.

Any suggestions on how to get the messages with the higher address?  Do I have a some fundamental flaw in my understanding of the CANBUS mask/filter settings?  (I'm using a PIC32MZ)  Any guidance would be greatly appreciated.






回帖(6)

程娇

2019-3-12 15:31:57
你使用的是什么版本的和声(1?x或2?x)?

以上来自于百度翻译


      以下为原文

    Which version of Harmony are you using (1.x or 2.x)?
举报

刘秀英

2019-3-12 15:49:07
我用和声V2Y02Y000

以上来自于百度翻译


      以下为原文

    I am using Harmony v2_02_00b
 
举报

程娇

2019-3-12 15:59:14
两个观察(可能或可能不重要):应该:PLBIK-Chan-ChhannUp更新(ChanaId1,1);在开关/ case语句之外移动?而不是ReEngEnter(仅仅是一个编程的优点)的无符号int:Chan-MeaveEnEncInEngult= PLIPK-CuiMeaveEngIGET(ChanaId1);

以上来自于百度翻译


      以下为原文

     a couple of observations (may or may not matter):
 
Should the:   PLIB_CAN_ChannelUpdate(CAN_ID_1, 1);    be moved outside of the switch/case statement?
 
instead of unsigned int for r_event  (just a programming goodness):
CAN_MODULE_EVENT r_event = PLIB_CAN_ModuleEventGet(CAN_ID_1);
举报

刘秀英

2019-3-12 16:12:31
我一直在玩这个,但没有效果。当生成事件时,它才生成。这就是为什么在处理事件之前我不检查ID的原因。我相信这是真的,因为第4452页的图片在OrthyYelHelp.PDF版本2.02V上回到了问题的症结,如果我只使用0x0作为掩码和过滤器,我会得到最低优先级的消息。我要找的是Mease0x10FFAAD2,所以我将过滤器设置为这个值。我把面具设为0x1FFF000,因为我想确定我没有在某个地方漏掉一些地址。对于这些设置,我从CAN中断中看不到任何东西。我想我会开始关注PLIB,但是为PLIB生成的和谐代码看起来很好:我知道的事情是:1)它是连接的,因为我可以通过0x0过滤器看到总线上的最低优先级消息。2)如果我把面罩/过滤器换成总线上的其他地址,它就不起作用了。我觉得这是一个平凡的细节,但我不知道会是什么。这种模式和它有什么关系吗?我只是在听留言,非常感谢您的建议。

以上来自于百度翻译


      以下为原文

    I've been playing around with this, but to no avail.  When an event is generated, it's just generated.  This is why I do not check for the ID until I handle the event.   I believe this is true due to the image on page 4452 on version 2.02v of the harmony_help.pdf   Back to the crux of the issue, if I just use 0x0 for the mask and filter, I get the lowest priority message.  What I am looking for is message 0x10FFAAD2, so I set the filter to this value.   I set the mask to 0x1FFFF000 because I wanted to be sure that I wasn't missing some address somewhere.    For these settings, I see nothing from the CAN interrupt.  I figured that I'd start to look at PLIB, but the Harmony code generated for PLIB looks pretty good:
 
void DRV_CAN0_Initialize(void)
{

    /* Switch the CAN module ON */
    PLIB_CAN_Enable(CAN_ID_1);
    
    /* Switch the CAN module to Configuration mode. Wait until the switch is complete */
    PLIB_CAN_OperationModeSelect(CAN_ID_1, CAN_CONFIGURATION_MODE);
    while(PLIB_CAN_OperationModeGet(CAN_ID_1) != CAN_CONFIGURATION_MODE);

    PLIB_CAN_PhaseSegment2LengthFreelyProgrammableEnable(CAN_ID_1);

    //Set the Baud rate to 250 kbps
    PLIB_CAN_PropagationTimeSegmentSet(CAN_ID_1, 1-1);
    PLIB_CAN_PhaseSegment1LengthSet(CAN_ID_1, 3-1);
    PLIB_CAN_PhaseSegment2LengthSet(CAN_ID_1, 3-1);
    PLIB_CAN_SyncJumpWidthSet(CAN_ID_1, 1-1);
    PLIB_CAN_BaudRatePrescaleSet(CAN_ID_1, 49); // set to 1 higher then ECAN tool


    /* Assign the buffer area to the CAN module.
      In this case assign enough memory for 2
      channels, each with 8 message buffers.*/
    PLIB_CAN_MemoryBufferAssign(CAN_ID_1, can_message_buffer0);

    /* Configure CAN_ID_1 Channel for CAN_TX_RTR_DISABLED operation. Allocate 1 message buffer, and assign low medium priority for transmissions. */
    PLIB_CAN_ChannelForTransmitSet(CAN_ID_1, CAN_CHANNEL0, 1, CAN_TX_RTR_DISABLED, CAN_LOW_MEDIUM_PRIORITY);
    /* Configure CAN_ID_1 Channel for CAN_RX_FULL_RECEIVE operation. Allocate 1 message buffer, and assign low medium priority for transmissions. */
    PLIB_CAN_ChannelForReceiveSet(CAN_ID_1, CAN_CHANNEL1, 1, CAN_RX_FULL_RECEIVE);
    PLIB_CAN_FilterToChannelLink(CAN_ID_1, CAN_FILTER0, CAN_FILTER_MASK0, CAN_CHANNEL1);
    PLIB_CAN_ChannelEventEnable(CAN_ID_1, CAN_CHANNEL1, CAN_RX_CHANNEL_NOT_EMPTY);
    PLIB_CAN_FilterConfigure(CAN_ID_1, CAN_FILTER0, 0x10FFAAD2, CAN_EID);
    PLIB_CAN_FilterEnable(CAN_ID_1, CAN_FILTER0);

    PLIB_CAN_FilterMaskConfigure(CAN_ID_1, CAN_FILTER_MASK0, 0x1FFFF000, CAN_EID, CAN_FILTER_MASK_ANY_TYPE);

    /* Switch the CAN module to Normal mode. Wait until the switch is complete */
    PLIB_CAN_OperationModeSelect(CAN_ID_1, CAN_LISTEN_ALL_MESSAGES_MODE);
    while(PLIB_CAN_OperationModeGet(CAN_ID_1) != CAN_LISTEN_ALL_MESSAGES_MODE);

    PLIB_CAN_ModuleEventEnable(CAN_ID_1 , 0|CAN_All_EVENTS);

    /* Setup CAN_ID_1 Interrupt */
    PLIB_INT_SourceEnable(INT_ID_0,INT_SOURCE_CAN_1);
    PLIB_INT_VectorPrioritySet(INT_ID_0,INT_VECTOR_CAN1, INT_PRIORITY_LEVEL3);
    PLIB_INT_VectorSubPrioritySet(INT_ID_0,INT_VECTOR_CAN1, INT_SUBPRIORITY_LEVEL1);
}
 
The things that I know:  1) it's connected, as I can see the lowest priority message on the bus via the 0x0 filter.  2) I'm if I change the mask/filter to the other addresses on the bus, it doesn't work. 
I feel that this is a mundane detail in the configuration, but I have no idea what that would be.  Would the mode have something to do with it?  I'm just listening to messages.
 
Any suggestions would be greatly appreciated.  
 
 
 
 
举报

更多回帖

发帖
×
20
完善资料,
赚取积分