本帖最后由 lmhtz 于 2017-4-30 14:59 编辑
GD32F190C6 ,CAN发送正常,不能接收,回环模式也无法接收,谁有碰到
一下相关代码:
端口:
/* Configure CAN1 RX pin */
GPIO_PinAFConfig(GPIOA,GPIO_PINSOURCE11,GPIO_AF_9);
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_11;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
GPIO_InitStructure.GPIO_OType = GPIO_OTYPE_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PUPD_PULLUP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure CAN1 TX pin */
GPIO_PinAFConfig(GPIOA,GPIO_PINSOURCE12,GPIO_AF_9);
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_12;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
GPIO_InitStructure.GPIO_OType = GPIO_OTYPE_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PUPD_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
配置
void CAN_Configuration(void)
{
CAN_InitPara CAN_InitStructure;
CAN_FilterInitPara CAN_FilterInitStructure;
RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_CAN1, ENABLE);
CAN_DeInit(CAN1);
CAN_StructInit(&CAN_InitStructure);
/* CAN1 and CAN2 cell init */
CAN_InitStructure.CAN_TTC = DISABLE;
CAN_InitStructure.CAN_ABOR = DISABLE;
CAN_InitStructure.CAN_AWK = DISABLE;
CAN_InitStructure.CAN_ARD = DISABLE;
CAN_InitStructure.CAN_RFOD = DISABLE;
CAN_InitStructure.CAN_TFO = ENABLE;
CAN_InitStructure.CAN_Mode = CAN_MODE_LOOPBACK;
CAN_InitStructure.CAN_SJW = CAN_SJW_4TQ; //4
CAN_InitStructure.CAN_BS1 = CAN_BS1_10TQ; //14
CAN_InitStructure.CAN_BS2 = CAN_BS2_6TQ; //2
CAN_InitStructure.CAN_Prescaler =4;
CAN_Init(CAN1, &CAN_InitStructure);
// CAN1 filter init
CAN_FilterInitStructure.CAN_FilterNumber = 1;
CAN_FilterInitStructure.CAN_FilterMode = CAN_FILTERMODE_MASK;
CAN_FilterInitStructure.CAN_FilterScale = CAN_FILTERSCALE_32BIT;
CAN_FilterInitStructure.CAN_FilterListHigh = (((uint32_t)0x5a5<<21)&0xffff0000)>>16;
CAN_FilterInitStructure.CAN_FilterListLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskListHigh = 0xffff;
CAN_FilterInitStructure.CAN_FilterMaskListLow = 0xffff;
CAN_FilterInitStructure.CAN_FilterFIFOAssociation = CAN_FIFO0;
CAN_FilterInitStructure.CAN_FilterWork = ENABLE;//DISABLE;//
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_INTConfig(CAN1, CAN_INT_RFNE0, ENABLE); //·Ç¿ÕÖжÏ
}
中断分配
/* Enable CAN1 RX0 interrupt IRQ channel */
NVIC_InitStructure.NVIC_IRQ = CAN1_RX0_IRQn;
NVIC_InitStructure.NVIC_IRQPreemptPriority = 0;
NVIC_InitStructure.NVIC_IRQSubPriority = 2;
NVIC_InitStructure.NVIC_IRQEnable = ENABLE;
NVIC_Init(&NVIC_InitStructure);
void CAN1_RX0_IRQHandler(void)
{
CAN_Receive(CAN1, CAN_FIFO0, &RxMessage);
。。。。
}
|