예제 #1
0
//Initialize all the peripherals
void init_peripherals(void)
{
	//Hardware modules:
	init_systick_timer();		//SysTick timer
	init_usart1(2000000);		//USART1 (RS-485 #1)
	init_usart6(2000000);		//USART6 (RS-485 #2)
	init_rs485_outputs();
	init_leds();
	init_switches();
	init_dio();					//All inputs by default
	init_adc1();
	init_spi4();				//Plan
	//init_spi5();				//FLASH
	//init_spi6();				//Expansion
	init_i2c1();
	init_imu();
	init_adva_fc_pins();
	init_pwr_out();

	//Software:
	init_master_slave_comm();

	//All RGB LEDs OFF
	LEDR(0); LEDG(0); LEDB(0);

	//Default analog input states:
	set_default_analog();
}
예제 #2
0
int main ( void ) {
	char *rstr = (char*) alloca(sizeof(char) * 128);  //allocate an array of 128 bytes called rstr
	uint8_t cnt=0;                        //counter variable
	for(cnt=0;cnt<128;cnt++) {
		rstr[cnt] = 0;                    //clear out variable 
	}
	init_usart1(51, DB8 | P_N | SB1);     //51 is the ubrr value for 19.2kBaud at 16MHz and data format is 8N1
	write_1s("This is a string of data!\r", 26);  //Transmit this 26 byte string over the usart
	write_1s("Enter a string: ", 16);       //Transmit this 16 byte string
	read_1s((uint8_t*)rstr, 128, '\r');    //read 128 bytes or until a '\r' is received (the enter button) and store in str
	write_1s("You entered: ", 13);         //write a string
        write_1s(rstr, strlen(rstr));          //write the received message
	while (1) ; 
	return 0;
}
예제 #3
0
int main_cm3 ( void ) {

#if 1 // go for 120MHz, built into libopencm3
  // requires: external 8MHz crystal on pin5/6 with associated caps to ground
  rcc_clock_setup_hse_3v3 ( &hse_8mhz_3v3 [ CLOCK_3V3_120MHZ ] );
#endif

  // wait a sec, so we have a reflash opportunity before things get funky
  //
  lame_delay_ms ( 2000 );

  // initialize USART1 @ 9600 baud
  //
  init_usart1 ( 9600 );

  usart_puts ( 1, "Init usart1 complete! Hello World!\r\n" );
  //usart_puts ( 2, "Init usart2 complete! Hello World!\r\n" );

  // PWM setup
#if 0
  usart_puts ( 1, "usart1 pwm test start!\r\n" );
  pwm_test();
  usart_puts ( 1, "usart1 pwm test complete!\r\n" );
#endif

  // MPU setup
#if 0
  mpu_test();
  usart_puts ( 1, "usart1 mpu test complete!\r\n" );
#endif

  // balance!
#if 1
  usart_puts ( 1, "usart1 - enter balance mode!\r\n" );
  balance_or_die();
#endif

  //__enable_irq();
  //cm_enable_interrupts();

  while ( 1 ) {
    __asm__("nop");
  } // while forever

  return 0;
}
예제 #4
0
int main(void)
{
	int16_t buff[6];
	uint8_t bin_buff[13];
	comm_package imu_comm;
	imu_comm.header = (uint8_t)'I';
	init_led();
	init_usart1();
	MPU6050_I2C_Init();
	MPU6050_Initialize();
	init_tim2();
	if( MPU6050_TestConnection() == TRUE)
	{
	   puts("connection success\r\n");
	}else {
	   puts("connection failed\r\n");
	}
	imu_calibration();

	while (1) {
		//puts("running now\r\n");
		MPU6050_GetRawAccelGyro(buff);
		imu_comm.acc_x = buff[0]-ACC_X_OFFSET;
		imu_comm.acc_y = buff[1]-ACC_Y_OFFSET;
		imu_comm.acc_z = buff[2]-ACC_Z_OFFSET;
		imu_comm.gyro_x = buff[3]-GYRO_X_OFFSET;
		imu_comm.gyro_y = buff[4]-GYRO_Y_OFFSET;
		imu_comm.gyro_z = buff[5]-GYRO_Z_OFFSET;
		generate_package( &imu_comm, &bin_buff[0]);
		for (int i = 0 ; i<13 ; i++)
			send_byte( bin_buff[i] );
		gpio_toggle(GPIOA, GPIO_Pin_0);
		gpio_toggle(GPIOA, GPIO_Pin_1);
		delay_ms(10);

	}
}
예제 #5
0
파일: main.c 프로젝트: skeezix/zikzak
int main(void) {

  system_cm3_setup();

  log_setup();
  queue_setup();

  init_usart1 ( 38400 ); // initialize USART1 @ 9600 baud
  init_usart2 ( 38400 );
  //USART_puts ( USART1, "Init usart1 complete! Hello World!\r\n" );
  USART_puts ( USART2, "Init usart2 complete! Hello World!\r\n" );

  fb_setup();

#ifdef VGA_DMA
  vga_setup ( VGA_USE_DMA );
#else
  vga_setup ( VGA_NO_DMA );
#endif

  fb_test_pattern ( fb_active, fbt_offset_squares );
  //fb_test_pattern ( fb_active, fbt_vlines );
  //fb_test_pattern ( fb_active, fbt_v1lines );
  //fb_test_pattern ( fb_active, fbt_onoff1 );

  while ( 1 ) {
    // weeeeee!

    // any work for us to do?
#if 1
    if ( vblank ) {

      if ( queueready() ) {
        command_queue_run();
      }

    }
#endif

    // update framebuffers
#if 0
    if ( vblank ) {
      unsigned char i = 0;
      fb_clone ( fb_2, fb_active );
      while ( vblank ) {
        __asm__("nop");
      }
      fb_test_pattern ( fb_2, i & 0x03 );
      i++;
    }
#endif

    // handle queued logs
#if 1
    if ( logready() ) {
      char *log;
      while ( ( log = logpull() ) ) {
        USART_puts ( USART2, log );
      }
    }
#endif

    __asm__("nop");
  }

} // main
예제 #6
0
파일: main.c 프로젝트: skeezix/zikzak
int main(void) {

  system_cm3_setup();

  log_setup();
  queue_setup();

  init_usart1 ( 38400 ); // initialize USART1 @ 9600 baud
  init_usart2 ( 38400 );
  //USART_puts ( USART1, "Init usart1 complete! Hello World!\r\n" );
  USART_puts ( USART2, "Init usart2 complete! Hello World!\r\n" );

  fb_setup();

#ifdef VGA_DMA
  vga_setup ( VGA_USE_DMA );
#else
  vga_setup ( VGA_NO_DMA );
#endif

#ifdef BUS_FRAMEBUFFER
  bus_setup();
#endif

  //fb_test_pattern ( fb_active, fbt_topbottom );
  fb_test_pattern ( fb_active, fbt_offset_squares );
  //fb_test_pattern ( fb_active, fbt_vlines );
  //fb_test_pattern ( fb_active, fbt_v1lines );
  //fb_test_pattern ( fb_active, fbt_onoff1 );
  //fb_test_pattern ( fb_active, fbt_spriteram );

  while ( 1 ) {
    // weeeeee!

    // any work for us to do?
#ifdef RUNMODE_COMMAND_SERIAL
    if ( vblank ) {

      if ( queueready() ) {
        command_queue_run();
      }

    }
#endif

#ifdef RUNMODE_FRAMEBUFFER_FOREVER
    if ( vblank ) {
      queueit ( "BD" );
      command_queue_run();
    }
#endif

    // update framebuffers
#if 0
    if ( vblank ) {
      unsigned char i = 0;
      fb_clone ( fb_2, fb_active );
      while ( vblank ) {
        __asm__("nop");
      }
      fb_test_pattern ( fb_2, i & 0x03 );
      i++;
    }
#endif

    // check for external RAM updates?
#ifdef zzBUS_FRAMEBUFFER
    static uint16_t _done = 0;
    _done++;
    if ( vblank && _done > 30 && _done < 40  ) {

      bus_grab_and_wait();

      uint32_t addr = 0x1C0000;
      uint8_t v;
      uint8_t i;
      char b [ 2 ];

      USART_puts_optional ( USART2, "+REM cart dump: " );

      for ( i = 0; i < 20; i++ ) {
        v = bus_perform_read ( addr );

        b [ 0 ] = v;
        b [ 1 ] = '\0';
        USART_puts_optional ( USART2, b );

        addr++;
      }

      USART_puts_optional ( USART2, "+++\n" );

      bus_release();

    }
#endif

    // handle queued logs
#if 0
    if ( logready() ) {
      char *log;
      while ( ( log = logpull() ) ) {
        USART_puts ( USART2, log );
      }
    }
#endif

    __asm__("nop");
  }

} // main
예제 #7
0
파일: main.c 프로젝트: msrLi/Robot
void main(void)
{
  uint8_t i;
  BitStatus bytes;
  CLK_HSICmd(ENABLE);//开始内部高频RC
  CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);//不分频  16MHz
  /* Initialize I/Os in Output Mode */
  init_usart1();   // 输入判断
  GPIO_Init(GPIOA, GPIO_PIN_3, GPIO_MODE_OUT_PP_LOW_FAST);// 输出 模式 用于Trag 
  GPIO_Init(GPIOA, GPIO_PIN_2, GPIO_MODE_OUT_PP_LOW_FAST);// 输出 模式 用于Trag 
  GPIO_WriteHigh(GPIOA, GPIO_PIN_2);
  GPIO_Init(GPIOA,GPIO_PIN_1,GPIO_MODE_IN_PU_NO_IT);       // 输入包含  上拉  中断 
//  GPIO_Init(GPIOA,GPIO_PIN_1,GPIO_MODE_IN_PU_IT); 
//  EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOA,EXTI_SENSITIVITY_RISE_ONLY); 
  InitADC();
  enableInterrupts();
  flageExtiA=0;  
  sendBuff[0]=DEVICE_ID;
  sendBuff[3]=0xff;
  sendBuff[4]=0xff;
  sendBuff[5]=0xFF;
  sendBuff[6]=0xA0;
  sendBuff[7]=0xFA; 

  while (1)
  {
     
    bytes=GPIO_ReadInputPin(GPIOA,GPIO_PIN_1);
    if(bytes==RESET && flageExtiA==0)    
    {
        flageExtiA=1;  
        GPIO_WriteReverse(GPIOA,GPIO_PIN_3);  
        for(i=0;i<8;i++)
        {  
          Send(sendBuff[i]);
         }
    }else if(bytes!=RESET)
    {
      flageExtiA=0;
    }  
    datas=readADCs();
  sendBuff[5]=0;
  sendBuff[1]=(uint8_t)(datas&0xff);
  sendBuff[2]=(uint8_t)((datas>>8)&0xff);
  for(i=0;i<5;i++)
  {
    sendBuff[5]+=sendBuff[i];
  }      
//    datas=datas;
//    bytes=GPIO_ReadInputPin(GPIOA,GPIO_PIN_1);
//    if(flageExtiA!=1)
//    {
//      sendBuff[1]=(uint8_t)(datas&0xff);
//      sendBuff[2]=(uint8_t)((datas>>8)&0xff);
//      sendBuff[5]=0;
//      for(i=0;i<5;i++)
//      {
//        sendBuff[5]+=sendBuff[i];
//      }
//    }
  }
  
}