Tip / 登入 to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Translation_Bot
Community Manager
Community Manager
Community Manager
can 發送資料失敗,一發送就會進入buf off, 下面有我的例程, 可以幫忙看看嗎? #include "Ifx_Types.h" #include "IfxCpu.h" #include "IfxScuWdt.h" IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0; #include "Ifx_Types.h" #include "IfxCan_Can.h" #include "IfxCan.h" #include "IfxCpu_Irq.h" #include "IfxPort.h" #include "Bsp.h" #define LED0 &MODULE_P13,0 #define LED1 & #define LED2 &MODULE_P13,2 #define LED3 &MODULE_P13,3 #define MODULE_CAN0_RAM 0xF020000 #define CAN_MESSAGE_TX_ID0 (uint32 )0x1234567 #define CAN_MESSAGE_RX_ID1 (uint32)0x1234561 #define CAN_MESSAGE_RX_ID2 (uint32)0x1234562 #define CAN_MESSAGE_RXID3( /* Define the CAN TX interrupt priority * #define ISR_PRIORITY_CAN_RX 1 /* Define the CAN RX interrupt priority */ #define ISR_PRIORITY_CAN22_BUSOFF 3 #define 2 /* Define maximum classical { IfxCan_Can_Config canConfig; /* CAN module configuration structure */ IfxCan_Can canModule; /* CAN module handle */ IfxCan_Can_Node can00Node; /* CAN source node handle data structure */ IfxCan_Can_NodeConfig canNodeConfig; /* CAN node configuration structure */ IfxCan_Filter canFilter; /* CAN filter configuration structure */ IfxCan_Message txMsg; /* Transmitted CAN message structure */ IfxCan_Message rxMsg; /* Received CAN message structure */ uint32 txData[MAXIMUM_CAN_DATA_PAYLOAD]; /* Transmitted CAN data array */ uint32 rxData[MAXIMUM_CAN_DATA_PAYLOAD]; /* Received CAN data array */ } { &IfxCan_TXD00_P20_8_OUT, IfxPort_OutputMode_pushPull, // CAN00_TX &IfxCan_RXD00B_P20_7_IN, IfxPort_InputMode_pullUp, // CAN00_RX IfxPort_PadDriver_cmosAutomotiveSpeed4 } g_mcmcan; void initCAN0(void); IFX_INTERRUPT(can22IsrBusOffHandler, 0, ISR_PRIORITY_CAN22_BUSOFF); void can22IsrBusOffHandler(void) { IfxCan_Node_clearInterruptFlag(g_mcmcan.can00Node.node, IfxCan_Interrupt_busOffStatus); initCAN0(); IfxPort_togglePin(LED1); //transmit indicator } (void) { /* Clear the "Transmission Completed" interrupt flag */ IfxCan_Node_clearInterruptFlag(g_mcmcan.can00Node.node, IfxCan_Interrupt_transmissionCompleted); IfxPort_togglePin(LED0); //transmit indicator } IFX_INTERRUPT(canIsrRxHandler, 0, ISR_PRIORITY_CAN_RX); void canIsrRxHandler(void) { /* Clear the "Message storeNode. Dedicated RX Buffer" interrupt flaglag*/ 30mflagx1005,F0* ,F0*0IfxCan_Interrupt_messageStoredToDedicatedRxBuffer); /* Clear the "New Data" flag; as long as the "New Data" flag is set, the respective Rx buffer is * locked against updates from eived matching frames */ IfxCan_Node_clearRxBufferNewDataFlag(g_mcmcan.can00Node.node,g_mcmcan.canFilter.rxBufferOffset); /* Read the received CAN message */ IfxCan_Can_readMessage(&g_mcmcan.can00Node, &g_mcmcan.rxMsg,g_mcmcan.rxData); /* Check if the received data matches with the transmitted one */ if((g_mcmcan.rxMsg.messageId == CAN_MESSAGE_RX_ID1) && (g_mcmcan.rxData[1]== 0xEFCDAB89)) { if(g_mcmcan.rxData[0]== 0x67452301) { //send 0x IfxPort_setPinState(LED1, IfxPort_State_low); //LED ON } else { IfxPort_setPinState(LED1, IfxPort_State_high); //LED OFF } } if((g_mcmcan.rxMsg.messageId == CAN_MESSAGE_RX_ID2) && (g_mcmcan.rxData[1]== 0xEFCDAB89)) { if(g_mcmcan.rxData[0]== 0x67452302) { IfxPort_setPinState(LED2, IfxPort_State_low); } else { IfxPort_setPinState(LED2, IfxPort_State_high); } } if((g_mcmcan.rxMsg.messageId == CAN_MESSAGE_RX_ID3) && (g_mcmcan.rxData[1]== 0xEFCDAB89)) { if(g_mcmcan.rxData[0]== 0x67452303) { IfxPort_setPinState(LED3, IfxPort_State_low); } else { IfxPort_setPinState(LED3, IfxPort_State_high); } } } void initCAN0(void) { /*******CAN module configuration and initialization*******/ IfxCan_Can_initModuleConfig(&g_mcmcan.canConfig, &MODULE_CAN0); IfxCan_Can_initModule(&g_mcmcan.canModule, &g_mcmcan.canConfig); /*******CAN00 node configuration and initialization*******/ IfxCan_Can_initNodeConfig(&g_mcmcan.canNodeConfig, &g_mcmcan.canModule); g_mcmcan.canNodeConfig.nodeId = IfxCan_NodeId_0; g_mcmcan.canNodeConfig.clockSource = IfxCan_ClockSource_both; g_mcmcan.canNodeConfig.frame.type = IfxCan_FrameType_transmitAndReceive; g_mcmcan.canNodeConfig.frame.mode = IfxCan_FrameMode_standard; //Classic CAN g_mcmcan.canNodeConfig.txConfig.txMode = IfxCan_TxMode_dedicatedBuffers; g_mcmcan.canNodeConfig.txConfig.dedicatedTxBuffersNumber = 255; g_mcmcan.canNodeConfig.txConfig.txBufferDataFieldSize = IfxCan_DataFieldSize_8; g_mcmcan.canNodeConfig.rxConfig.rxMode = IfxCan_RxMode_dedicatedBuffers; g_mcmcan.canNodeConfig.rxConfig.rxBufferDataFieldSize = IfxCan_DataFieldSize_8; g_mcmcan.canNodeConfig.filterConfig.extendedListSize = 255; //Extended Frame g_mcmcan.canNodeConfig.filterConfig.messageIdLength = IfxCan_MessageIdLength_extended; g_mcmcan.canNodeConfig.messageRAM.extendedFilterListStartAddress = 0x100; //Extended Frame g_mcmcan.canNodeConfig.messageRAM.rxBuffersStartAddress = 0x200; g_mcmcan.canNodeConfig.messageRAM.txBuffersStartAddress = 0x400; g_mcmcan.canNodeConfig.messageRAM.baseAddress = MODULE_CAN0_RAM + NODE0_RAM_OFFSET; g_mcmcan.canNodeConfig.baudRate.baudrate = 500000; //500KBaud //transmit interrupt g_mcmcan.canNodeConfig.interruptConfig.transmissionCompletedEnabled = TRUE; g_mcmcan.canNodeConfig.interruptConfig.traco.priority = ISR_PRIORITY_CAN_TX; g_mcmcan.canNodeConfig.interruptConfig.traco.interruptLine = IfxCan_InterruptLine_0; g_mcmcan.canNodeConfig.interruptConfig.traco.typeOfService = IfxSrc_Tos_cpu0; //receive interrupt g_mcmcan.canNodeConfig.interruptConfig.messageStoredToDedicatedRxBufferEnabled = TRUE; g_mcmcan.canNodeConfig.interruptConfig.reint.priority = ISR_PRIORITY_CAN_RX; g_mcmcan.canNodeConfig.interruptConfig.reint.interruptLine = IfxCan_InterruptLine_1; g_mcmcan.canNodeConfig.interruptConfig.reint.typeOfService = IfxSrc_Tos_cpu0; //bus-off interrupt g_mcmcan.canNodeConfig.interruptConfig.busOffStatusEnabled = TRUE; g_mcmcan.canNodeConfig.interruptConfig.boff.priority = ISR_PRIORITY_CAN22_BUSOFF; g_mcmcan.canNodeConfig.interruptConfig.boff.interruptLine = IfxCan_InterruptLine_2; g_mcmcan.canNodeConfig.interruptConfig.boff.typeOfService = IfxSrc_Tos_cpu0; //binding pin g_mcmcan.canNodeConfig.pins = &Can00_pins; IfxCan_Can_initNode(&g_mcmcan.can00Node, &g_mcmcan.canNodeConfig); /*******CAN filter configuration and initialization*******/ g_mcmcan.canFilter.number = 0; g_mcmcan.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxBuffer; g_mcmcan.canFilter.id1 = CAN_MESSAGE_RX_ID1; g_mcmcan.canFilter.rxBufferOffset = IfxCan_RxBufferId_0; //IfxCan_Can_setStandardFilter(&g_mcmcan.can00Node, &g_mcmcan.canFilter); IfxCan_Can_setExtendedFilter(&g_mcmcan.can00Node, &g_mcmcan.canFilter); g_mcmcan.canFilter.number = 1; g_mcmcan.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxBuffer; g_mcmcan.canFilter.id1 = CAN_MESSAGE_RX_ID2; //g_mcmcan.canFilter.id2 = CAN_MESSAGE_RX_ID2; g_mcmcan.canFilter.rxBufferOffset = IfxCan_RxBufferId_0; //IfxCan_Can_setStandardFilter(&g_mcmcan.can00Node, &g_mcmcan.canFilter); IfxCan_Can_setExtendedFilter(&g_mcmcan.can00Node, &g_mcmcan.canFilter); g_mcmcan.canFilter.number = 2; g_mcmcan.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxBuffer; g_mcmcan.canFilter.id1 = CAN_MESSAGE_RX_ID3; //g_mcmcan.canFilter.id2 = CAN_MESSAGE_RX_ID3; g_mcmcan.canFilter.rxBufferOffset = IfxCan_RxBufferId_0; //IfxCan_Can_setStandardFilter(&g_mcmcan.can00Node, &g_mcmcan.canFilter); IfxCan_Can_setExtendedFilter(&g_mcmcan.can00Node, &g_mcmcan.canFilter); } void initLED(void) { IfxPort_setPinMode(LED0, IfxPort_Mode_outputPushPullGeneral); /* Initialize LED port pin */ IfxPort_setPinMode(LED1, IfxPort_Mode_outputPushPullGeneral); IfxPort_setPinMode(LED2, IfxPort_Mode_outputPushPullGeneral); IfxPort_setPinMode(LED3, IfxPort_Mode_outputPushPullGeneral); IfxPort_setPinState(LED0, IfxPort_State_high); /* Turn off LED (LED is low-level active) */ IfxPort_setPinState(LED1, IfxPort_State_high); IfxPort_setPinState(LED2, IfxPort_State_high); IfxPort_setPinState(LED3, IfxPort_State_high); } void core0_main(void) { IfxC_enable) ; /* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE * Enable the watchdogs and service them periodically if it is required */ IfxScuWdt_disxSatchWatch(Watch_Watcham(cOft)_cuWdt_disxSatchWatch_dis; ableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword()); /* Wait for CPU sync event */ IfxCpu_emitEvent(&g_cpuSyncEvent ; IfxCpu_waitEvent(&g_cpuSyncEvent caten) dinitTime(cx) ); g_mcmcan.txMsg.messageId = CAN_MESSAGE_TX_ID0; g_mcmcan.txMsg.bufferNumber= 0; g_mcmcan.txMsg.dataLengthCode= IfxCan_DataLengthCode_8;//8 bytes g_mcmcan.txMsg.frameMode = IfxCan_FrameMode_standard; //Classic CAN g_mcmcan.txMsg.messageIdLength=IfxCan_MessageIdLength_extended;//Extended Frame g_mcmcan.txData[0]= 0x98BADCFE; g_mcmcan.txData[1]= 0x10325476; //you will receive: FE DC BA 98 76 54 32 10 while(1) { while(IfxCan_Status_notSentBusy == IfxCan_Can_sendMessage(&g_mcmcan.can00Node, &g_mcmcan.txMsg, &g_mcmcan.txData[0]) ); waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 1000)); //ms } }

smartconx_target@Q!w2e3r4t5y6u7i8o9p0||/t5/AURIX/tc397-can-%E5%8F%91%E9%80%81%E6%95%B0%E6%8D%AE%E5%A4%B1%E8%B4%A5-%E4%B8%80%E5%8F%91%E9%80%81%E5%B0%B1%E4%BC%9A%E8%BF%9B%E5%85%A5buf-off/td-p/678165

1 解決方案
Translation_Bot
Community Manager
Community Manager
Community Manager

Hi @andersons ,

我想你需要把問題描述重新排版一下?上面的內容擠在一起根本沒辦法看。

BR,

Jeremy

smartconx_target@Q!w2e3r4t5y6u7i8o9p0||/t5/AURIX/tc397-can-%E5%8F%91%E9%80%81%E6%95%B0%E6%8D%AE%E5%A4%B1%E8%B4%A5-%E4%B8%80%E5%8F%91%E9%80%81%E5%B0%B1%E4%BC%9A%E8%BF%9B%E5%85%A5buf-off/m-p/678953

在原始文章中檢視解決方案

0
3 回應
Translation_Bot
Community Manager
Community Manager
Community Manager

Hi @andersons ,

我想你需要把問題描述重新排版一下?上面的內容擠在一起根本沒辦法看。

BR,

Jeremy

smartconx_target@Q!w2e3r4t5y6u7i8o9p0||/t5/AURIX/tc397-can-%E5%8F%91%E9%80%81%E6%95%B0%E6%8D%AE%E5%A4%B1%E8%B4%A5-%E4%B8%80%E5%8F%91%E9%80%81%E5%B0%B1%E4%BC%9A%E8%BF%9B%E5%85%A5buf-off/m-p/678953

0
Translation_Bot
Community Manager
Community Manager
Community Manager

Hi @andersons ,

请问问题解决了吗?

BR,

Jeremy

smartconx_target@Q!w2e3r4t5y6u7i8o9p0||/t5/AURIX/tc397-can-%E5%8F%91%E9%80%81%E6%95%B0%E6%8D%AE%E5%A4%B1%E8%B4%A5-%E4%B8%80%E5%8F%91%E9%80%81%E5%B0%B1%E4%BC%9A%E8%BF%9B%E5%85%A5buf-off/m-p/689133

0
Translation_Bot
Community Manager
Community Manager
Community Manager

Hi  @Jeremy_Z 

      抱歉,我没有注意到之前的消息, 问题已经解决了. 感谢支持. 

原因是我在测试can通讯的时候没有接入其它的can设备. 我看到can协议中需要有应答信号, 我想tc397应该是检测不到其它can设备的ack,导致一直发送不出去.

Best regards

smartconx_target@Q!w2e3r4t5y6u7i8o9p0||/t5/AURIX/tc397-can-%E5%8F%91%E9%80%81%E6%95%B0%E6%8D%AE%E5%A4%B1%E8%B4%A5-%E4%B8%80%E5%8F%91%E9%80%81%E5%B0%B1%E4%BC%9A%E8%BF%9B%E5%85%A5buf-off/m-p/689145

0