各位大神 我是STM8的新手,最近买了两套STM8A-DISCOVERY开发板,基于STM8AF52芯片开发,原本想着将两块开发板的CAN口对接,进行一些通信测试,但发现无法实现CAN通信,一下是我的代码,请各位大神指点指点: 主循环中的实现: main() { .... CLK_Config(); CAN_Config(); .... while(1) { ... /* Transmit Parameters*/ Tx_Id = 0; Tx_IDE = CAN_Id_Standard; Tx_RTR = CAN_RTR_Data; Tx_DLC = 1; Tx_Data[0] = i; GPIO_WriteLow(GPIOA, (GPIO_Pin_TypeDef)GPIO_PIN_3); /* Sender send Frame */ status = CAN_Transmit(Tx_Id,Tx_IDE,Tx_RTR,Tx_DLC,Tx_Data); ... } } void CLK_Config(void) { /* Initialization of the clock */ /* Clock divider to HSI/1 */ CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); } void CAN_Config(void) { CAN_InitStatus_TypeDef status = CAN_InitStatus_Failed; /* Filter Parameters */ CAN_FilterNumber_TypeDef CAN_FilterNumber; FunctionalState CAN_FilterActivation; CAN_FilterMode_TypeDef CAN_FilterMode; CAN_FilterScale_TypeDef CAN_FilterScale; UINT8 CAN_FilterID1; UINT8 CAN_FilterID2; UINT8 CAN_FilterID3; UINT8 CAN_FilterID4; UINT8 CAN_FilterIDMask1; UINT8 CAN_FilterIDMask2; UINT8 CAN_FilterIDMask3; UINT8 CAN_FilterIDMask4; /* Init Parameters*/ CAN_MasterCtrl_TypeDef CAN_MasterCtrl; CAN_Mode_TypeDef CAN_Mode; CAN_SynJumpWidth_TypeDef CAN_SynJumpWidth; CAN_BitSeg1_TypeDef CAN_BitSeg1; CAN_BitSeg2_TypeDef CAN_BitSeg2; UINT8 CAN_Prescaler; /* CAN register init */ CAN_DeInit(); /* CAN init */ CAN_MasterCtrl=CAN_MasterCtrl_AllDisabled; CAN_Mode = CAN_Mode_Normal; CAN_SynJumpWidth = CAN_SynJumpWidth_1TimeQuantum; CAN_BitSeg1 = CAN_BitSeg1_8TimeQuantum; CAN_BitSeg2 = CAN_BitSeg2_7TimeQuantum; CAN_Prescaler = 1; status = CAN_Init(CAN_MasterCtrl, CAN_Mode, CAN_SynJumpWidth, CAN_BitSeg1, \ CAN_BitSeg2, CAN_Prescaler); /* CAN filter init */ CAN_FilterNumber = CAN_FilterNumber_0; CAN_FilterActivation = ENABLE; CAN_FilterMode = CAN_FilterMode_IdMask; CAN_FilterScale = CAN_FilterScale_32Bit; CAN_FilterID1=0; CAN_FilterID2=0; CAN_FilterID3=0; CAN_FilterID4=0; CAN_FilterIDMask1=0; CAN_FilterIDMask2=0; CAN_FilterIDMask3=0; CAN_FilterIDMask4=0; CAN_FilterInit(CAN_FilterNumber, CAN_FilterActivation, CAN_FilterMode, CAN_FilterScale,CAN_FilterID1, CAN_FilterID2, CAN_FilterID3, CAN_FilterID4,CAN_FilterIDMask1, CAN_FilterIDMask2, CAN_FilterIDMask3, CAN_FilterIDMask4); /* Enable Fifo message pending interrupt*/ /* Message reception is done by CAN_RX ISR*/ CAN_ITConfig(CAN_IT_FMP, ENABLE); } 中断配置如下: /** * @brief CAN RX Interrupt routine. * @param None * @retval None */ INTERRUPT_HANDLER(CAN_RX_IRQHandler, 8) { /* In order to detect unexpected events during development, it is recommended to set a breakpoint on the following instruction. */ /* Receiver Receives Frame */ CAN_Receive(); } 同时在stm8_interrupt_vector.c文件中的中断向量表里修改如下: {0x82, (interrupt_handler_t)CAN_RX_IRQHandler}, /* irq8 */ 将两块开发板CAN口对接,然后我通过调试器将断点设置在中断响应函数的CAN_Receive()一行,无任何中断响应。请问,这个CAN通信的问题有可能出在哪里? |
测试标签123
IAR FOR ARM和IAR FOR STM8无法共存,
STM8L052,液晶内部电源怎么用?
STM8S103飞线外接芯片,I2C不能得到slaveAddress应答,通讯失败。
STM8S105C6T6 UART2串口,能接收数据,不能发送数据
STM8S105K4 串口2 无奇偶校验,也能接收 偶校验的 数据
在STM8S的IAP使用中断和APP使用中断问题
STM8L151 SMBUS设计
STM8S103F复位异常
STM8L的LCD调试时不亮
我的代码就是引用网上下的demo code,只是不知道是不是自己操作哪里不当,或者引用别人代码时有遗漏的。请问你有CAN通信的可用代码吗?