2009-10-28 09:16 AM
CAN normal mode
2011-05-17 04:04 AM
I have a problem in setting up CAN in normal mode. It is working well while in LoopBack, but not working when i change it to Normal mode.
My settings are given below..Please Let me know if anyone detect anything missing from this.. /* RCC setup */ RCC_DeInit(); /* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON); /* Wait till HSE is ready */ HSEStartUpStatus = RCC_WaitForHSEStartUp(); if(HSEStartUpStatus == SUCCESS) { /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK/2 */ RCC_PCLK1Config(RCC_HCLK_Div1); /* Enable Prefetch Buffer */ FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); /* Select HSE as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE); /* Wait till HSE is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x04) { } } /* GPIOA and GPIOC clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_USART1 | RCC_APB2Periph_AFIO, ENABLE); /* CAN Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE); /* GPIO setup */ GPIO_PinRemapConfig(GPIO_Remap1_CAN, ENABLE);// for remapping to PB8 & PB9 /* Configure CAN pin: RX */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Configure CAN pin: TX */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); /* NVIC interrupt setup*/ NVIC_InitStructure.NVIC_IRQChannel=USB_LP_CAN_RX0_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* CAN setup and Transmit*/ // CAN register init CAN_DeInit(); CAN_StructInit(&CAN_InitStructure); // CAN filter init CAN_FilterInitStructure.CAN_FilterNumber=1; CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask; CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit; CAN_FilterInitStructure.CAN_FilterIdHigh=0x0000; CAN_FilterInitStructure.CAN_FilterIdLow=0x0000; CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0x0000; CAN_FilterInitStructure.CAN_FilterMaskIdLow=0x0000; CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_FIFO0; CAN_FilterInitStructure.CAN_FilterActivation=ENABLE; CAN_FilterInit(&CAN_FilterInitStructure); // CAN cell init CAN_InitStructure.CAN_TTCM=DISABLE; CAN_InitStructure.CAN_ABOM=DISABLE; CAN_InitStructure.CAN_AWUM=DISABLE; CAN_InitStructure.CAN_NART=DISABLE; CAN_InitStructure.CAN_RFLM=DISABLE; CAN_InitStructure.CAN_TXFP=DISABLE; CAN_InitStructure.CAN_Mode=CAN_Mode_Normal;//CAN_Mode_LoopBack;// CAN_InitStructure.CAN_SJW=CAN_SJW_1tq; CAN_InitStructure.CAN_BS1=CAN_BS1_8tq; CAN_InitStructure.CAN_BS2=CAN_BS2_7tq; CAN_InitStructure.CAN_Prescaler=2;// 8 MHz - (8/16)/250000 status=CAN_Init(&CAN_InitStructure); if (status==CANINITOK) { /* CAN FIFO0 message pending interrupt enable */ CAN_ITConfig(CAN_IT_FMP0, ENABLE); /* transmit 1 message */ TxMessage.StdId= 0x63A; TxMessage.ExtId=0x200A; TxMessage.IDE=CAN_ID_EXT; TxMessage.RTR=CAN_RTR_DATA; TxMessage.DLC=3; TxMessage.Data[0]=0x00; TxMessage.Data[1]=0xEE; TxMessage.Data[2]=0x00; ret=CAN_Transmit(&TxMessage); } /* CAN Receive */ void USB_LP_CAN_RX0_IRQHandler(void) { CanRxMsg RxMessage; RxMessage.StdId=0x00; RxMessage.ExtId=0x00; RxMessage.IDE=0; RxMessage.DLC=0; RxMessage.FMI=0; RxMessage.Data[0]=0x00; RxMessage.Data[1]=0x00; RxMessage.Data[2]=0x00; CAN_Receive(CAN_FIFO0, &RxMessage); }2011-05-17 04:04 AM
I have similar problem, did you manage to get your code work?