同一块板子上的CAN1与CAN2进行通信,CAN1在正常模式下可以发送以及接收,CAN2只能发送不能接收
谢谢
也不行,CAN2只能发送成功,没法接收
请问你的CAN2接收问题解决了吗?
您好,参考2楼附件例程,都是测试过没有问题的
can2 查询的方式可以接受,中断的方式接收不了信息,会不会中断配置错误?
void CAN2_RX0_IRQHandler (void) __attribute__((interrupt("WCH-Interrupt-fast")));
/****************************模块CAN初始化****************************************/
void Mod_Can_Init(void)
{
CAN_DeInit(CAN2);
?RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
?RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2, ENABLE);
?GPIO_InitTypeDef GPIO_InitStructure;
?CAN_InitTypeDef? CAN_InitSturctureTypeDef;
?CAN_FilterInitTypeDef CAN_FilterInitStructure;
?NVIC_InitTypeDef? NVIC_InitTypeDefStructure;
?GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
?GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
?GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
?GPIO_Init(GPIOB, &GPIO_InitStructure);
?GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
?GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
?GPIO_Init(GPIOB, &GPIO_InitStructure);
?CAN_InitSturctureTypeDef.CAN_TTCM = DISABLE;
?CAN_InitSturctureTypeDef.CAN_TXFP = DISABLE;
?CAN_InitSturctureTypeDef.CAN_ABOM = DISABLE;
?CAN_InitSturctureTypeDef.CAN_AWUM = DISABLE;
?CAN_InitSturctureTypeDef.CAN_NART = ENABLE;
?CAN_InitSturctureTypeDef.CAN_RFLM = DISABLE;
?CAN_InitSturctureTypeDef.CAN_Mode = CAN_Mode_Normal;
?CAN_InitSturctureTypeDef.CAN_SJW =? CAN_SJW_1tq;
?CAN_InitSturctureTypeDef.CAN_BS1 =? CAN_BS1_5tq;
?CAN_InitSturctureTypeDef.CAN_BS2 =? CAN_BS1_3tq;
?CAN_InitSturctureTypeDef.CAN_Prescaler = 64;? ? ? ?
?CAN_Init(CAN2, &CAN_InitSturctureTypeDef);
?CAN_FilterInitStructure.CAN_FilterNumber = 0;? ? ? ? ?// 滤波器组
?CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;
?CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
?MReceiveID = ModO_Rx_ID;
?CAN_FilterInitStructure.CAN_FilterIdHigh =(MReceiveID<<3)&0xFFFF0000;
?CAN_FilterInitStructure.CAN_FilterIdLow = ((MReceiveID<<3)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
?CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000;
?CAN_FilterInitStructure.CAN_FilterMaskIdLow =? 0x0000;
?CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FilterFIFO0;
?CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
?CAN_FilterInit(&CAN_FilterInitStructure);
?NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
?NVIC_InitTypeDefStructure.NVIC_IRQChannel = CAN2_RX0_IRQn;
?NVIC_InitTypeDefStructure.NVIC_IRQChannelPreemptionPriority =? 1;
?NVIC_InitTypeDefStructure.NVIC_IRQChannelSubPriority = 1;
?NVIC_InitTypeDefStructure.NVIC_IRQChannelCmd = ENABLE;
?NVIC_Init(&NVIC_InitTypeDefStructure);
?CAN_ITConfig(CAN2, CAN_IT_FF0|CAN_IT_FF1, ENABLE);
?CAN_ClearITPendingBit(CAN2,CAN_IT_FF0|CAN_IT_FF1);
}
void Mod_Data_Init(void)
{
?ModRxCurT? = 0;
?ModRxCurH = 0;
?Mod.mdSendToAlarm = AlarmGetValFromMod;
?Mod.mdSendToLcd = lcdGetValFromMod;
?Mod.Cmd = 0;
}
/************************can接受中断************************************/
void CAN2_RX0_IRQHandler(void)
{
?if(CAN_GetITStatus(CAN2, CAN_IT_FF0) == SET)
?{
? ?ModRxCurT++;
? ?if(ModRxCurT>=10)
? ?ModRxCurT = 0;
? ?CAN_ClearITPendingBit(CAN2,CAN_IT_FF0);
? ?printf("Can2中断触发1");
? ?if( CAN_MessagePending( CAN2, CAN_FIFO0 ) == 0)
? ? ?return;
? ? CAN_Receive(CAN2,CAN_FIFO0, &MRxMessage[ModRxCurT]);
? }
? if(CAN_GetITStatus(CAN2, CAN_IT_FF1) == SET )
?{
? ? ModRxCurT++;
? ? if(ModRxCurT>=10)
? ? ?ModRxCurT = 0;
? ? ?CAN_ClearITPendingBit(CAN2,CAN_IT_FF1);
? ? ?printf("Can2中断触发2");
? ? ?if( CAN_MessagePending( CAN2, CAN_FIFO1 ) == 0)
? ? ? ?return;
? ? ?CAN_Receive(CAN2,CAN_FIFO1, &MRxMessage[ModRxCurT]);
?}
}
您好! 程序已经测试,第一次下载正常,能够打印中断信息,但是多次下载程序后,CAN2中断无法接收信息,开启了程序的can2发送,通信正常,依然无法中断接收信息。
您好,正常情况下,第一次下载正常运行,后面下载应该也不会有问题的,可检查一下工程以及下载文件是否被改变。相关问题这边工程师也已和你沟通过,附件为测试例程,若有需要,可再次下载测试一下
您好,我有一个问题,2楼的CAN查询接收发送例程中,为什么CAN2的例程都不需要设置ID过滤呢?我看函数里面都是对CAN1的寄存器操作。我通过什么来确定,数据是接收到CAN_FIFO0还是CAN_FIFO1呢??