Exemplo n.º 1
0
int main(void) {
    int i = 10;

    GPIO_InitTypeDef gpio_init;
    USART_InitTypeDef usart_init;
    USART_ClockInitTypeDef usart_clk_init;

    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

    // PA9 = Tx, PA10 = Rx
    gpio_init.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
    gpio_init.GPIO_Mode = GPIO_Mode_AF;
    gpio_init.GPIO_Speed = GPIO_Speed_40MHz;
    gpio_init.GPIO_OType = GPIO_OType_PP;
    gpio_init.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOA, &gpio_init);

    GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);

    USART_ClockStructInit(&usart_clk_init);
    USART_ClockInit(USART1, &usart_clk_init);

    usart_init.USART_BaudRate =            9600;
    usart_init.USART_WordLength =          USART_WordLength_8b;
    usart_init.USART_StopBits =            USART_StopBits_1;
    usart_init.USART_Parity =              USART_Parity_No ;
    usart_init.USART_Mode =                USART_Mode_Rx | USART_Mode_Tx;
    usart_init.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    USART_Init(USART1, &usart_init);
    USART_Cmd(USART1,ENABLE);

    while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) {}

    while (1) {

        if ( usart_available() ) // data available
        {
            usart_print( "Data Available: " );
            uint8_t ch = usart_read();
            usart_write(ch);
            usart_print( "\r\n" );
        }

    }


    return 0;
}
Exemplo n.º 2
0
void serial_printf(const char *format, ...) {
    va_list args;

    va_start(args, format);
    vsnprintf(prbuff, PRBUFF_LEN, format, args);
    usart_print(prbuff);
    va_end(args);
}
Exemplo n.º 3
0
static void on_line_recv(const char* c, unsigned int length)
{
  if (c[0] == 'm') {
    charge_start(MANUAL);
    usart_print("manual\n");
  } else if (c[0] == 't') {
    charge_start(TRICKLE);
    usart_print("trickle\n");
  } else if (c[0] == 'c') {
    charge_start(CHARGE);
    usart_print("charge\n");
  } else if (c[0] == '=') {
    const char* end = c+length+1;
    long offset = strtol(&c[1], (char** restrict) &end, 10);
    set_charge_offset(offset);
    usart_printf("set offset %d\n", offset);
  } else if (c[0] == 'v') {
Exemplo n.º 4
0
int main(void)
{
  RCC_GetClocksFreq(&RCC_Clocks);
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
    
  GPIO_InitTypeDef gpio_init;
  USART_InitTypeDef usart_init;
  USART_ClockInitTypeDef usart_clk_init;
 
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
 
  // PA2 = Tx, PA3 = Rx
  gpio_init.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
  gpio_init.GPIO_Mode = GPIO_Mode_AF_PP;
  gpio_init.GPIO_Speed = GPIO_Speed_10MHz;
  GPIO_Init(GPIOA, &gpio_init);

  gpio_init.GPIO_Pin = GPIO_Pin_5;
  gpio_init.GPIO_Mode = GPIO_Mode_Out_PP;
  gpio_init.GPIO_Speed = GPIO_Speed_10MHz;
  GPIO_Init(GPIOA, &gpio_init);

  GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
  GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
 
  USART_ClockStructInit(&usart_clk_init);
  USART_ClockInit(USART2, &usart_clk_init);
 
  usart_init.USART_BaudRate =            9600;
  usart_init.USART_WordLength =          USART_WordLength_8b;
  usart_init.USART_StopBits =            USART_StopBits_1;
  usart_init.USART_Parity =              USART_Parity_No ;
  usart_init.USART_Mode =                USART_Mode_Rx | USART_Mode_Tx;
  usart_init.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_Init(USART2, &usart_init);
  USART_Cmd(USART2,ENABLE);    
     
  while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET) {}        
 
  while (1)
  {
    usart_print( "UART Example" );

    // toggle led
    GPIOA->ODR ^= GPIO_Pin_5;
    Delay(500);
  }
}
Exemplo n.º 5
0
int main(void) {
	char tmp[256];

	const char message[] = 
			"This royal throne of kings, this scepter'd isle, \n"
			"This earth of majesty, this seat of Mars, \n" /*
			"This other Eden, demi-paradise, \n" 
			"This fortress built by Nature for herself\n"
			"Against infection and the hand of war, \n"
			"This happy breed of men, this little world,\n" 
			"This precious stone set in the silver sea, \n"
			"Which serves it in the office of a wall, \n"
			"Or as a moat defensive to a house, \n"
			"Against the envy of less happier lands, \n"
			"This blessed plot, this earth, this realm, this England,"*/
	;
	const uint16 messlen = strlen(message);
	
	cmcore_init();
	usart_init(&Serial6, USART6, PC7, PC6);
	usart_begin(&Serial6, 57600);

	spi_init(&spi1, SPI1, PA5, PA6, PA7, PA4);
	spi_begin(&spi1);

	usart_print(&Serial6, "Basic initialization has been finished.\n");
		
	RCC_ClocksTypeDef RCC_Clocks;
	RCC_GetClocksFreq(&RCC_Clocks);
	
	usart_print(&Serial6, message);
	usart_print(&Serial6, "\r\n\r\n");
	usart_flush(&Serial6);

	sprintf(tmp, "Clock frequencies: SYSCLK = %dl, HCLK = %dl, PCLK1 = %dl\r\n", 
		RCC_Clocks.SYSCLK_Frequency, RCC_Clocks.HCLK_Frequency, RCC_Clocks.PCLK1_Frequency);
	usart_print(&Serial6, tmp); 

	GPIOMode(PinPort(LED1), (PinBit(LED1) | PinBit(LED2) | PinBit(LED3) | PinBit(LED4)), 
					OUTPUT, FASTSPEED, PUSHPULL, NOPULL);
	
	nokiaLCD.init();
	nokiaLCD.clear();
	nokiaLCD.drawBitmap(PCD8544::SFEFlame);
		delay(1000);
		
	uint16 shift = 0;
	nokiaLCD.selectFont(PCD8544::CHICAGO10);
	
	while (1) {
		nokiaLCD.clear();
		nokiaLCD.cursor(shift);
		nokiaLCD.drawString("Nuke is absolutely safe!");
//		nokiaLCD.drawFont(Nokia5110::Chicago10x15, 'A');
//		nokiaLCD.drawFont(Nokia5110::Chicago10x15, 'W');
		shift++;
		shift %= 252;
		delay(250);

/*
		if ( millis() / 125 != shift ) {
			shift = millis()/ 125;
			nokiaLCD.clear();
			nokiaLCD.gotoXY(7- shift%7,0);
			strncpy(tmp, message+((shift/7) % messlen), 48);
			tmp[48] = 0;
			nokiaLCD.drawString(tmp);
//		usart_print(&Serial6, tmp);
//		usart_print(&Serial6, "\r\n");
		}
		*/
	}
}
Exemplo n.º 6
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
	RCC_ClocksTypeDef RCC_Clocks;
	char tmp[64];
	
  /*!< At this stage the microcontroller clock setting is already configured, 
       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
     */  

	cmcore_init();
	//TIM2_delay_start();
	//usart_init(&stdserial, USART3, PB11, PB10, 19200);
  /* SysTick end of count event each 10ms */
  RCC_GetClocksFreq(&RCC_Clocks);
//  SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);
	
//	usart_init(&stdserial, USART3, PB11, PB10, 57600);
	sprintf(tmp, "SYSCLK = %ld\n", RCC_Clocks.SYSCLK_Frequency);
	usart_print(&stdserial, tmp);
	sprintf(tmp, "HCLK = %ld\n", RCC_Clocks.HCLK_Frequency);
	usart_print(&stdserial, tmp);
	sprintf(tmp, "PCLK1 = %ld\n", RCC_Clocks.PCLK1_Frequency);
	usart_print(&stdserial, tmp);
	sprintf(tmp, "PCLK2 = %ld\n", RCC_Clocks.PCLK2_Frequency);
	usart_print(&stdserial, tmp);
//	usart_print(&stdserial, tmp);
	
  /* Initialize LEDs and LCD available on STM324xG-EVAL board *****************/
	pinMode(LED1_PIN, OUTPUT);
//  STM_EVAL_LEDInit(LED1);
//  STM_EVAL_LEDInit(LED2);
//  STM_EVAL_LEDInit(LED3);
//  STM_EVAL_LEDInit(LED4);

  /* Initialize the LCD */
	digitalWrite(LED1_PIN, HIGH); // Off
//  STM324xG_LCD_Init();
  /* Display message on STM324xG-EVAL LCD *************************************/
  /* Clear the LCD */ 
//  LCD_Clear(White);

  /* Set the LCD Back Color */
//  LCD_SetBackColor(Blue);
  /* Set the LCD Text Color */
//  LCD_SetTextColor(White);
//  LCD_DisplayStringLine(LINE(0), (uint8_t *)MESSAGE1);
//  LCD_DisplayStringLine(LINE(1), (uint8_t *)MESSAGE2);
//  LCD_DisplayStringLine(LINE(2), (uint8_t *)MESSAGE3);

  /* Turn on LEDs available on STM324xG-EVAL **********************************/
	digitalWrite(LED1_PIN, HIGH);
//  STM_EVAL_LEDOn(LED1);
//  STM_EVAL_LEDOn(LED2);
//  STM_EVAL_LEDOn(LED3);
//  STM_EVAL_LEDOn(LED4);

  /* Add your application code here
     */
	pinMode(BUTTON1_PIN, INPUT);

  /* Infinite loop */
  while (1)
  {
    /* Toggle LD4 */
//    STM_EVAL_LEDToggle(LED4);
		digitalToggle(LED1_PIN);
    /* Insert 50 ms delay */
    delay(500);

    /* Toggle LD2 */
//    STM_EVAL_LEDToggle(LED2);
		digitalToggle(LED1_PIN);

    /* Insert 50 ms delay */
    delay(500);
		
		if ( digitalRead(BUTTON1_PIN) ) {
			usart_print(&stdserial, "Wow! ");
		} else {
			sprintf(tmp, "%ld\n", millis());
			usart_print(&stdserial, tmp);
		}
  }
}
Exemplo n.º 7
0
Arquivo: main.c Projeto: ADTL/ARMWork
int main(void) {
	uint16_t bits;
	uint32_t intval = 40;
	uint32_t tnow;
	char tmp[92];
	RCC_ClocksTypeDef RCC_Clocks;
	uint16_t i;
	
	TIM2_timer_start();

	usart_begin(&USerial3, USART3, PC11, PC10, 19200);

	usart_print(&USerial3, 
			"Happy are those who know they are spiritually poor; \n"
			"The kingdom of heaven belongs to them!\n");
	usart_flush(&USerial3);
	
	RCC_GetClocksFreq(&RCC_Clocks);

	sprintf(tmp, "SYSCLK = %ul\n", RCC_Clocks.SYSCLK_Frequency);
	usart_print(&USerial3, tmp);
	sprintf(tmp, "PCLK1 = %ul\n", RCC_Clocks.PCLK1_Frequency);
	usart_flush(&USerial3);

	GPIOMode(PinPort(PD12),
			(PinBit(PD12) | PinBit(PD13) | PinBit(PD14) | PinBit(PD15)), OUTPUT,
			FASTSPEED, PUSHPULL, NOPULL);
			/*
	spi_begin(SPI2, PB13, PB14, PB15, PB12);
	digitalWrite(PB12, HIGH);
*/
	I2C1_Init();
/*
	i2c_begin(&Wire1, PB9, PB8, 100000);
	lcd.init(&Wire1);
	lcd.begin();
	lcd.setContrast(46);
	lcd.print("Yappee!");       // Classic Hello World!
*/
	bits = GPIO_ReadOutputData(GPIOD );
	GPIOWrite(GPIOD, PinBit(PD13) | (bits & 0x0fff));
	delay_ms(intval);
	tnow = millis() / 1000;
	while (tnow == millis() / 1000)
		;
	tnow = millis() / 1000;

	while (1) {
		bits = GPIO_ReadOutputData(GPIOD );

		GPIOWrite(GPIOD, PinBit(PD13) | (bits & 0x0fff));
		delay_ms(intval);
		GPIOWrite(GPIOD, PinBit(PD14) | (bits & 0x0fff));
		delay_ms(intval);
		GPIOWrite(GPIOD, PinBit(PD15) | (bits & 0x0fff));
		delay_ms(intval);
		GPIOWrite(GPIOD, PinBit(PD12) | (bits & 0x0fff));
		delay_ms(intval);
		//
		bits &= 0x0fff;
		switch ((tnow % 60) / 15) {
		case 3:
			bits |= PinBit(PD12);
		case 2:
			bits |= PinBit(PD15);
		case 1:
			bits |= PinBit(PD14);
		case 0:
		default:
			bits |= PinBit(PD13);
			break;
		}
		GPIOWrite(GPIOD, bits);

		while (tnow == millis() / 1000);
		tnow = millis() / 1000;

		//Serial3.print(tmp);
		sprintf(tmp, "%04ld\n", millis());
		usart_print(&USerial3, tmp);

		/*
		digitalWrite(PB12, LOW);
		spi_transfer(SPI2, (uint8_t *) tmp, 8);
		digitalWrite(PB12, HIGH);
*/
		i = 0;
		if (usart_available(&USerial3) > 0) {
			while (usart_available(&USerial3) > 0 && i < 92) {
				tmp[i++] = (char) usart_read(&USerial3);
			}
			tmp[i] = 0;
			usart_print(&USerial3, "> ");
			usart_print(&USerial3, tmp);
			usart_print(&USerial3, "\n");
		}

	}
	return 0;
}