同一塊板子上的CAN1與CAN2進(jìn)行通信,CAN1在正常模式下可以發(fā)送以及接收,CAN2只能發(fā)送不能接收
謝謝
也不行,CAN2只能發(fā)送成功,沒法接收
請問你的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中斷觸發(fā)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中斷觸發(fā)2");
? ? ?if( CAN_MessagePending( CAN2, CAN_FIFO1 ) == 0)
? ? ? ?return;
? ? ?CAN_Receive(CAN2,CAN_FIFO1, &MRxMessage[ModRxCurT]);
?}
}
您好! 程序已經(jīng)測試,第一次下載正常,能夠打印中斷信息,但是多次下載程序后,CAN2中斷無法接收信息,開啟了程序的can2發(fā)送,通信正常,依然無法中斷接收信息。
您好,正常情況下,第一次下載正常運(yùn)行,后面下載應(yīng)該也不會有問題的,可檢查一下工程以及下載文件是否被改變。相關(guān)問題這邊工程師也已和你溝通過,附件為測試?yán)蹋粲行枰?,可再次下載測試一下
您好,我有一個問題,2樓的CAN查詢接收發(fā)送例程中,為什么CAN2的例程都不需要設(shè)置ID過濾呢?我看函數(shù)里面都是對CAN1的寄存器操作。我通過什么來確定,數(shù)據(jù)是接收到CAN_FIFO0還是CAN_FIFO1呢??