Пример #1
0
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);		
    }

  }
Пример #2
0
int main(void) {


  init_pins();	//Initializes the leds and the read write enabler pins as outputs

  init_USART1(BOTTOM_MOTOR_BAUD); 	// initialize USART1 baud rate
  init_USART2(TOP_BOTTOM_BAUD);	// initialize USART2 baud rate

  GPIO_SetBits(GPIOD, READ_WRITE_ENABLER);	//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, BLUE_LED);
			
			//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 > PACKETS_SENT_BEFORE_POLLED)
			{
						GPIO_SetBits(GPIOD, RED_LED);
				
				//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, GREED_LED);	//Turns off the led 
		GPIO_ResetBits(GPIOD, RED_LED);		
    }

  }
Пример #3
0
Файл: serial.c Проект: dbry/eDog
void Dbg_init (void)
{
    init_USART2 (230400); // initialize USART2 @ 230400 baud
}