示例#1
0
void main()
{

    RCC_ClocksTypeDef RCC_Clocks;

    RCC_GetClocksFreq(&RCC_Clocks);

    SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);

    LED_Config();
    LWIP_Config();
    UDP_Config();
    CAN_Config();
    TIM7_Config(PERIOD);

    while(1)
    {
        if(ETH_CheckFrameReceived())
        {
            LwIP_Pkt_Handle();
        }

        LwIP_Periodic_Handle(LocalTime);

        if(rew_status != 0) ReSendUdpData();
    }

}
示例#2
0
/* 
 * 函数名:main
 * 描述  : "主机"的主函数
 * 输入  :无
 * 输出  : 无
 */
int main(void)
{
	/*初始化串口模块*/
 	USART1_Config();
 			
 	/* 配置CAN模块 */
	CAN_Config();  

	printf( "\r\n***** 这是一个双CAN通讯实验******** \r\n");
	printf( "\r\n 这是 “主机端” 的反馈信息: \r\n");

	/*设置要通过CAN发送的信息*/
	 CAN_SetMsg();

	 printf("\r\n将要发送的报文内容为:\r\n");
	 printf("\r\n 扩展ID号ExtId:0x%x",TxMessage.ExtId);
	 printf("\r\n 数据段的内容:Data[0]=0x%x ,Data[1]=0x%x \r\n",TxMessage.Data[0],TxMessage.Data[1]);
	 			
	 /*发送消息 “ABCD”**/
	 CAN_Transmit(CAN1, &TxMessage);

	 		
	while( flag == 0xff );					//flag =0 ,success

	printf( "\r\n 成功接收到“从机”返回的数据\r\n ");	
	printf("\r\n 接收到的报文为:\r\n"); 
	printf("\r\n 扩展ID号ExtId:0x%x",RxMessage.ExtId);	 
	printf("\r\n 数据段的内容:Data[0]= 0x%x ,Data[1]=0x%x \r\n",RxMessage.Data[0],RxMessage.Data[1]);

	while(1);
	
}
示例#3
0
文件: main.c 项目: kitaev/can
void main(void) {
    GPIO_Config();
    CAN_Config();
    GPIO_SetBits(GPIOA, GPIO_Pin_8);

    while(1) {
        PWR_EnterSleepMode(PWR_SLEEPEntry_WFI);
    }
}
/**
  * @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
  */

  /* Configures LED 1..4 */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDOff(LED1);
  DFLASH

  /* NVIC configuration */
  NVIC_Config();
  RCC_Configuration();
  GPIO_Configuration();

  USART_InitStructure.USART_BaudRate = 19200;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_No;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  USART_Init(USART1, &USART_InitStructure);
  USART_Cmd(USART1, ENABLE);
  Debug("\nZZZZZZZZZZZZZZzzzzzzzzzzzzzzzzzz!!!!!!!!!!!!!!!!!!!!");

  DFLASH

  /* CAN configuration */
  CAN_Config();
  Delay();
  CAN_ITConfig(CANx, CAN_IT_FMP0, ENABLE);

  /* Infinite loop */
  short int x,led;

  while(1) {
    x++;
    if (x == 0) {
      if (led) {
          STM_EVAL_LEDOn(LED1);
          Delay();
      }
      else {
          STM_EVAL_LEDOff(LED1);
          TxMessage.Data[0]++;
          CAN_Transmit(CANx, &TxMessage);
          Delay();
      }
      led ^= 1;
    }
  }//END While
}//END main
示例#5
0
//fungsi utama
int main (void) {
	
	//inisialisasi HAL (Hardware Abstraction Layer)
	halInit();
	
	//inisialisasi kernel
	chSysInit();
	
	Adc_Init();
	
	process_running();
	
	//inisialisasi CAN
	CAN_Config();
	
	// serial
	sdStart(&SD2,NULL);  
    palSetPadMode(GPIOB,3, PAL_MODE_ALTERNATE(7)); //TX
    palSetPadMode(GPIOB,4, PAL_MODE_ALTERNATE(7)); //RX

    sdStart(&SD1,NULL);
    palSetPadMode(GPIOA,9, PAL_MODE_ALTERNATE(7)); //TX
    palSetPadMode(GPIOA,10, PAL_MODE_ALTERNATE(7)); //RX

    sdStart(&SD3,NULL);
    palSetPadMode(GPIOB,10, PAL_MODE_ALTERNATE(7)); //TX
    palSetPadMode(GPIOE,15, PAL_MODE_ALTERNATE(7)); //RX
    
	//inisialisasi USB
	sduObjectInit(&SDU1);
    sduStart(&SDU1, &serusbcfg);
    
    //aktifasi USB
    usbDisconnectBus(serusbcfg.usbp);
    chThdSleepMilliseconds(200);
    usbStart(serusbcfg.usbp, &usbcfg);
    usbConnectBus(serusbcfg.usbp);
	
	//thread 1
	chThdCreateStatic(waBacavolt, sizeof(waBacavolt), NORMALPRIO, Bacavolt, NULL);
	chThdCreateStatic(waBacacurrent, sizeof(waBacacurrent), NORMALPRIO, Bacacurrent, NULL);
	chThdCreateStatic(waThreadBMS, sizeof(waThreadBMS), NORMALPRIO, ThreadBMS, NULL);
	//chThdCreateStatic(waThreadkirimjoule, sizeof(waThreadkirimjoule), NORMALPRIO, Threadkirimjoule, NULL);
	//chThdCreateStatic(waThreadkirimjoule2, sizeof(waThreadkirimjoule2), NORMALPRIO, Threadkirimjoule2, NULL);


while(TRUE) {
	kirim_data_usart1();
    chprintf((BaseSequentialStream *)&SD1,"%d,%f,%d,%d,%f,%f,%d,%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%d,%d,%d,%d \n",avgtemp,packsoc,packDCL,packCCL,lowvoltcell,highvoltcell,hightemp,lowtemp,packcurrent,packvolt,amphours,supply12v, deltacellvolt,avgcellvolt,mppt1_v,mppt2_v,mppt3_v,mppt4_v,mppt5_v,mppt6_v,mppt7_v,mppt8_v,mppt9_v,mppt10_v,mppt11_v,mppt12_v,mppt13_v,mppt15_v,mppt16_v, mppt1_i, mppt2_i, mppt3_i, mppt4_i, mppt5_i, mppt6_i, mppt7_i,mppt8_i, mppt9_i, mppt10_i, mppt11_i, mppt12_i, mppt13_i, mppt14_i, mppt15_i,current1,current2,current3,voltage1,voltage2,voltage3,milidetik,detik,menit,jam);
    //chprintf((BaseSequentialStream *)&SDU1,"%d,%f,%d,%d,%f,%f,%d,%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f \n",avgtemp,packsoc,packDCL,packCCL,lowvoltcell,highvoltcell,hightemp,lowtemp,packcurrent,packvolt,amphours,supply12v, deltacellvolt,avgcellvolt,mppt1_v,mppt2_v,mppt3_v,mppt4_v,mppt5_v,mppt6_v,mppt7_v,mppt8_v,mppt9_v,mppt10_v,mppt11_v,mppt12_v,mppt13_v,mppt15_v,mppt16_v, mppt1_i, mppt2_i, mppt3_i, mppt4_i, mppt5_i, mppt6_i, mppt7_i,mppt8_i, mppt9_i, mppt10_i, mppt11_i, mppt12_i, mppt13_i, mppt14_i, mppt15_i);
    //chprintf((BaseSequentialStream *)&SDU1,"%x %x %x %x %x %x %x %x \n",RxMessage33.StdId, RxMessage44.StdId, RxMessage55.StdId, RxMessage66.StdId, RxMessage77.StdId, RxMessage88.StdId, RxMessage99.StdId, RxMessage11.StdId); 
    //chprintf((BaseSequentialStream *)&SD1,"tes \n");
    chThdSleepMilliseconds(500);
}
   return 0 ;
}	
示例#6
0
void init(void){
	GPIO_init();
	USART_init();
	CAN_Config();
	SysTick_init();
	accelerometer_init();
	ADC_init();
	TIM4_init();
	TIM2_init();
}
示例#7
0
文件: main.c 项目: Axis-Labs/STM32
/**
  * @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
     */     
       
  /* NVIC configuration */
  NVIC_Config();

  /* Configures LED 1..4 */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);
  
  /* Configure Push button key */
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); 
   
  /* CAN configuration */
  CAN_Config();
  
  CAN_ITConfig(CANx, CAN_IT_FMP0, ENABLE);

  /* turn off all leds*/
  STM_EVAL_LEDOff(LED1);
  STM_EVAL_LEDOff(LED2);
  STM_EVAL_LEDOff(LED3);
  STM_EVAL_LEDOff(LED4);
 
  /* Infinite loop */
  while(1)
  {
    while(STM_EVAL_PBGetState(BUTTON_KEY) == KEY_PRESSED)
    {
      if(KeyNumber == 0x4) 
      {
        KeyNumber = 0x00;
      }
      else
      {
        LED_Display(++KeyNumber);
        TxMessage.Data[0] = KeyNumber;
        CAN_Transmit(CANx, &TxMessage);
        Delay();
        
        while(STM_EVAL_PBGetState(BUTTON_KEY) != KEY_NOT_PRESSED)
        {
        }
      }
    }
  }
}
示例#8
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{

    USART_Configuration();
    printf("\r\n****************************************************************\r\n");
    printf("CAN-Bus Test \r\n");
    printf("CAN-Bus Speed 100kHz \r\n");

    CAN_Config();
    NVIC_Config();
    Open207_LEDInit();
    /* Infinite loop */
    while (1)
    {
        if( CanFlag == ENABLE )
        {
            CanFlag = DISABLE;
            printf("CAN Receive Data \r\n");
            printf("CAN ID %x \r\n",CAN_ID);
            printf("CAN_DATA0 %x \r\n",CAN_DATA0);
            printf("CAN_DATA1 %x \r\n",CAN_DATA1);
            printf("CAN_DATA2 %x \r\n",CAN_DATA2);
            printf("CAN_DATA3 %x \r\n",CAN_DATA3);
            printf("CAN_DATA4 %x \r\n",CAN_DATA4);
            printf("CAN_DATA5 %x \r\n",CAN_DATA5);
            printf("CAN_DATA6 %x \r\n",CAN_DATA6);
            printf("CAN_DATA7 %x \r\n",CAN_DATA7);
        }

        CanWriteData(0xA5A5);

        if( Display )
        {
            /*====LED-ON=======*/
            GPIO_SetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED1);
            GPIO_SetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED2);
            GPIO_SetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED3);
            GPIO_SetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED4);
        }
        else
        {
            /*====LED-OFF=======*/
            GPIO_ResetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED1);
            GPIO_ResetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED2);
            GPIO_ResetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED3);
            GPIO_ResetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED4);
        }
        Display = ~Display;
        Delay();  /* delay 200ms */
    }
}
示例#9
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
       files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s)
       before to branch to application main. 
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */     
       
  /* NVIC configuration */
  NVIC_Config();

   /* Initialize LEDs mounted on EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);
  
  /* Initialize Key Button mounted on EVAL board */
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); 
   
  /* CAN configuration */
  CAN_Config();
  
  while(1)
  {
    while(STM_EVAL_PBGetState(BUTTON_KEY) == KEY_PRESSED)
    {
      if(ubKeyNumber == 0x4) 
      {
        ubKeyNumber = 0x00;
      }
      else
      {
        LED_Display(++ubKeyNumber);
        TxMessage.Data[0] = ubKeyNumber;
        CAN_Transmit(CANx, &TxMessage);
        /* Wait until one of the mailboxes is empty */
        while((CAN_GetFlagStatus(CANx, CAN_FLAG_RQCP0) !=RESET) || \
              (CAN_GetFlagStatus(CANx, CAN_FLAG_RQCP1) !=RESET) || \
              (CAN_GetFlagStatus(CANx, CAN_FLAG_RQCP2) !=RESET));
        
        while(STM_EVAL_PBGetState(BUTTON_KEY) != KEY_NOT_PRESSED)
        {
        }
      }
    }
  }
}
示例#10
0
文件: main.c 项目: jiesse/time-meter
/**
  * @brief  Main program
  * @param  None
  * @retval : None
  */
int main(void)
{
 uint32_t i=0;
  
  /* System clocks configuration ---------------------------------------------*/
  RCC_Configuration();

  /* NVIC configuration ------------------------------------------------------*/
  NVIC_Configuration();

  /* GPIO configuration ------------------------------------------------------*/
  GPIO_Configuration();

  /* CAN configuration */
  CAN_Config();

  CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);

  /* turn off all leds*/
  LED_Display(5);

  /* Infinite loop*/
  while(1)
  {
    while(Key_Status()== Key_Pressed)
     {
	if(Key_Pressed_Number==0x4) 
        {
	   Key_Pressed_Number = 0x00;
        }
	else
        {
       	  LED_Display(++Key_Pressed_Number);
          TxMessage.Data[0] = Key_Pressed_Number;
          CAN_Transmit(CAN1, &TxMessage);
	  for(i=0;i<0xFFFF;i++);
          while(Key_Status()!= Key_NoPressed);
        }
     }
  }
}
示例#11
0
/**
  * @brief  Setup STM32 system (clocks, Ethernet, GPIO, NVIC) and STM3210C-EVAL resources.
  * @param  None
  * @retval None
  */
void System_Setup(void)
{
//	GPIO_InitTypeDef  GPIO_InitStructure1;
  RCC_ClocksTypeDef RCC_Clocks;
	
  /* Setup STM32 clock, PLL and Flash configuration) */
  SystemInit();

  /* Enable USART2 clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);


  /* Enable ETHERNET clock  */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ETH_MAC | RCC_AHBPeriph_ETH_MAC_Tx |
                        RCC_AHBPeriph_ETH_MAC_Rx, ENABLE);

  /* Enable GPIOs and ADC1 clocks */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC |
                         RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO |
						 RCC_APB2Periph_ADC1, ENABLE);

  /* NVIC configuration */
  NVIC_Configuration();  
	
	
  /* ADC configuration */
  ADC_Configuration();

  /* Configure the GPIO ports */
  GPIO_Configuration();

//  /* Initialize the STM3210C-EVAL's LCD */
//  STM3210C_LCD_Init();
	
	CAN_NVIC_Config();
	CAN_Config();

//  /* Initialize STM3210C-EVAL's LEDs */
//  STM_EVAL_LEDInit(LED1);
//  STM_EVAL_LEDInit(LED2);
//  STM_EVAL_LEDInit(LED3);
//  STM_EVAL_LEDInit(LED4);

//  /* Turn on leds available on STM3210X-EVAL */
//  STM_EVAL_LEDOn(LED1);
//  STM_EVAL_LEDOn(LED2);
//  STM_EVAL_LEDOn(LED3);
//  STM_EVAL_LEDOn(LED4);
  
//  /* Enable the GPIO_LED Clock */
//  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

//  /* Configure the GPIO_LED pin */
//  GPIO_InitStructure1.GPIO_Pin = GPIO_Pin_9;
//  GPIO_InitStructure1.GPIO_Mode = GPIO_Mode_Out_PP; 
//  GPIO_InitStructure1.GPIO_Speed = GPIO_Speed_50MHz;

//  GPIO_Init(GPIOB, &GPIO_InitStructure1);

  /* Clear the LCD */
  LCD_Clear(Blue);

  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);

  /* Set the LCD Text Color */
  LCD_SetTextColor(White);

  /* Display message on the LCD*/
  LCD_DisplayStringLine(Line0, MESSAGE1);
  LCD_DisplayStringLine(Line1, MESSAGE2);
  LCD_DisplayStringLine(Line2, MESSAGE3);
  LCD_DisplayStringLine(Line3, MESSAGE4);

  /* Configure the Ethernet peripheral */
  Ethernet_Configuration();

  /* SystTick configuration: an interrupt every 10ms */
  RCC_GetClocksFreq(&RCC_Clocks);
  SysTick_Config(RCC_Clocks.SYSCLK_Frequency / 100);

  /* Update the SysTick IRQ priority should be higher than the Ethernet IRQ */
  /* The Localtime should be updated during the Ethernet packets processing */
  NVIC_SetPriority (SysTick_IRQn, 1);
//	NVIC_SetPriority (CAN2_RX0_IRQn, 1);
  
  /* Configure the Key button */ 
  //STM_EVAL_PBInit(Button_KEY, Mode_GPIO);
}
示例#12
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();
  
  /* Configure the system clock to 180 MHz */
  SystemClock_Config();
  
  /* Configure LED1, LED2, LED3 and LED4 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED2);
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);
  
  /* Configure Key Button */ 
  BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO);
  
  /*##-1- Configure the CAN peripheral #######################################*/
  CAN_Config();
  
  /*##-2- Start the Reception process and enable reception interrupt #########*/
  if(HAL_CAN_Receive_IT(&CanHandle, CAN_FIFO0) != HAL_OK)
  {
    /* Reception Error */
    Error_Handler();
  }
  
  /* Infinite loop */
  while(1)
  {
    while(BSP_PB_GetState(BUTTON_KEY) == KEY_PRESSED)
    {
      if(ubKeyNumber == 0x4) 
      {
        ubKeyNumber = 0x00;
      }
      else
      {
        LED_Display(++ubKeyNumber);
        
        /* Set the data to be transmitted */
        CanHandle.pTxMsg->Data[0] = ubKeyNumber;
        CanHandle.pTxMsg->Data[1] = 0xAD;
        
        /*##-3- Start the Transmission process ###############################*/
        if(HAL_CAN_Transmit(&CanHandle, 10) != HAL_OK)
        {
          /* Transmition Error */
          Error_Handler();
        }
        HAL_Delay(10);
        
        while(BSP_PB_GetState(BUTTON_KEY) != KEY_NOT_PRESSED)
        {
        }
      }
    }
  } 
}
示例#13
0
文件: main.c 项目: Axis-Labs/STM32
/**
  * @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
     */
        
  /* NVIC configuration */
  NVIC_Config();

  /* Configures LED 1..4 */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

  /* LCD Initialization */
  STM3210C_LCD_Init();
  LCD_Clear(LCD_COLOR_WHITE);

  /* Set the LCD Back Color */
  LCD_SetBackColor(LCD_COLOR_RED);
  /* Set the LCD Text Color */
  LCD_SetTextColor(LCD_COLOR_GREEN);
  
  LCD_DisplayStringLine(LCD_LINE_0, "   STM3210C-EVAL    ");
  LCD_DisplayStringLine(LCD_LINE_1, " STM32F10x Dual CAN ");
  LCD_DisplayStringLine(LCD_LINE_2, "To start Press on:  ");
  LCD_DisplayStringLine(LCD_LINE_3, "Key or Tamper Button");

  /* Set the LCD Back Color */
  LCD_SetBackColor(LCD_COLOR_BLUE);

#if CAN_BAUDRATE == 1000 /* 1MBps */
  LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 1MBps   ");
#elif CAN_BAUDRATE == 500 /* 500KBps */
  LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 500kBps   ");
#elif CAN_BAUDRATE == 250 /* 250KBps */
  LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 250kBps   ");
#elif CAN_BAUDRATE == 125 /* 125KBps */
  LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 125kBps   ");
#elif  CAN_BAUDRATE == 100 /* 100KBps */
  LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 100kBps   ");
#elif  CAN_BAUDRATE == 50 /* 50KBps */
  LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 50kBps   ");
#elif  CAN_BAUDRATE == 20 /* 20KBps */
  LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 20kBps   ");
#elif  CAN_BAUDRATE == 10 /* 10KBps */
  LCD_DisplayStringLine(LCD_LINE_4, " BAUDRATE = 10kBps   ");
#endif
  /* Set the LCD Text Color */
  LCD_SetTextColor(LCD_COLOR_WHITE);   
    
  /* Configure BUTTON_KEY */
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); 
  
  /* Configure BUTTON_TAMPER */
  STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_GPIO); 
   
  /* CANs configuration */
  CAN_Config();

  /* IT Configuration for CAN1 */  
  CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);

  /* IT Configuration for CAN2 */  
  CAN_ITConfig(CAN2, CAN_IT_FMP0, ENABLE);

  /* turn off all leds*/
  STM_EVAL_LEDOff(LED1);
  STM_EVAL_LEDOff(LED2);
  STM_EVAL_LEDOff(LED3);
  STM_EVAL_LEDOff(LED4);
 
  /* Infinite loop */
  while(1)
  {
    if(STM_EVAL_PBGetState(BUTTON_KEY)== RESET)
    {
      /* Turn On LED1 */
      LED_Display(0x01);
      TxMessage.Data[0] = 0x55;
      CAN_Transmit(CAN1, &TxMessage);

      /* Loop while KEY button is pressed */
      while(STM_EVAL_PBGetState(BUTTON_KEY)== RESET)
      {
      }
    }
    if(STM_EVAL_PBGetState(BUTTON_TAMPER)== RESET)
    {
      /* Turn On LED2 */
      LED_Display(0x2);
      TxMessage.Data[0] = 0xAA;
      CAN_Transmit(CAN2, &TxMessage);

      /* Loop while TAMPER button is pressed */
      while(STM_EVAL_PBGetState(BUTTON_TAMPER)== RESET)
      {
      }
    }
  }
}
示例#14
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_stm32f0xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f0xx.c file
     */
  
  /* Initialize the LCD */
  STM32072B_LCD_Init();      
  
  /* Clear the LCD */
  LCD_Clear(LCD_COLOR_WHITE);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(White);
  
  /* Displays MESSAGE1 on line 0 */
  LCD_DisplayStringLine(LINE(0), (uint8_t *)MESSAGE1);
  
  /* Set the LCD Text size */
  LCD_SetFont(&Font8x12);
  
  /* Display */
  LCD_DisplayStringLine(LINE(0x13), "CAN CAN_DualFIFO using FIFO 0 and FIFO 1 ");
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(White);
  /* Set the LCD Text Color */
  LCD_SetTextColor(Blue);
  /* Set the LCD Text size */
  LCD_SetFont(&Font12x12);
  
  /* Display Messages on the the LCD */  
  LCD_DisplayStringLine(LINE(0x7), (uint8_t *)MESSAGE2);
  LCD_DisplayStringLine(LINE(0x8), (uint8_t *)MESSAGE3);
                        
  /* Set the LCD Text size */
  LCD_SetFont(&Font16x24);
  
  /* Configures LED 1..4 */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);
  
  /* Configure Push button key */
  STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_EXTI); 
  
  /* Configure Push button sel */
  STM_EVAL_PBInit(BUTTON_SEL, BUTTON_MODE_EXTI); 
   
  /* CAN configuration */
  CAN_Config();
  
  /* Infinite loop */
  while(1)
  {
  }
}
示例#15
0
文件: init.c 项目: Olavhk/usb_can_v01
void init(void){
	GPIO_init();
	USART_init();
	CAN_Config();
	SysTick_init();
}
示例#16
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* Enable the CPU Cache */
  CPU_CACHE_Enable();

  /* STM32F7xx HAL library initialization:
       - Configure the Flash ART accelerator on ITCM interface
       - Systick timer is configured by default as source of time base, but user 
         can eventually implement his proper time base source (a general purpose 
         timer for example or other time source), keeping in mind that Time base 
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
         handled in milliseconds basis.
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();


  /* Configure the system clock to 216 MHz */
  SystemClock_Config();

  /* Since MFX is used, LED init is done after clock config */
  /* Configure LED1, LED2, LED3 and LED4 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED2);
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);
  
  /* Configure Tamper push-button */
  BSP_PB_Init(BUTTON_TAMPER, BUTTON_MODE_GPIO);

  /*##-1- Configure the CAN peripheral #######################################*/
  CAN_Config();

  /*##-2- Start the Reception process and enable reception interrupt #########*/
  if (HAL_CAN_Receive_IT(&CanHandle, CAN_FIFO0) != HAL_OK)
  {
    /* Reception Error */
    Error_Handler();
  }

  /* Infinite loop */
  while (1)
  {
    while (BSP_PB_GetState(BUTTON_TAMPER) == KEY_PRESSED)
    {
      if (ubKeyNumber == 0x4)
      {
        ubKeyNumber = 0x00;
      }
      else
      {
        LED_Display(++ubKeyNumber);
        
        /* Set the data to be transmitted */
        CanHandle.pTxMsg->Data[0] = ubKeyNumber;
        CanHandle.pTxMsg->Data[1] = 0xAD;
        
        /*##-3- Start the Transmission process ###############################*/
        if (HAL_CAN_Transmit(&CanHandle, 10) != HAL_OK)
        {
          /* Transmission Error */
          Error_Handler();
        }
        HAL_Delay(10);
        
        while (BSP_PB_GetState(BUTTON_TAMPER) != KEY_NOT_PRESSED)
        {
        }
      }
    }
  }
}
示例#17
0
void main(void)
{
    CAN_TxStatus_TypeDef status = CAN_TxStatus_Failed;

    /* Transmit Parameters */
    CAN_Id_TypeDef Tx_IDE = CAN_Id_Standard;
    CAN_RTR_TypeDef Tx_RTR = CAN_RTR_Data;
    uint8_t Tx_DLC = 0;
    uint8_t Tx_Data[8] = {0};
    uint32_t Tx_Id = 0;

    /* Clock configuration --------------------------------------*/
    CLK_Config();

    /* GPIO Configuration ---------------------------------------*/
    GPIO_Config();

    /* Configure LCD mounted on STM8-128 EVAL board -------------*/
    LCD_Config();

    /* CAN configuration ----------------------------------------*/
    CAN_Config();

    /* Enable Interrupts*/
    enableInterrupts();

    /* Infinite loop*/
    while(1)
    {
        while(Key_status != Key_NoPressed)
        {

            if(Key_Pressed_Number == 0x0)
            {
                Key_Pressed_Number = 0x03;
            }
            else
            {
                Key_Pressed_Number--;
            }

            /* Sender Display*/
            LED_Display(Key_Pressed_Number);
            LCD_Display(Key_Pressed_Number);
            Delay(TIME);

            /* Transmit Parameters*/
            Tx_Id = 0x321;
            Tx_IDE = CAN_Id_Standard;
            Tx_RTR = CAN_RTR_Data;
            Tx_DLC = 1;
            Tx_Data[0] = Key_Pressed_Number;

            /* Sender send Frame */
            status = CAN_Transmit(Tx_Id,Tx_IDE,Tx_RTR,Tx_DLC,Tx_Data);

            /* while key is not pressed, loop*/
            Key_status= Key_NoPressed;
        }
    }
}
示例#18
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void CAN_FIFOExtension(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f30x.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f30x.c file
     */
  
  /* Initialize the LCD */
  STM32303C_LCD_Init();      
  
  /* Clear the LCD */
  LCD_Clear(LCD_COLOR_WHITE);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(White);
  
  /* Displays MESSAGE1 on line 0 */
  LCD_DisplayStringLine(LINE(0), (uint8_t *)MESSAGE1);
    
  LCD_SetFont(&Font12x12);
  
  /* Display Messages on the the LCD */  
  LCD_DisplayStringLine(LINE(0x3), (uint8_t *)MESSAGE2);
  
  /* Set the LCD Text size */
  LCD_SetFont(&Font16x24);
  
  /* Configure Push button key */
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO); 
     
  /* CAN configuration */
  CAN_Config();
  
  /* Infinite loop */
  while(1)
  {
    while(STM_EVAL_PBGetState(BUTTON_KEY) == KEY_PRESSED)
    { 
      if(KeyNumber == 41) KeyNumber = 0;
      
      Display_TransmittedMsg(KeyNumber);
      
      KeyNumber++;
      
      Delay();
      
      while(STM_EVAL_PBGetState(BUTTON_KEY) != KEY_NOT_PRESSED)
      {
      }
    }
      if (MsgReceived != 0)
        {
            /* Display received the 6 messages on tghe LCD */
            Display_ReceivedMsg();
            MsgReceived = 0;
     
    }
  }
}