各位大神 我是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通信的问题有可能出在哪里? |
STMS005K6T6 如何采集内部参考电压。
stm8s003 adc中断和通道切换的问题
adc施密特触发器stm8
stm8l051f3 TSSOP20 封装,待机模式下,2天后,电流突然增加到140UA
STM8S用STVP烧录怎么加密?
如何使用ST官网例程_LIN总线通讯_STM8AF
STM8 LIN
IAR代码编辑太费劲了,想问一下有没有好的方法,试了VScode但是头文件老是报错,调了很久也没调好,想换个方法了。
想问一下各位大佬,IAR下载调试代码时出现 warning: is an illegal data sample expression IAR是什么意思啊?
STM8S标准库TIM1编码器功能不计数,请大师帮我看看
我的代码就是引用网上下的demo code,只是不知道是不是自己操作哪里不当,或者引用别人代码时有遗漏的。请问你有CAN通信的可用代码吗?