/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
uint32_t main(void)
{
  RST_CLK_DeInit();
  /* Select HSI/2 as CPU_CLK source*/
  RST_CLK_CPU_PLLconfig (RST_CLK_CPU_PLLsrcHSEdiv2,0);
  /* Periph clocks enable */
  RST_CLK_PCLKcmd((RST_CLK_PCLK_RST_CLK | RST_CLK_PCLK_CAN1),ENABLE);
  RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTD,ENABLE);

  /* Reset PORTD settings */
  PORT_DeInit(MDR_PORTD);

  /* Configure PORTD pins 10,11 for output to switch LED on/off */
  PORT_InitStructure.PORT_FUNC  = PORT_FUNC_PORT;
  PORT_InitStructure.PORT_Pin   = PORT_Pin_10 | PORT_Pin_11;
  PORT_InitStructure.PORT_OE    = PORT_OE_OUT;
  PORT_InitStructure.PORT_MODE  = PORT_MODE_DIGITAL;
  PORT_InitStructure.PORT_SPEED = PORT_SPEED_SLOW;
  PORT_Init(MDR_PORTD, &PORT_InitStructure);

/* CAN transmit at 500Kb/s and receive by interrupt in loopback mode */
  TestRx = CAN_Interrupt();
  if (TestRx == FAILED)
  {
    /* Turn on led LED2 */
    LEDOn(LED2);
  }
  else
  {
    /* Turn on led LED1 */
    LEDOn(LED1);
  }

  while(1);
}
Esempio n. 2
0
/*
 * 函数名:CAN_Test
 * 描述  :CAN 回环模式跟中断模式测试
 * 输入  :无
 * 输出  : 无	 
 * 调用  :外部调用
 */
void USER_CAN_Test(void)
{
	/* CAN transmit at 100Kb/s and receive by polling in loopback mode */
	TestRx = CAN_Polling();
	
	if (TestRx == FAILED)
	{    
		LED1( OFF );	// LED1 OFF 		
	}
	else
	{    
		LED1( ON );	  // LED1 ON;		
	}
	
	/* CAN transmit at 500Kb/s and receive by interrupt in loopback mode */
	TestRx = CAN_Interrupt();
	
	if (TestRx == FAILED)
	{    
		LED2( OFF );	// LED2 OFF;		 
	}
	else
	{   
		LED2( ON );	  // LED2 ON;		
	}
}
Esempio n. 3
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */     
       
  /* CAN1 Periph clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);

  /* NVIC Configuration */
  NVIC_Configuration();
  
  /* Configures LED 1..4 */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);
  
  /*Turns selected LED Off */  
  STM_EVAL_LEDOff(LED1);
  STM_EVAL_LEDOff(LED2);
  STM_EVAL_LEDOff(LED3);
  STM_EVAL_LEDOff(LED4);
  
  /* CAN transmit at 100Kb/s and receive by polling in loopback mode */
  TestRx = CAN_Polling();

  if (TestRx == FAILED)
  {
    /* Turn on led LD3 */
    STM_EVAL_LEDOn(LED3);
  }
  else
  {
    /* Turn on led LD1 */
    STM_EVAL_LEDOn(LED1);
  }

  /* CAN transmit at 500Kb/s and receive by interrupt in loopback mode */
  TestRx = CAN_Interrupt();

  if (TestRx == FAILED)
  {
    /* Turn on led LD4 */
    STM_EVAL_LEDOn(LED4);
  }
  else
  {
    /* Turn on led LD2 */
    STM_EVAL_LEDOn(LED2);
  }

  /* Infinite loop */
  while (1)
  {
  }
}