EVB-4357: project periph_ccan

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

EVB-4357: project periph_ccan

跳至解决方案
1,334 次查看
andreaskneissl
Contributor II

In this project an acceptance filter is set to identifier 0x100 and the interrupt filter is handling status interrupts and error interrupts. When I am sending messages with other identifiers, I get an status interupt with status CCAN_STAT_RXOK. But the message I cannot read. When I remove status interrupt from my interrupt filter I get only interrupts for the identifier 0x100, what I expect.

1) Is there any way to get the message of identifier, which are not defined in a filter?
   -> status interrupt CCAN_STAT_RXOK -> read message from other identifier

2) How I can get every message received from the CAN-bus (no filter)

标签 (2)
0 项奖励
回复
1 解答
1,044 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Andreas Kneissl,

  You can configure the can in the test mode, and enable the basic mode.

   Please modify the code like this:

CCAN_MSG_OBJ_T can_msg;

void CAN0_IRQHandler(void)
{
     CCAN_MSG_OBJ_T msg_buf;
     uint32_t can_int, can_stat, i;
     while ( (can_int = Chip_CCAN_GetIntID(LPC_C_CAN0)) != 0 ) {
          //if ((can_int & CCAN_INT_STATUS) ) 
                if ((CCAN_INT_STATUS == can_int) && (CCAN_STAT_RXOK & LPC_C_CAN0->STAT))
                {
                  //CCAN_MSG_OBJ_T can_msg;

                  can_msg.id = (uint32_t) (LPC_C_CAN0->IF[1].ARB1 | LPC_C_CAN0->IF[1].ARB2 << 16);

                  if (can_msg.id & (0x1 << 30)){
                     can_msg.id &= CCAN_MSG_ID_EXT_MASK;
                    }
                  else {
                     can_msg.id >>= 18;
                     can_msg.id &= CCAN_MSG_ID_STD_MASK;
                   }

                  can_msg.dlc = (uint8_t) (LPC_C_CAN0->IF[1].MCTRL & CCAN_IF_MCTRL_DLC_MSK);

                  *((uint16_t *)&can_msg.data[0]) = (uint16_t) (LPC_C_CAN0->IF[1].DA1 & 0x0000FFFF);
                  *((uint16_t *)&can_msg.data[2]) = (uint16_t) (LPC_C_CAN0->IF[1].DA2 & 0x0000FFFF);
                  *((uint16_t *)&can_msg.data[4]) = (uint16_t) (LPC_C_CAN0->IF[1].DB1 & 0x0000FFFF);
                  *((uint16_t *)&can_msg.data[6]) = (uint16_t) (LPC_C_CAN0->IF[1].DB2 & 0x0000FFFF);

                 
                  DEBUGOUT("can_msg ID :%x\r\n", can_msg.id);
                    DEBUGOUT("can_msg data :");
                    for (i = 0; i < can_msg.dlc; i++) {
                         DEBUGOUT("%x ", can_msg.data[i]);
                    }
                    DEBUGOUT("\r\nFeed back...\r\n");
                  Rx_Flag =1;
                  LPC_C_CAN0->STAT = LPC_C_CAN0->STAT & (~CCAN_STAT_RXOK);

                  return;
                }

     }
}
int main(void)
{
     CCAN_MSG_OBJ_T send_obj;
     SystemCoreClockUpdate();
     Board_Init();
     set_pinmux();
     DEBUGOUT(WelcomeMenu);
     /* Set CCAN peripheral clock under 100Mhz for working stable */
     Chip_Clock_SetBaseClock(CLK_BASE_APB3, CLKIN_IDIVC, true, false);
     Chip_CCAN_Init(LPC_C_CAN0);
        Chip_CCAN_EnableTestMode(LPC_C_CAN0);//jjadd
       // Chip_CCAN_ConfigTestMode(LPC_C_CAN0, ( CCAN_TEST_BASIC_MODE));//jjadd //CCAN_TEST_SILENT_MODE |
     Chip_CCAN_SetBitRate(LPC_C_CAN0, 500000);
     Chip_CCAN_EnableInt(LPC_C_CAN0, (CCAN_CTRL_IE | CCAN_CTRL_SIE | CCAN_CTRL_EIE));

     send_obj.id = CCAN_TX_MSG_ID;
     send_obj.dlc = 4;
     send_obj.data[0] = 'A';
     send_obj.data[1] = 'B';
     send_obj.data[2] = 'C';
     send_obj.data[3] = 'D';
     Chip_CCAN_Send(LPC_C_CAN0, CCAN_MSG_IF1, false, &send_obj);
     Chip_CCAN_ClearStatus(LPC_C_CAN0, CCAN_STAT_TXOK);


        Chip_CCAN_ConfigTestMode(LPC_C_CAN0, ( CCAN_TEST_BASIC_MODE));
        
     NVIC_EnableIRQ(C_CAN0_IRQn);

     while (1) {
        
        }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

After modify like the above code, I can receive all the IDs.

The test result is:

pastedImage_1.png

Wish it helps you!

If you still have question, please let me know!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

在原帖中查看解决方案

0 项奖励
回复
1 回复
1,045 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Andreas Kneissl,

  You can configure the can in the test mode, and enable the basic mode.

   Please modify the code like this:

CCAN_MSG_OBJ_T can_msg;

void CAN0_IRQHandler(void)
{
     CCAN_MSG_OBJ_T msg_buf;
     uint32_t can_int, can_stat, i;
     while ( (can_int = Chip_CCAN_GetIntID(LPC_C_CAN0)) != 0 ) {
          //if ((can_int & CCAN_INT_STATUS) ) 
                if ((CCAN_INT_STATUS == can_int) && (CCAN_STAT_RXOK & LPC_C_CAN0->STAT))
                {
                  //CCAN_MSG_OBJ_T can_msg;

                  can_msg.id = (uint32_t) (LPC_C_CAN0->IF[1].ARB1 | LPC_C_CAN0->IF[1].ARB2 << 16);

                  if (can_msg.id & (0x1 << 30)){
                     can_msg.id &= CCAN_MSG_ID_EXT_MASK;
                    }
                  else {
                     can_msg.id >>= 18;
                     can_msg.id &= CCAN_MSG_ID_STD_MASK;
                   }

                  can_msg.dlc = (uint8_t) (LPC_C_CAN0->IF[1].MCTRL & CCAN_IF_MCTRL_DLC_MSK);

                  *((uint16_t *)&can_msg.data[0]) = (uint16_t) (LPC_C_CAN0->IF[1].DA1 & 0x0000FFFF);
                  *((uint16_t *)&can_msg.data[2]) = (uint16_t) (LPC_C_CAN0->IF[1].DA2 & 0x0000FFFF);
                  *((uint16_t *)&can_msg.data[4]) = (uint16_t) (LPC_C_CAN0->IF[1].DB1 & 0x0000FFFF);
                  *((uint16_t *)&can_msg.data[6]) = (uint16_t) (LPC_C_CAN0->IF[1].DB2 & 0x0000FFFF);

                 
                  DEBUGOUT("can_msg ID :%x\r\n", can_msg.id);
                    DEBUGOUT("can_msg data :");
                    for (i = 0; i < can_msg.dlc; i++) {
                         DEBUGOUT("%x ", can_msg.data[i]);
                    }
                    DEBUGOUT("\r\nFeed back...\r\n");
                  Rx_Flag =1;
                  LPC_C_CAN0->STAT = LPC_C_CAN0->STAT & (~CCAN_STAT_RXOK);

                  return;
                }

     }
}
int main(void)
{
     CCAN_MSG_OBJ_T send_obj;
     SystemCoreClockUpdate();
     Board_Init();
     set_pinmux();
     DEBUGOUT(WelcomeMenu);
     /* Set CCAN peripheral clock under 100Mhz for working stable */
     Chip_Clock_SetBaseClock(CLK_BASE_APB3, CLKIN_IDIVC, true, false);
     Chip_CCAN_Init(LPC_C_CAN0);
        Chip_CCAN_EnableTestMode(LPC_C_CAN0);//jjadd
       // Chip_CCAN_ConfigTestMode(LPC_C_CAN0, ( CCAN_TEST_BASIC_MODE));//jjadd //CCAN_TEST_SILENT_MODE |
     Chip_CCAN_SetBitRate(LPC_C_CAN0, 500000);
     Chip_CCAN_EnableInt(LPC_C_CAN0, (CCAN_CTRL_IE | CCAN_CTRL_SIE | CCAN_CTRL_EIE));

     send_obj.id = CCAN_TX_MSG_ID;
     send_obj.dlc = 4;
     send_obj.data[0] = 'A';
     send_obj.data[1] = 'B';
     send_obj.data[2] = 'C';
     send_obj.data[3] = 'D';
     Chip_CCAN_Send(LPC_C_CAN0, CCAN_MSG_IF1, false, &send_obj);
     Chip_CCAN_ClearStatus(LPC_C_CAN0, CCAN_STAT_TXOK);


        Chip_CCAN_ConfigTestMode(LPC_C_CAN0, ( CCAN_TEST_BASIC_MODE));
        
     NVIC_EnableIRQ(C_CAN0_IRQn);

     while (1) {
        
        }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

After modify like the above code, I can receive all the IDs.

The test result is:

pastedImage_1.png

Wish it helps you!

If you still have question, please let me know!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复