static void usart_rx_task(void *pvParameters) { uint8_t i=0; char data_buf[BUFFER_LENGTH]; for (;;) { if (pdPASS == xQueueReceive(usart_rxq, &data_buf[i], portMAX_DELAY)) { #ifdef USART_ECHO USART_SendByte(data_buf[i]); #endif if (data_buf[i]=='\r') { data_buf[i+1]='\0'; if (i) { USART_SendString("\r\nReceived data: "); USART_SendString(data_buf); }; #ifndef USART_ECHO USART_SendByte('\r'); #endif USART_SendByte('\n'); i=0; } else if (i<BUFFER_LENGTH-1) i++; } } vTaskDelete(NULL); }
int main(void) { rcc_init(); GPIO_init(); USART2_init(); USART_SendString("Hello World\n"); while (1) { if (USART_ReceiveChar() == 'g'){ USART_SendString("Received your message\r\n"); } } }
int main(void) { GPIO_Config(); USART_Config(); USART_SendString("Hello"); USART_SendByte('!'); USART_SendString("\r\n"); xTaskCreate(vLedTask,(signed char*) "LedTask", configMINIMAL_STACK_SIZE, (void *) NULL, tskIDLE_PRIORITY + 2, NULL); vTaskStartScheduler(); }
int main(void) { SysTick_Config(SystemCoreClock/1000); STM_EVAL_LEDInit(LED3); // Oranzova STM_EVAL_LEDInit(LED4); // Zelena STM_EVAL_LEDInit(LED5); // Cervena STM_EVAL_LEDInit(LED6); // Modra STM_EVAL_LEDOn(LEDG); Delay(1000); STM_EVAL_LEDOff(LEDG); Init_Measure(); Init_Comunication(); init_output(); timer_init(); STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI); USART_SendString(USART6, "\nSwitching Power Source Welcome\n"); while(1) { if((Time-Last_Blink > 75) && output){ STM_EVAL_LEDToggle(LEDB); Last_Blink=Time; }else if(Time-Last_Blink > 75){ STM_EVAL_LEDOn(LEDB); } loop++; f = loop/(Time/1000); } }
void proccess_rx(void) { uint32_t u, i; switch (rx_buffer[0]) { case 'q': GPIO_SetBits(GPIOC, GPIO_Pin_0); USART_SendString(USART6, "PC0 ON\n"); break; case 'a': GPIO_ResetBits(GPIOC, GPIO_Pin_0); USART_SendString(USART6, "PC0 OFF\n"); break; default: USART_SendString(USART6, "Unknown command\n"); break; } }
int main(void) { TSDS18x20 DS18x20; TSDS18x20 *pDS18x20 = &DS18x20; char buffer[10]; // AVR serial port init USART_init(103); // Init DS18B20 sensor if (DS18x20_Init(pDS18x20,&PORTD,PD5)) { USART_SendString("Error!!! Can not find 1-Wire device attached on the bus!"); return -1; } else USART_SendString("1-Wire device detected on the bus."); USART_SendChar(0x0D); // Set DS18B20 resolution to 9 bits. DS18x20_SetResolution(pDS18x20,CONF_RES_9b); DS18x20_WriteScratchpad(pDS18x20); // Initiate a temperature conversion and get the temperature reading if (DS18x20_MeasureTemperature(pDS18x20)) { // Send the temperature over serial port USART_SendString("Current Temperature is: "); dtostrf(DS18x20_TemperatureValue(pDS18x20),9,4,buffer); USART_SendString(buffer); USART_SendChar('C'); USART_SendChar(0x0D); } else USART_SendString("CRC error!!!"); while(1); return 0; }
void USART_SendNumber(USART_TypeDef* USARTx, uint32_t n){ char buffer[15]; char *p; buffer[14] = 0; p = buffer+14; while(n>0){ p--; *p = (n%10)+'0'; n = n/10; } USART_SendString(USARTx, p); }
void USART_SendHex(USART_TypeDef* USARTx, uint32_t n){ char buffer[11]; uint8_t i; buffer[0] = '0'; buffer[1] = 'x'; buffer[10] = 0; for(i=0; i<8; i++){ buffer[9-i] = "0123456789ABCDEF"[n & 0xF]; n = n >> 4; } USART_SendString(USARTx, buffer); }
int main(void) { SysTick_Config(SystemCoreClock / 1000); STM_EVAL_LEDInit(LED3); // Oranzova STM_EVAL_LEDInit(LED4); // Zelena STM_EVAL_LEDInit(LED5); // Cervena STM_EVAL_LEDInit(LED6); // Modra GPIOD->BSRRL = LED_G; Delay(1000); GPIOD->BSRRH = LED_G; Init_Comunication(); timer_init(); USART_SendString(USART6, "\nSwitching Power Source Welcome\n"); while (1) { GPIOD->ODR ^= LED_B; Delay(100); } }
void initialize( void ) { CPU_PRESCALE(0); USART_Init(BAUD_RATE); USART_Transmit('\f'); // Send form feed to clear the terminal. USART_SendString("WunderBoard initializing...\r\n"); USART_SendString("\tSetting ADC prescaler and disabling free running mode...\r\n"); SetupADC(ADC_PRESCALER_32, FALSE); USART_SendString("\tEnabling ADC...\r\n"); ADCEnable(); USART_SendString("\tSetting ADC reference to Vcc...\r\n"); ADCSetReference(ADC_REF_VCC); // Configure IO // USART_SendString("\tConfiguring IO...\r\n"); //DDRx corresponds to PORTx/PINx, dependng on direction of data flow -- PORT for output, PIN for input DDRA = 0x00; // Buttons and switches DDRB = 0xE7; // Red enable, green enable and audio out DDRC = 0xff; // Discrete LEDs DDRE = 0x47; // LED Column DDRF = 0x00; // Accelerometer // Disable pullups and set outputs low // PORTA = 0x00; PORTB = 0x01; PORTC = 0x81; PORTE = 0x00; PORTF = 0x00; //Set OC1A to toggle TCCR1A = 0b01000000; // Clk/64 and CTC mode TCCR1B = 0b00001011; OCR1A = 24; USART_SendString("\tSetting SPI\r\n"); //Set the SPI bus appropriately to use the LED array SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0); }
void proccess_rx(void){ uint32_t u, i; switch(rx_buffer[0]){ case 'g': u = Actual_U; i = Actual_I; USART_SendString(USART6, "U:"); USART_SendNumber(USART6, u); USART_SendString(USART6, ", I:"); USART_SendNumber(USART6, i); USART_SendString(USART6, "\n"); break; case 's': if(rx_pointer>1){ u = StringToInt(rx_buffer+1, 5); i = StringToInt(rx_buffer+6, 5); Set_U = u; Set_I = i; USART_SendString(USART6, "OK\n"); }else{ u = Set_U; i = Set_I; USART_SendString(USART6, "Set U:"); USART_SendNumber(USART6, u); USART_SendString(USART6, ", Set I:"); USART_SendNumber(USART6, i); USART_SendString(USART6, "\n"); } break; case 'o': if(rx_pointer>1){ output = (rx_buffer[1]=='1'); } USART_SendString(USART6, output?"Output ON\n":"Output OFF\n"); break; case 'q': GPIO_SetBits(GPIOC, GPIO_Pin_0); USART_SendString(USART6, "PC0 ON\n"); break; case 'a': GPIO_ResetBits(GPIOC, GPIO_Pin_0); USART_SendString(USART6, "PC0 OFF\n"); break; default: USART_SendString(USART6, "Unknown command\n"); break; } }
int main(int argc, char **argv) { initialize(); clear_array(); //Message to display on serial console. //USART_SendString("\tHello world.\r\n"); char str [33]; while(1){ PORTC = PINA; //Creating the "X": int i, j, k; //printf("\tHello \r\n"); //IF no button pressed, light up as green if (PORTC != 0b00000001) { //clear_array(); for (i = 7; i >= 0; i--) { PORTE = i; led_green(7-i, 7-i); led_green(7-i, i); _delay_ms(0.1); #ifdef DEBUG USART_SendString("\t\r\nX: "); USART_Transmit(itoa(7-i, str, 10)); USART_SendString("\t\r\nY(top): "); USART_Transmit(itoa(7-i, str, 10)); USART_SendString("\t\r\nY(bottom): "); USART_Transmit(itoa(i, str, 10)); #endif set_array_green(0); } } //IF button 1 is pressed, light up as red if (PORTC & 0b00000010) { clear_array(); for (i = 7; i >= 0; i--) { PORTE = i; led_red(7-i, 7-i); led_red(7-i, i); _delay_ms(0.1); #ifdef DEBUG USART_SendString("\t\r\nX: "); USART_Transmit(itoa(7-i, str, 10)); USART_SendString("\t\r\nY(top): "); USART_Transmit(itoa(7-i, str, 10)); USART_SendString("\t\r\nY(bottom): "); USART_Transmit(itoa(i, str, 10)); #endif set_array_red(0); } } //IF button 5 is pressed, light up as blue. if (PORTC & 0b00100000) { clear_array(); for (i = 7; i >= 0; i--) { PORTE = i; led_blue(7-i, 7-i); led_blue(7-i, i); _delay_ms(0.1); #ifdef DEBUG USART_SendString("\t\r\nX: "); USART_Transmit(itoa(7-i, str, 10)); USART_SendString("\t\r\nY(top): "); USART_Transmit(itoa(7-i, str, 10)); USART_SendString("\t\r\nY(bottom): "); USART_Transmit(itoa(i, str, 10)); #endif set_array_blue(0); } } } }