TestRx = CAN_Polling(); // CAN transmit at 100Kb/s and receive by polling in loopback mode
if (TestRx == FAILED) { GPIO_SetBits(GPIOC, GPIO_Pin_4); // Turn on led connected to PC.08 pin (LD3) } else { GPIO_SetBits(GPIOC, GPIO_Pin_6); // Turn on led connected to PC.06 pin (LD1) }
while (1) { } }
/******************************************************************************* * Function Name : RCC_Configuration * Description : Configures the different system clocks. * Input : None * Output : None * Return : None *******************************************************************************/ void RCC_Configuration(void) { RCC_DeInit(); /* RCC system reset(for debug purpose) */ RCC_HSEConfig(RCC_HSE_ON); /* Enable HSE */ HSEStartUpStatus = RCC_WaitForHSEStartUp(); /* Wait till HSE is ready */ if(HSEStartUpStatus == SUCCESS) { FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); /* Enable Prefetch Buffer */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* HCLK = SYSCLK */ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK1Config(RCC_HCLK_Div2); /* PCLK1 = HCLK/2 */ RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE); /* Select HSE as system clock source */ while(RCC_GetSYSCLKSource() != 0x04) { // Wait till HSE is used as system clock source } }
/******************************************************************************* * Function Name : NVIC_Configuration * Description : Configures the NVIC and Vector Table base address. * Input : None * Output : None * Return : None *******************************************************************************/ void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); /* Set the Vector Table base location at 0x20000000 */ #else /* VECT_TAB_FLASH */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); /* Set the Vector Table base location at 0x08000000 */ #endif
/******************************************************************************* * Function Name : CAN_Polling * Description : Configures the CAN and transmit and receive by polling * Input : None * Output : None * Return : PASSED if the reception is well done, FAILED in other case *******************************************************************************/ TestStatus CAN_Polling(void) { u8 Error;
/******************************************************************************* * Function Name : CAN_Configuration * Description : Configures the CAN * Input : None * Output : None * Return : PASSED if the configration is well done, FAILED in other case *******************************************************************************/ TestStatus CAN_Configuration(void) { u8 Error; CAN_InitTypeDef CAN_InitStructure; CAN_FilterInitTypeDef CAN_FilterInitStructure;
CAN_DeInit(); // CAN register init CAN_StructInit(&CAN_InitStructure);
/******************************************************************************* * Function Name : main * Description : Main program * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { CanRxMsg RxMessage; u32 i = 0;
if (TestRx == FAILED) { GPIO_SetBits(GPIOC, GPIO_Pin_4); // Turn on led connected to PC.08 pin (LD3) } else { GPIO_SetBits(GPIOC, GPIO_Pin_6); // Turn on led connected to PC.06 pin (LD1) } } } }