int main(void) { /* GPIOD Periph clock enable */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); /* Configures the leds and the read/write pin on D1 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15 | USART6_ENABLE_PIN | USART6_DISABLE_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOD, &GPIO_InitStructure); init_USART6(BOTTOM_MOTOR_BAUD); // initialize USART6 baud rate init_USART2(TOP_BOTTOM_BAUD); // initialize USART2 baud rate GPIO_SetBits(USART6_ENABLE_PORT, USART6_ENABLE_PIN); //Turns the read/write pin for rs485 to write mode Delay(0xFFF); //Delays to give the read/write pin time to initialize while (1){ //Reads the top packet, converts the top packet to motor packets, and then sends the motor packets to the motor controllers if(handleTopPacket()) //If the read top packet function was successful, go within the if statement { GPIO_ResetBits(GPIOD, GPIO_Pin_15); //Increments how many times the motor packets have been sent pollCounter++; //Waits for twenty packets to be sent to the motors before polling a motor. if(pollCounter > 20) { GPIO_SetBits(GPIOD, GPIO_Pin_14); //Sends a packet to poll the motor at pollAddress pollMotor(pollAddress); if(!readSlavePacket()) //If we cannot read the packet { //TODO } //Add the fault data information to the packet we are sending back to the battle station //Increments through the addresses and goes back to address one after eight time pollAddress++; //Changes which motor will be polled next if(pollAddress == 9) pollAddress = 1; pollCounter = 0; //Resets the poll counter } } GPIO_ResetBits(GPIOD, GPIO_Pin_12); //Turns off the led GPIO_ResetBits(GPIOD, GPIO_Pin_14); } }
int main(void) { /*!< At this stage the microcontroller clock setting is already configured to 144 MHz, this is done through SystemInit() function which is called from startup file (startup_stm32f4xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ init_USART6(115200); /*Initialize LCD and Leds */ printf("LCD_LED_Init\r\n"); LCD_LED_Init(); /* configure ethernet (GPIOs, clocks, MAC, DMA) */ printf("ETH_BSP_Config\r\n"); ETH_BSP_Config(); /* Initilaize the LwIP stack */ printf("LwIP_Init\r\n"); LwIP_Init(); /* Initialize webserver demo */ printf("http_server_socket_init\r\n"); http_server_socket_init(); #ifdef USE_DHCP /* Start DHCPClient */ printf("DHCP task create\r\n"); xTaskCreate(LwIP_DHCP_task, "DHCPClient", configMINIMAL_STACK_SIZE * 2, NULL,DHCP_TASK_PRIO, NULL); #endif /* Start toogleLed4 task : Toggle LED4 every 250ms */ printf("xTaskCreate(ToggleLed4)\r\n"); xTaskCreate(ToggleLed4, "LED4", configMINIMAL_STACK_SIZE, NULL, LED_TASK_PRIO, NULL); /* Start scheduler */ printf("Start vTaskStartScheduler\r\n"); vTaskStartScheduler(); /* We should never get here as control is now taken by the scheduler */ for ( ;; ); }