Exemplo n.º 1
0
int main(void) {
///////// Initial Portion /////////////////////////
  init_USART1(9600); // initialize USART1 @ 9600 baud
	SystemCoreClockUpdate();                      /* Get Core Clock Frequency   */
  if (SysTick_Config(SystemCoreClock / 1000)) { /* SysTick 1 msec interrupts  */
    while (1);                                  /* Capture error              */
  }
  USART_puts(USART1, "Init 1 complete! Hello World!rn"); // just send a message to indicate that it works

		//Init GPIO for Leds on board and button input
	init_GPIO();
	
	/////////////////- Loop - ////////////////////////////////////
  while (1){
    
     // You can do whatever you want in here
		USART_puts(USART1, "Init 2 complete! Hello World! \r \n"); // just send a message to indicate that it works
				
		//GPIO_ToggleBits(GPIOD, GPIO_Pin_15 | GPIO_Pin_14 | GPIO_Pin_13| GPIO_Pin_12 );
		GPIO_ToggleBits(GPIOD, GPIO_Pin_12 ); //Test Leds on board
		Delay(200);
		GPIO_ToggleBits(GPIOD, GPIO_Pin_13 ); //Test Leds on board
		Delay(200);
		GPIO_ToggleBits(GPIOD, GPIO_Pin_14 ); //Test Leds on board
		Delay(1000);
     
  }
//////////////////////////////////////////////////////////	
}
Exemplo n.º 2
0
int main(void) {
	initButton();
	initLEDs();
	init_USART1(54000); // initialize USART1 @ 9600 baud

	//USART_puts(USART1, "Init complete! Hello World!&"); // just send a message to indicate that it works
	byte bull[5];
	//Set lowest power parameter
	bull[0]=0x43;
	bull[1]=0x78;
	bull[2]=0x1E;
	bull[3]=0x09;
	bull[4]=7;

	USART_puts(USART1, bull);
	
	//Set 50000bps
	bull[0]=0x43;
	bull[1]=0x78;
	bull[2]=0x1E;
	bull[3]=0x08;
	bull[4]=50;
	USART_puts(USART1, bull);

	while (1){

		char buff[4]="*&*";

		USART_puts(USART1, buff);
	}
}
Exemplo n.º 3
0
void abrir(char *id, uint8_t print) {
	uint32_t num_id = (uint32_t) strtoul(id, NULL, 0);

//	USART_puts(USART2, "Abrir: Comando ainda nao implementado. ID: ");
//	USART_puts(USART2, id);
//	USART_puts(USART2, "\n");

	if (consultaID(num_id)) {
		if (print)
			USART_puts(USART2, "Usuario Cadastrado!\n");
		openRequestTimer = 10000;
//		USART_puts(USART2, "Abrindo o Portao!\n");
	} else {
		uint8_t i;
		if (print)
			USART_puts(USART2, "Usuario Nao Cadastrado!\n");
		for( i = 1 ; i <= bufferNaoCadastrados[0] ; ++i ){
			if( bufferNaoCadastrados[i] == num_id ){
				return;
			}
		}
		if (bufferNaoCadastrados[0] < 9) {
			bufferNaoCadastrados[0]++;
			bufferNaoCadastrados[bufferNaoCadastrados[0]] = num_id;
		}

	}

}
Exemplo n.º 4
0
// cpu <-> gpu serial
void usart1_isr ( void ) {

  // check if the USART1 receive interrupt flag was set
  if ( USART_GetITStatus ( USART1, USART_IT_RXNE ) ) {

    static uint8_t cnt = 0; // this counter is used to determine the string length
    char t = USART1->DR; // the character from the USART1 data register is saved in t

    /* check if the received character is not the LF character (used to determine end of string)
     * or the if the maximum string length has been been reached
     */
    if( (t != '\n') && (cnt < MAX_STRLEN) ){
      received_string[cnt] = t;
      cnt++;
    } else { // otherwise reset the character counter and print the received string
      cnt = 0;
      //USART_puts(USART1, received_string);
      USART_puts ( USART2, "avr: " );
      USART_puts ( USART2, received_string );
      USART_puts ( USART2, "\r\n" );
    }

  } // if USART received

} // func
Exemplo n.º 5
0
/**
  * @brief  Configures all needed resources (I2C, DCMI and DMA) to interface with
  *         the OV9655 camera module
  * @param  None
  * @retval 0x00 Camera module configured correctly 
  *         0xFF Camera module configuration failed
  */
uint8_t DCMI_OV9655Config(void)
{
    uint8_t readvalue;
    char str[8];
    uint8_t opmask=MODE|LEN|OEN_TRI_SEL_MASK;
  /* I2C1 will be used for camera configuration */
  I2C1_Config();  
//  - Read ID and check
    readvalue=DCMI_SingleRandomRead(OV9655_DEVICE_READ_ADDRESS,ID);
    sprintf(str,"ID=%x,",readvalue);
    USART_puts(USART2,str);
    
    
//- Write opform register
    //Mode=0, Len=0, rest default
    tw9910_mask_set(OV9655_DEVICE_WRITE_ADDRESS, OPFORM, opmask, 0x00|OEN_TRI_SEL_ALL_ON);
    
    
//- set resolution(vscale,hscale or vactive,hactive and vdelay hdelay)
      /* OV9655 Camera size setup */    
  DCMI_OV9655_QVGASizeSetup();
    




//- write the hsync vsync pin configuration(output control 0x05)
 DCMI_SingleRandomWrite(OV9655_DEVICE_WRITE_ADDRESS, OUTCTR1, 0x02);//**0x11,0x01,0x10?
 //- write clock
 DCMI_SingleRandomWrite(OV9655_DEVICE_WRITE_ADDRESS, OUTCTR2, 0x00);

//- write vbi control register for invalid bit settings and Hactive enable
tw9910_mask_set(OV9655_DEVICE_WRITE_ADDRESS,VBICNTL,0x18, 0x18);//Enable HA_EN**0,1? and cntl656


//- read and print status registers(Nicely! - normal status, detected format etc.)
    readvalue=DCMI_SingleRandomRead(OV9655_DEVICE_READ_ADDRESS,STATUS1);
    sprintf(str,"St1=%x,",readvalue);
    USART_puts(USART2,str);
    while((DCMI_SingleRandomRead(OV9655_DEVICE_READ_ADDRESS,STATUS1)&~0x10)!=0x68){
    
        
        Delay(10);
    }
    readvalue=DCMI_SingleRandomRead(OV9655_DEVICE_READ_ADDRESS,STATUS1);
    sprintf(str,"St1=%x,",readvalue);
//    USART_puts(USART2,str);
    readvalue=DCMI_SingleRandomRead(OV9655_DEVICE_READ_ADDRESS,STATUS2);
    sprintf(str,"St2=%x,",readvalue);
    USART_puts(USART2,str);
    readvalue=DCMI_SingleRandomRead(OV9655_DEVICE_READ_ADDRESS,SDT);
    sprintf(str,"Sdt=%x\n",readvalue);
    USART_puts(USART2,str);


  /* Configure the DCMI to interface with the OV9655 camera module */
  DCMI_Config();
  
  return (0x00);
}
Exemplo n.º 6
0
//--------------
//main loop
int main(void)
{

	int i=0;
	for(i=0;i<100000ul;i++);


	rcc_config();
	nvic_config();
	gpio_config();
	usart_config();
	USART_puts(USART1, "USART BT initialization complete!\r\n"); // just send a message to indicate that it works

	MPU6050_I2C_Init();
	MPU6050_Initialize();
	if( MPU6050_TestConnection() == 1){
	    // connection success
		USART_puts(USART1, "I2C IMU connection initialization complete!\r\n");
	}else{
	    // connection failed
		USART_puts(USART1, "I2C initialization failed!\r\n");
	}

	//sysTick_Config_Mod(SysTick_CLKSource_HCLK_Div8, 10500000ul); // interruption every 1/2sec from systick
	sysTick_Config_Mod(SysTick_CLKSource_HCLK_Div8, 840000ul); // interruption every 0.04sec from systick


    while(1)
    {

    }
}
Exemplo n.º 7
0
void TIM4_Init(void)
{
	TIM4->PSC = 1999;
  TIM4->ARR = 41999;
	TIM4->CR1 |= TIM_CR1_CEN;
	USART_puts(USART1, "TIM4 init ok");
	USART_puts(USART1, "\n\r");
}
Exemplo n.º 8
0
void backward(){
	SpeedValue_left = 105;
	SpeedValue_right = 105;
	mMove(SpeedValue_left, SpeedValue_right);
	USART_puts(USART3, "left:");
	USART_putd(USART3, SpeedValue_left);
	USART_puts(USART3, " right:");
	USART_putd(USART3, SpeedValue_right);
	USART_puts(USART3, "\r\n");
}
Exemplo n.º 9
0
void forward(){
	SpeedValue_left = 140;
	SpeedValue_right = 140;
	mMove(SpeedValue_left,SpeedValue_right);
	USART_puts(USART3, "left:");
	USART_putd(USART3, SpeedValue_left);
	USART_puts(USART3, " right:");
	USART_putd(USART3, SpeedValue_right);
	USART_puts(USART3, "\r\n");
}
Exemplo n.º 10
0
void stop(){
	SpeedValue_left = 120;
	SpeedValue_right = 120;
	mMove(SpeedValue_left, SpeedValue_right);
	USART_puts(USART3, "left");
	USART_putd(USART3, SpeedValue_left);
	USART_puts(USART3, " right");
	USART_putd(USART3, SpeedValue_right);
	USART_puts(USART3, "\r\n");
}
Exemplo n.º 11
0
void right(){
	SpeedValue_left = 140;
	SpeedValue_right = 105;
	mMove(SpeedValue_left, SpeedValue_right);
	USART_puts(USART3, "left");
	USART_putd(USART3, SpeedValue_left);
	USART_puts(USART3, " right");
	USART_putd(USART3, SpeedValue_right);
	USART_puts(USART3, "\r\n");
}
Exemplo n.º 12
0
uint8_t handleTopPacket(void)
{

    if(USART_GetFlagStatus(USART2, USART_FLAG_RXNE))
    {
        uint8_t received = USART_ReceiveData(USART2);

        if(START_BYTE == received)
        {
            uint8_t timer = 0;	//Timer used to stop the function from waiting for data if there is an error
            GPIO_SetBits(GPIOD, GREED_LED);	//Turns on the green led
            uint8_t counter = 1;	//Counter used to count how many bytes we have read in from the top borad
            while(counter < PACKET_SIZE && timer < 0xFFFF)  //Waits until all 16 bytes are read in. If no data comes then the function will break
                //out after a short period of time
            {
                if(USART_GetFlagStatus(USART2, USART_FLAG_RXNE)) //if data is received store it in the array storage
                {
                    received = USART_ReceiveData(USART2);
                    if(received != START_BYTE)
                    {
                        storage[counter] = received;	//Reads in the data from the buffer into an array
                        counter++;	//Increments the counter
                    }
                    else
                    {
                        return(0);
                    }


                }
                GPIO_SetBits(GPIOD, ORANGE_LED);
                timer++;
            }
            if(1 || (checksum(storage, PACKET_SIZE - 3) == storage[PACKET_SIZE - 2]) && (storage[PACKET_SIZE - 1] == END_BYTE))  //Checks the check sum and the end byte
            {
                GPIO_ResetBits(GPIOD, ORANGE_LED);
                convertTBtoBB(storage);  //Converts the data from the top board into motor controller commands that we can use
                sendPackets();	//Sends the motor controller commands produced by the convert function
                return(1); //Reading the packet was successful!
            }
            else
            {
                USART_puts(USART1, (checksum(storage, PACKET_SIZE - 3)));
                USART_puts(USART1,storage[PACKET_SIZE - 2]);
                return(0);  //Returns 0 if the check sum or end byte were incorrect
            }

        }
        else
            return(0);  //Makes the function recursive until we get a response from the top board
    }
    else
        return(0);
}
Exemplo n.º 13
0
void listar(void) {
	int i = 0;
	uint32_t contadorRegistros;

	USART_puts(USART2, "Usuarios Cadastrados: \n");
	contadorRegistros = buffer[0];
	sprintf(string_buffer, "Quantidade: %d\n", (int) contadorRegistros);
	USART_puts(USART2, string_buffer);
	if (contadorRegistros != 0)
		USART_puts(USART2, "\tCodigo\n");
	for (i = 1; i <= contadorRegistros; i++) {
		sprintf(string_buffer, "%d.\t%d\n", i, (int) buffer[i]);
		USART_puts(USART2, string_buffer);
	}

	USART_puts(USART2, "Usuarios Nao Cadastrados (Recentes): \n");
	contadorRegistros = bufferNaoCadastrados[0];
	sprintf(string_buffer, "Quantidade: %d\n", (int) contadorRegistros);
	USART_puts(USART2, string_buffer);
	if (contadorRegistros != 0)
		USART_puts(USART2, "\tCodigo\n");
	for (i = 1; i <= contadorRegistros; i++) {
		sprintf(string_buffer, "%d.\t%d\n", i, (int) bufferNaoCadastrados[i]);
		USART_puts(USART2, string_buffer);
	}

	bufferNaoCadastrados[0] = 0;

}
Exemplo n.º 14
0
void convert_int(int x)
{
	if(x<0)
	{
		x = x*(-1);
		USART_puts(USART2,'-');
	}
	
    if(x>=10)
        convert_int(x/10);

    x = x%10;
    USART_puts(USART2,x+'0');
}
Exemplo n.º 15
0
// this is the interrupt request handler (IRQ) for ALL USART3 interrupts
void USART3_IRQHandler(void){

	// check if the USART3 receive interrupt flag was set
	if( USART_GetITStatus(USART3, USART_IT_RXNE) ){

		/*check the uart RX have accept the char*/
		GPIO_ToggleBits(GPIOD,GPIO_Pin_14);


		static uint8_t cnt = 0; // this counter is used to determine the uart receive string length

		//Receive_data = USART3->DR; // the character from the USART3 data register is saved in t
		Receive_data = USART_ReceiveData(USART3);;

		/* check if the received character is not the LF character (used to determine end of string) 
		 * or the if the maximum string length has been been reached 
		 */

		if( cnt < MAX_STRLEN){ 
			received_string[cnt] = Receive_data;
            if(Receive_data=='0') GPIO_ToggleBits(GPIOD,GPIO_Pin_15);

            /*start determine the period of command.*/
            if(received_string[cnt]=='\r'){
                Receive_String_Ready = 1; /*Ready to parse the command */
                cnt=0; /*restart to accept next stream message.*/
            }
            else{
                cnt++;
            }
		}
		else{ // over the max string length, cnt return to zero.
			Receive_String_Ready=1;
			cnt = 0;  
		}
		if(Receive_String_Ready){
			//print the content of the received string
			USART_puts(USART3, received_string);
			USART_puts(USART3,"\r\n");
			//receive_task();
			/*clear the received string and the flag*/
			Receive_String_Ready = 0;
			int i;
			for( i = 0 ; i< MAX_STRLEN ; i++){
				received_string[i]= 0;
			}
		}
	}
}
Exemplo n.º 16
0
void TIM2_Init(void)
{
	TIM2->CR1 &= ~TIM_CR1_CEN;
	prescaler = SystemCoreClock/2;
	prescaler /=Timer_Frequency;
	prescaler -=1;
	TIM2	->	PSC			=		(Timer_Frequency-1);
	TIM2	->	ARR			=		prescaler;
	NVIC_EnableIRQ(TIM2_IRQn);
	NVIC_SetPriority(TIM2_IRQn, 0x01);
	TIM2->DIER |= TIM_DIER_UIE;
	TIM2->CR1 |= TIM_CR1_CEN;
	USART_puts(USART1, "TIM2 init ok");
	USART_puts(USART1, "\n\r");
}
Exemplo n.º 17
0
FRESULT ff_read(void)
{
    char line[20];

    printf("ff_read begin\n\r");
    res = f_mount(&fatfs, "", 0);
    if(res != FR_OK) printf("mount failed: %d\n\r", res);

    res = f_open(&file, "test.txt", FA_READ);
    res = f_open(&file2, "var.txt", FA_READ);
    if(res != FR_OK) printf("open failed: %d\n\r", res);

    speed[0] = 1;
    speed[1] = 0;

    while(1)
    {
	f_gets(line, sizeof(line), &file);
	if(line[0] == 0) break;
	USART_puts(USART3, line);

	int i;
	for(i = 0; i < 20; i++) line[i] = 0;
    }

    res = f_read(&file2, speed, sizeof(speed), &br);
    printf("speed:%d, %d\n\r",speed[0], speed[1]);

    res = f_close(&file);
    res = f_close(&file2);
    if(res != FR_OK) printf("close failed: %d\n\r", res);

    res = f_mount(NULL, "", 0);
    if(res != FR_OK) printf("umnout failed: %d\n\r", res);
}
Exemplo n.º 18
0
void printf2(const char *format, ...)
{
    if ( Utils::inISR() ) {
        Event *e = EventPool::instance().newEvent(DEBUG_EVENT);
        if ( e == NULL )
            return;

        va_list list;
        va_start(list, format);
        vsnprintf(e->debugMessage.buffer, 128, format, list);
        va_end(list);

        EventQueue::instance().push(e);
    }
    else {
        va_list list;
        va_start(list, format);
        vsnprintf(__buffer, 128, format, list);
        va_end(list);
#ifdef MULTIPLEXED_OUTPUT
        DataTerminal::instance().write("DEBUG", __buffer);
#else
        USART_puts(USART2, __buffer);
#endif
    }
}
Exemplo n.º 19
0
void test_motors(int max_torgue)
{
	cnt = 0;
	while(cnt < max_torgue)
	{
		sprintf(send, "hhh: %d\n",cnt);
		USART_puts(USART2, send); 
		
		if(cnt < max_torgue-1)
		{
			STM_EVAL_LEDOn(LED3);
			cnt = cnt + 5;
			ESC_SetPower(1,cnt);
			ESC_SetPower(2,cnt);
			ESC_SetPower(3,cnt);
			ESC_SetPower(4,cnt);
			Delay(10);
		}else
		{
			STM_EVAL_LEDOff(LED3);
			ESC_SetPower(1,0);
			ESC_SetPower(2,0);
			ESC_SetPower(3,0);
			ESC_SetPower(4,0);
			Delay(3000);
		}
		if(UserButtonPressed == 1)
		{
			break;
		}
	}
}
Exemplo n.º 20
0
void usartTaskMain(void* dummy) {
  USART_puts("usartTaskMain");
  while (1) {
    vTaskDelay(usartTask_delay); // yield
  }
  return;
}
Exemplo n.º 21
0
void USART2_INIT(void)
{
	GPIOA	->	MODER 		|=	GPIO_MODER_MODER3_1;		// RX PD6 to alternate function output push-pull at 50 MHz 0x10
	GPIOA	->	MODER 		|=	GPIO_MODER_MODER2_1;		// TX PD5 to alternate function output push-pull at 50 MHz 0x10
	GPIOA ->	OSPEEDR		|=  GPIO_OSPEEDER_OSPEEDR3_0 | GPIO_OSPEEDER_OSPEEDR3_1;		//50Mhz fast speed
	GPIOA ->	OSPEEDR		|=	GPIO_OSPEEDER_OSPEEDR2_0 | GPIO_OSPEEDER_OSPEEDR2_1;
	GPIOA ->	PUPDR			|=  GPIO_PUPDR_PUPDR2_0;
	GPIOA	->	AFR[0]		|=	(7<<8);
	GPIOA	->	AFR[0]		|=	(7<<12);
	BRR = (SystemCoreClock/4) / (BaudRate*16);
	USART2 ->	BRR = (68 << 4 ) + 0x06; //38400br
	USART2 -> CR1 |= USART_CR1_UE | USART_CR1_RE | USART_CR1_TE;
	USART2 -> CR3 |= USART_CR3_DMAR;
	USART_puts(USART1, "USART2 init ok");
	USART_puts(USART1, "\n\r");
}
Exemplo n.º 22
0
void serial::write(uint8_t* packet, uint8_t size)
{
	for(int i = 0; i < size; i++)
	{
		USART_puts(thisUsart, packet[i]);
	}
}
Exemplo n.º 23
0
void USART_putd(USART_TypeDef* USARTx, uint32_t number) //uint32_t = unsigned int
{
	static uint32_t temp; //uint32_t
	static uint8_t cnt = 0; //uint8_t = unsigned char
	volatile uint8_t tmp_num[10]; //uint8_t
	volatile uint8_t num[10]; //uint8_t

	if(number == 0){
		tmp_num[cnt++] = '0';
	}
	while(number != 0){
		temp = number % 10;
		number -= temp;
		number /= 10;
		tmp_num[cnt] = temp+'0';
		cnt++;
	}
	
	int j = 0;
	while(cnt){
		num[j++] = tmp_num[--cnt];
	}
	num[j] = '\0';

	USART_puts(USART3, num);
	cnt = 0;
	int i;
	for( i = 0 ; i< 10 ; i++){
		tmp_num[i]= 0;
		num[i]= 0;
	}
}
Exemplo n.º 24
0
Arquivo: main.c Projeto: ADTL/ARMWork
int main (void) {
  
  SystemCoreClockUpdate();

  USART_init(&usart, PIO0_18, PIO0_19);
  USART_begin(&usart, 9600);
  USART_puts(&usart, "Hello.\n");

  VCOM_Init();                              // VCOM Initialization

  USB_Init();                               // USB Initialization
  USB_Connect(TRUE);                        // USB Connect

  while (!USB_Configuration) ;              // wait until USB is configured

  while (1) {                               // Loop forever
    VCOM_Serial2Usb();                      // read serial port and initiate USB event
    VCOM_CheckSerialState();
	VCOM_Usb2Serial();
  } // end while											   
  
  SPI_init(&SPI0, PIO0_1, PIO0_1, PIO0_1, PIO0_2);			
	
  while ( 1 );
}
Exemplo n.º 25
0
void USART1_IRQHandler(void)
{
	if( USART_GetITStatus(USART1, USART_IT_RXNE) )
	{
		char t = USART1->DR;
		USART_puts(USART1, (t+10)%256);
	}
}
Exemplo n.º 26
0
void DMA2_Init(void)
{
	DMA2_Stream0 -> CR &= ~DMA_SxCR_EN;					// disable Stream0
	DMA2_Stream0 -> PAR = (uint32_t)&ADC1->DR;							// from periph port register
	DMA2_Stream0 -> M0AR = (uint32_t) &adc_buffer;					// write to memory
	DMA2_Stream0 -> NDTR = ARRAYSIZE;						// number of data items
	DMA2_Stream0 -> CR |= DMA_SxCR_MINC;				// memory increment
	DMA2_Stream0 -> CR &= ~(DMA_SxCR_CHSEL);		// select chanel0
	DMA2_Stream0 -> CR |= DMA_SxCR_MSIZE_0;			// half-word (16bit) memory data size
	DMA2_Stream0 -> CR |= DMA_SxCR_PSIZE_0;			// half-word (16bit) peripherial data size
	DMA2_Stream0 -> CR |= DMA_SxCR_TCIE;				// transaction complete interrupt
	DMA2_Stream0 -> CR |= DMA_SxCR_CIRC;				// non enable continous mode
	DMA2_Stream0 -> CR |= DMA_SxCR_EN;					// enable Stream0
	NVIC_EnableIRQ(DMA2_Stream0_IRQn);					// enable IRQ
	USART_puts(USART1, "DMA2 init ok");
	USART_puts(USART1, "\n\r");
}
Exemplo n.º 27
0
void cnc_joystick_interrupt(){
	if(cnc_joystick_button_status(BUTTON_UP))USART_puts(USART1, "Button UP pressed\n\r");
	if(cnc_joystick_button_status(BUTTON_DOWN))USART_puts(USART1, "Button DOWN pressed\n\r");
	if(cnc_joystick_button_status(BUTTON_FORWARD))USART_puts(USART1, "Button FORWARD pressed\n\r");
	if(cnc_joystick_button_status(BUTTON_BACK))USART_puts(USART1, "Button BACK pressed\n\r");
	if(cnc_joystick_button_status(BUTTON_LEFT))USART_puts(USART1, "Button LEFT pressed\n\r");
	if(cnc_joystick_button_status(BUTTON_RIGHT))USART_puts(USART1, "Button RIGHT pressed\n\r");
	if(cnc_joystick_button_status(BUTTON_OK))USART_puts(USART1, "Button OK pressed\n\r");
	if(cnc_joystick_button_status(BUTTON_CANCEL))USART_puts(USART1, "Button CANCEL pressed\n\r");
}
Exemplo n.º 28
0
/* test use for printing the status and counter value through usart */
void getEncoder(void){
	detachEXTI(EXTI_Line0 | EXTI_Line1 | EXTI_Line2 | EXTI_Line3);

	USART_puts(USART3, "L_state:");
	USART_putd(USART3, ENCODER_L.rotate);

	USART_puts(USART3, " R_state:");
	USART_putd(USART3, ENCODER_R.rotate);

	getEncoderState(&ENCODER_L);
	getEncoderState(&ENCODER_R);

	USART_puts(USART3, " L_state2:");
	USART_putd(USART3, ENCODER_L.rotate);
	USART_puts(USART3, " R_state2:");
	USART_putd(USART3, ENCODER_R.rotate);

	USART_puts(USART3, " le_en:");
	USART_putd(USART3, ENCODER_L.count);
	USART_puts(USART3, " ri_en:");
	USART_putd(USART3, ENCODER_R.count);
	USART_puts(USART3, "\r\n");

	/* clear encoder counter*/
	ENCODER_L.count = 0;
	ENCODER_R.count = 0;

	attachEXTI(EXTI_Line0 | EXTI_Line1 | EXTI_Line2 | EXTI_Line3);
}
Exemplo n.º 29
0
void ADC_Init(void)
{
	ADC1-> CR1 |=ADC_CR1_SCAN;		// Enable channel scan
	ADC1-> CR2 |=ADC_CR2_CONT;		//continous
	ADC1-> SQR1 |=(1<<20);				// 0001: 2 conversion
	ADC1-> SQR3	|=(16<<0);				// Channel 16 first sequence
	ADC1-> SQR3	|=(18<<5);				// Channel 18 second sequence
	ADC1-> CR2 |=ADC_CR2_ADON;		// Enable ADC1
	ADC1->CR2 &=~ADC_CR2_DMA;
	ADC1->CR2 |=ADC_CR2_DMA;
	ADC1->SMPR1 |= ADC_SMPR1_SMP16_1 | ADC_SMPR1_SMP16_2;	// sampling time 144 cycles
	ADC1->SMPR1 |= ADC_SMPR1_SMP18_1 | ADC_SMPR1_SMP18_2;	// sampling time 144 cycles
	ADC -> CCR |=ADC_CCR_TSVREFE;	// Enable TSVREFE
	ADC -> CCR |=ADC_CCR_VBATE;		// Enable VBATE
	ADC1 -> DR = 0;
	USART_puts(USART1, "ADC init ok");
	USART_puts(USART1, "\n\r");
}
Exemplo n.º 30
0
void USART1_INIT(uint32_t baudrate)
{
	GPIOB	->	MODER 		|=	GPIO_MODER_MODER6_1;		// RX PD6 to alternate function output push-pull at 50 MHz 0x10
	GPIOB	->	MODER 		|=	GPIO_MODER_MODER7_1;		// TX PD5 to alternate function output push-pull at 50 MHz 0x10
	GPIOB ->	OSPEEDR		|=  GPIO_OSPEEDER_OSPEEDR6_0 | GPIO_OSPEEDER_OSPEEDR6_1;		//50Mhz fast speed
	GPIOB ->	OSPEEDR		|=	GPIO_OSPEEDER_OSPEEDR7_0 | GPIO_OSPEEDER_OSPEEDR7_1;
	GPIOB ->	PUPDR			|=  GPIO_PUPDR_PUPDR6_0;
	GPIOB	->	AFR[0]		|=	(7<<24);
	GPIOB	->	AFR[0]		|=	(7<<28);

	USART1 ->	BRR = (136 << 4 ) + 0x0C; //38400br 
	USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); // enable the USART1 receive interrupt
	NVIC_SetPriority(USART1_IRQn, 2);
	NVIC_EnableIRQ(USART1_IRQn);
	USART1 -> CR1 |= USART_CR1_UE | USART_CR1_RE | USART_CR1_TE;
	USART_puts(USART1, "USART1 init ok");
	USART_puts(USART1, "\n\r");
}