void init_uart() { /* Set UART pin driver states */ pinMode(D,6,INPUT); pinMode(D,7,OUTPUT); /* Remap the UART pins */ PORTD.REMAP = PORT_USART0_bm; /* 8bit */ USARTD0.CTRLB = USART_RXEN_bm|USART_TXEN_bm; USARTD0.CTRLC = USART_CMODE_ASYNCHRONOUS_gc|USART_PMODE_DISABLED_gc|USART_CHSIZE_8BIT_gc; /* 115200 baud rate with 32MHz clock */ USARTD0.BAUDCTRLA = 131; USARTD0.BAUDCTRLB = (-3 << USART_BSCALE_gp); /* Enable UART data reception interrupt */ USARTD0.CTRLA |= USART_DRIE_bm; /* Set UART data reception interrupt priority */ USARTD0.CTRLA |= (1<<5); USARTD0.CTRLA |= (1<<4); /* Connect the xprintf library to UART hardware */ xdev_out(sendch); /* Enable all interrupt levels */ PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; sei(); }
void startup_task (void *pvParameters) { (void) pvParameters; MX_GPIO_Init(); /* Init Device Library */ USBD_Init(&hUsbDeviceFS, &VCP_Desc, 0); /* Add Supported Class */ USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC); /* Add CDC Interface Class */ USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS); /* Start Device Process */ USBD_Start(&hUsbDeviceFS); xdev_out(putchar); MX_SDIO_SD_Init(); FATFS_LinkDriver(&SD_Driver, SD_Path); fsInit(); vTaskDelete(NULL); }
void start() { uint32_t temp; uint8_t getstr[20]; GPJ2CON = 0x1111; GPJ2DAT = 0x0a; uart0_init(115200); fimd_init(); xdev_out(uart0_putc); xdev_in(uart0_getc); xprintf("FA210 Tester v1\n"); while(1){ xputc('>'); xgets(getstr,15); } }
int main(void) { _U08 u8Config; ANCON0 = 0XFF; /*Desactivamos las entradas analógicas*/ ANCON1 = 0XFF; /*Desactivamos las entradas analógicas*/ Gpios_PinDirection(GPIOS_PORTD, 0, GPIOS_INPUT); /*SCL2*/ Gpios_PinDirection(GPIOS_PORTD, 1, GPIOS_INPUT); /*SDA2*/ Gpios_PinDirection(GPIOS_PORTC, 6, GPIOS_OUTPUT); /*puerto de tx uart como salida*/ (void)Uart_Init(UART_PORT1, 115200); /*velocidad a 115200 bauds*/ xdev_out(putChar); /*funcion Uart_PutChar como salida estandar*/ I2c_Init(I2C_PORT2, 100000); /*puerto I2C 2 a 100KHz de velocidad*/ I2c_Start(I2C_PORT2); /*generamos condicion start*/ (void)I2c_bTxByte(I2C_PORT2, ADDR_WRITE(0b1001101)); /*madamos direccion del sensor en modo escritura*/ (void)I2c_bTxByte(I2C_PORT2, 0x01); /*mandamos direccion a leer*/ I2c_RepeatedStart(I2C_PORT2); /*repetimos señal start*/ (void)I2c_bTxByte(I2C_PORT2, ADDR_READ(0b1001101)); /*madmaos direccion del sensor en modo lectura*/ u8Config = I2c_u8RxByte(I2C_PORT2, I2C_NACK); /*leemos dato leido y contestamos NACK*/ I2c_Stop(I2C_PORT2); /*indicamos fin de comunicacion*/ /*mostramos por serial el byte leido el cual tendra el valor de 0x40, indica sensor listo*/ xprintf("Registro config: 0x%X\r\n", (_U16)u8Config); while (1) { /*Escribe aqui tu aplicacion*/ } }
/** * * @brief Main Function * @param none * @retval none */ int main(void) { /* Set 1mSec Timer */ SysTickInit(INTERVAL); /* Initialize GPIO for the LED. */ FM3_GPIO->PDORF_f.P3 = 0; /* Set Clr(at first)*/ FM3_GPIO->PFRF_f.P3 = 0; /* Use PF3 as GPIO */ FM3_GPIO->DDRF_f.P3 = 1; /* Mode Output */ FM3_GPIO->PZRF_f.P3 = 1; /* Port Tristate */ /* Initialize UART */ UartInit(); /* To Use xprintf */ xdev_out(putch); xdev_in(getch); /* Test */ xprintf("Hello FM3 \r\n"); _delay_ms(1000); #if 0 while (1) /* loop forever */ { FM3_GPIO->PDORF_f.P3 = ~FM3_GPIO->PDORF_f.P3; /* Invert Pin */ _delay_ms(500); } #endif }
int main(void) { uint16_t i; FRESULT rc; map_io(); init_port(); InitRTCC(); uart2_init(); xdev_out(uart2_put); xdev_in(uart2_get); dbg_printf("$" PROJECT_NAME "\n"); dbg_printf("$" __DATE__ " " __TIME__ "\n"); rc = f_mount(&fatfs, "", 1); dbg_printf("$FF,f_mount,%s\n", get_rc(rc)); OpenTimer1(T1_PS_1_256 & T1_GATE_OFF & T1_SOURCE_INT & T1_IDLE_CON & T1_ON & T1_SYNC_EXT_OFF, 0xFFFF); ConfigIntTimer1(T1_INT_ON & T1_INT_PRIOR_1); OpenCapture1(IC_IDLE_STOP & IC_TIMER1_SRC & IC_INT_1CAPTURE & IC_EVERY_RISE_EDGE, IC_CASCADE_DISABLE & IC_TRIGGER_ENABLE & IC_UNTRIGGER_TIMER & IC_SYNC_TRIG_IN_DISABLE); ConfigIntCapture1(IC_INT_ON & IC_INT_PRIOR_5); _IC1IF = 0; while (1) { while (_RTCSYNC == 0); while (_RTCSYNC == 1); if (gps_pr > 0) { _T1IE = 0; float f = (float) TMR1 / gps_pr; _T1IE = 1; xprintf("%u\n", (uint16_t) (f * 1000)); } if (ngpslines > 0) { ngpslines--; if (xgets(gps_line, 128)) { xprintf("$GPS%s\n", gps_line); } } } while (0) { while (_RTCSYNC == 0); while (_RTCSYNC == 1); if (gps_pr > 0) { _T1IE = 0; float f = (float) TMR1 / gps_pr; _T1IE = 1; xprintf("%u\n", (uint16_t) (f * 1000)); } } return (EXIT_SUCCESS); }
void start() { uint8_t data_out[10]={0xff, 0xff, 0xff,0,0,0,0}; uint8_t data_in[10]={0xff, 0xff, 0xff,0,0,0,0}; uart_init(DEBUG_COM); xdev_in(get_char); xdev_out(put_char); xprintf("\nHello, 6410!\n"); // delay(DELAY_1S_VAL); // xprintf("init si470x..."); // if (si470x_init()){ // xprintf("ok\n"); // } // else { // xprintf("failed\n"); // } // delay(DELAY_1S_VAL); // xprintf("powerdown si470x..."); // if (si470x_powerdown()){ // xprintf("ok\n"); // } // else{ // xprintf("failed\n"); // } // delay(DELAY_1S_VAL); // xprintf("powerup si470x..."); // if (si470x_powerup()){ // xprintf("ok\n"); // } // else{ // xprintf("failed\n"); // } while(1){ } //test_FMRX(); // test_FMRXrds(); // Tunes to an RDS station and populates // variables with RDS information. }
int main(void) { ANCON0 = 0XFF; /*Desactivamos las entradas analogicas*/ ANCON1 = 0XFF; /*Desactivamos las entradas analogicas*/ System_EnablePLL(); /*uC a 48MHz*/ HD44780_Init(); /*inicliza el LCD*/ xdev_out(HD44780_WriteData); /*establece elcd como salida*/ xprintf("Tengo %d edad", (_U16)29); /*imprime una cadena de caracteres*/ HD44780_SetCursor(2, 0); /*se cambia el cursor a la linea 2 columna 5*/ xprintf("Hoy es %d de %d", (_U16)30, (_U16)1984); /*se imprime otra linea de caracteres*/ while (1) { } }
// ----------------------------------------------------------------------------- HAL_StatusTypeDef BSP_UART_Init(void) { HAL_StatusTypeDef result; debug_uart1_handle.Instance = USARTx; debug_uart1_handle.Init.BaudRate = 115200; debug_uart1_handle.Init.WordLength = UART_WORDLENGTH_8B; debug_uart1_handle.Init.StopBits = UART_STOPBITS_1; debug_uart1_handle.Init.Parity = UART_PARITY_NONE; debug_uart1_handle.Init.HwFlowCtl = UART_HWCONTROL_NONE; debug_uart1_handle.Init.Mode = UART_MODE_TX_RX; debug_uart1_handle.Init.OverSampling = UART_OVERSAMPLING_16; result = HAL_UART_Init(&debug_uart1_handle); xdev_out(UART_Send_Byte); return result; }
/** xprintf need functions api setup */ void xprintf_setup(void) { if (xprintf_setup_flag) { return; } console_uart = uart_get_dev(CONSOLE_UART_ID); console_uart->uart_open(BOARD_CONSOLE_UART_BAUD); xdev_in(console_getchar); xdev_out(console_putchar); #if ENABLE_BANNER == 1 embarc_print_banner(); #endif xprintf("embARC Build Time: %s, %s\r\n", __DATE__, __TIME__); #if defined(__GNU__) xprintf("Compiler Version: ARC GNU, %s\r\n", __VERSION__); #else xprintf("Compiler Version: Metaware, %s\r\n", __VERSION__); #endif xprintf_setup_flag = 1; }
int main(void) { _S08 i8Temp; ANCON0 = 0XFF; /*Desativamos las entradas analógicas*/ ANCON1 = 0XFF; /*Desativamos las entradas analógicas*/ Gpios_PinDirection(GPIOS_PORTD, 0, GPIOS_INPUT); /*SCL2*/ Gpios_PinDirection(GPIOS_PORTD, 1, GPIOS_INPUT); /*SDA2*/ Gpios_PinDirection(GPIOS_PORTC, 6, GPIOS_OUTPUT); /*puerto de tx uart como salida*/ (void)Uart_Init(UART_PORT1, 115200); /*velocidad a 115200 bauds*/ xdev_out(putChar); /*funcion Uart_PutChar como salida estandar*/ I2c_Init(I2C_PORT2, 100000); /*puerto I2C 2 a 100KHz de velocidad*/ while (1) { i8Temp = Tc74ax_ReadTemp(TC74A5); /*mostramos por serial el byte leido el cual tendra el valor de la temp ambiental*/ xprintf("Temperatura ambiente: %d\r", (_S16)i8Temp); Delays_ms(1000); } }
/* * See the serial.h header file. */ void vSerialPortInit( eCOMPort ePort, unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength ) { USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* Create the queues used to hold Rx/Tx characters. */ xRxedChars[ePort] = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) ); xCharsForTx[ePort] = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) ); /* If the queue/semaphore was created correctly then setup the serial port hardware. */ if( ( xRxedChars[ePort] == serINVALID_QUEUE ) || ( xCharsForTx[ePort] == serINVALID_QUEUE ) ) return; if (ePort == serCOM1) { /* Enable USART1 and GPIO clocks */ USARTx_APBPERIPHCLOCK( USARTx_CLK, ENABLE ); RCC_AHBPeriphClockCmd( USARTx_TX_GPIO_CLK, ENABLE ); RCC_AHBPeriphClockCmd( USARTx_RX_GPIO_CLK, ENABLE ); /* Connect PXx to USARTx_Tx */ GPIO_PinAFConfig(USARTx_TX_GPIO_PORT, USARTx_TX_SOURCE, USARTx_TX_AF); /* Connect PXx to USARTx_Rx */ GPIO_PinAFConfig(USARTx_RX_GPIO_PORT, USARTx_RX_SOURCE, USARTx_RX_AF); } else { /* Enable USART2 and GPIO clocks */ USARTy_APBPERIPHCLOCK( USARTy_CLK, ENABLE ); RCC_AHBPeriphClockCmd( USARTy_TX_GPIO_CLK, ENABLE ); RCC_AHBPeriphClockCmd( USARTy_RX_GPIO_CLK, ENABLE ); /* Connect PXx to USARTx_Tx */ GPIO_PinAFConfig(USARTy_TX_GPIO_PORT, USARTy_TX_SOURCE, USARTy_TX_AF); /* Connect PXx to USARTx_Rx */ GPIO_PinAFConfig(USARTy_RX_GPIO_PORT, USARTy_RX_SOURCE, USARTy_RX_AF); } /* Configure USART Tx and Rx as alternate function push-pull */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; if (ePort == serCOM1) { GPIO_InitStructure.GPIO_Pin = USARTx_TX_PIN; GPIO_Init(USARTx_TX_GPIO_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = USARTx_RX_PIN; GPIO_Init(USARTx_RX_GPIO_PORT, &GPIO_InitStructure); } else { GPIO_InitStructure.GPIO_Pin = USARTy_TX_PIN; GPIO_Init(USARTy_TX_GPIO_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = USARTy_RX_PIN; GPIO_Init(USARTy_RX_GPIO_PORT, &GPIO_InitStructure); } /* Configure USART parameters */ USART_InitStructure.USART_BaudRate = ulWantedBaud; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No ; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init((ePort == serCOM1) ? USARTx : USARTy, &USART_InitStructure); /* Configure interrupts controller */ NVIC_InitStructure.NVIC_IRQChannel = (ePort == serCOM1) ? USARTx_IRQChannel : USARTy_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init( &NVIC_InitStructure ); USART_ITConfig((ePort == serCOM1) ? USARTx : USARTy, USART_IT_RXNE, ENABLE); /* Enable the USART */ USART_Cmd((ePort == serCOM1) ? USARTx : USARTy, ENABLE); /* Init the xprintf library on debug interface */ if (ePort == serCOM1) xdev_out(vPutCharToUSARTx); }
//////////////////// MAIN ///////////////////////////// int main (void) { int i; float temperature, pressure; float QNHPA; const int QNH_Calib=2; //AO: TODO Make this settable at startup and //write to nvRAM. float altitude_m,altitude_ft; struct ms5611_vars baro; //Coordinates for writing values on screen: uint8_t ALTFT_x=190, ALTFT_y=100; uint8_t QNH_x=90,QNH_y=120; //Location on screen to print QNH uint8_t ALTM_x=QNH_x, ALTM_y=140; uint8_t BARO_x=QNH_x,BARO_y=160; //Location on screen to print BARO uint8_t TEMP_x=QNH_x,TEMP_y=180; //Location on screen to print TEMP //TODO: Remove obsolete code. //TODO: Baro_Delay_Max becomes a #define. // int GPIO_Delay_Max =250; //Led's will stay on for this many ms. // int BARO_Delay_Max =200; //Baro refresh rate. //Display related: int a; // Both single speed and double speed access works. // Single speed is slower, needs less memory, vice versa for double speed. //u8g_InitComFn(&u8g, &u8g_dev_ssd1306_128x64_i2c, u8g_com_hw_i2c_fn); u8g_InitComFn(&u8g, &u8g_dev_ssd1306_128x64_2x_i2c, u8g_com_hw_i2c_fn); // Initialize hardware: disable_JTAG(); //So that some pins (notably LED) are freed up for use. init_BKP(); //Battery backup/RTC module init. init_ENC(); //Initialize ports connected to encoder. init_LED_GPIO(); //Initialize ports connected to LED. /* Init Chan's Embedded String Functions (xprintf etc) */ xdev_out(uart_putc); xdev_in(uart_getc); init_USART1(); // Initialize USART1: uart_open (USART1, 115200, 0); //USART2 is not supported. if (SysTick_Config(SystemCoreClock/1000)) while (1); // Every 1 msec, the timer will trigger a call to the SysTick_Handler. xprintf ("STM32F103 Naze32/Flip32.\n\r"); xprintf("System core clock rate is %d Hz\n\r",SystemCoreClock); xprintf("QNH calibration value set to: %d. \n\r",QNH_Calib); //Turn off LED LED_OFF(); QNH = BKP_ReadBackupRegister (BKP_DR1); QNH=1013; //TODO: Naze32 has no provision for backup battery connection. // The pin V_bat is connected to supply... // The function works correctly. Needs a board with V_bat wired correctly. if (QNH<950) //Quick sanity check. QNH=950; else if (QNH>1050) QNH=1050; ms5611_init(&baro); ms5611_measure(&baro); ms5611_calculate(&baro); QNHPA = (QNH+QNH_Calib)*100; //Convert to Pa. baro.pressure is also in pa. //Note: Uncomment following line for AGL measurement. //QNHPA= baro.pressure; BARO_Delay = BARO_Delay_Max; //Counts the number of timer ticks so far. //Display an introductory info message and wait 3s before starting: u8g_FirstPage(&u8g); do { draw_Intro(); } while ( u8g_NextPage(&u8g) ); i=0; while(i < INTRO_WAIT_MS){ //Keep info screen up for some time. if (TimerEventFlag==TRUE){ TimerEventFlag=FALSE; ++i; } } while (1) { if (TimerEventFlag==TRUE){ // QNH adjustment used to live here but because of the long delay // in calculating the altitude, it was moved into the ISR. TimerEventFlag=FALSE; } //Time to update barometer?: if (BARO_Delay >=BARO_Delay_Max){ BARO_Delay=0; //LED_ON(); //To check utilization. ms5611_measure(&baro); ms5611_calculate(&baro); //Note: Comment following line for AGL measurement. QNHPA = (QNH+QNH_Calib)*100;//Convert to Pa. baro.pressure is also in pa. altitude_m = 44330*(1- powf((baro.pressure/QNHPA),(0.19029495))); //m altitude_ft =altitude_m *3.28084; //ft. } //END: if (BARO_Delay >=BARO_Delay_Max) if (printQNH==TRUE){ //Time to print QNH: printQNH=FALSE; u8g_FirstPage(&u8g); do { draw_qnh((int)baro.pressure/100,(int)baro.temperature/100,(int)altitude_m,(int)altitude_ft,(int)QNH); } while ( u8g_NextPage(&u8g) ); BKP_WriteBackupRegister (BKP_DR1, QNH); } else if (printINFO==TRUE){ u8g_FirstPage(&u8g); do { draw_Intro(); } while ( u8g_NextPage(&u8g) ); }else{ u8g_FirstPage(&u8g); do { draw_alt((int)baro.pressure/100,(int)baro.temperature/100,(int)altitude_m,(int)altitude_ft,(int)QNH); } while ( u8g_NextPage(&u8g) ); } //LED_OFF(); //To check utilization. } //END: while(1) } //END: main
/* ------------------------------------------------------------------------- */ int main() { /* init the software uart */ uart_init(); /* init the xprintf library */ xdev_out(uart_put_char); /* simple greeting message */ xprintf("\r\n> TX device ready\r\n"); /* init hardware pins */ nrf24_init(); /* Channel #2 , payload length: 4 */ nrf24_config(2,4); /* Set the device addresses */ nrf24_tx_address(tx_address); nrf24_rx_address(rx_address); while(1) { /* Fill the data buffer */ data_array[0] = 0x00; data_array[1] = 0xAA; data_array[2] = 0x55; data_array[3] = q++; /* Automatically goes to TX mode */ nrf24_send(data_array); /* Wait for transmission to end */ while(nrf24_isSending()); /* Make analysis on last tranmission attempt */ temp = nrf24_lastMessageStatus(); if(temp == NRF24_TRANSMISSON_OK) { xprintf("> Tranmission went OK\r\n"); } else if(temp == NRF24_MESSAGE_LOST) { xprintf("> Message is lost ...\r\n"); } /* Retranmission count indicates the tranmission quality */ temp = nrf24_retransmissionCount(); xprintf("> Retranmission count: %d\r\n",temp); /* Optionally, go back to RX mode ... */ nrf24_powerUpRx(); /* Or you might want to power down after TX */ // nrf24_powerDown(); /* Wait a little ... */ _delay_ms(10); } }
int main() { uint8_t i, change; uint8_t hand; uint32_t timeout = 0; uart_init(); xdev_out(uart_putchar); // Determine which hand this is from PE2 // Left is hand 0, right is hand 1 PORTE = (1 << 2); DDRE = 0; hand = (PINE & 0x04) ? 0 : 1; xprintf("\r\nHand %d\r\n", hand); // Initialise NRF24 // Set the last byte of the address to the hand ID rx_address[4] = hand; nrf24_init(); nrf24_config(CHANNEL, sizeof msg); nrf24_tx_address(tx_address); nrf24_rx_address(rx_address); matrix_init(); msg[0] = hand & 0x01; msg[1] = 0; msg[2] = 0; // Set up LED and flash it briefly DDRE |= 1<<6; PORTE = 1<<6; _delay_ms(500); PORTE = 0; get_voltage(); check_voltage(); // Scan the matrix and detect any changes. // Modified rows are sent to the receiver. while (1) { timeout++; matrix_scan(); for (i=0; i<ROWS; i++) { change = matrix_prev[i] ^ matrix[i]; // If this row has changed, send the row number and its current state if (change) { if (DEBUG) xprintf("%d %08b -> %08b %ld\r\n", i, matrix_prev[i], matrix[i], timeout); msg[1] = i; msg[2] = matrix[i]; nrf24_send(msg); while (nrf24_isSending()); timeout = 0; } matrix_prev[i] = matrix[i]; } // Sleep if there has been no activity for a while if (timeout > SLEEP_TIMEOUT) { timeout = 0; enter_sleep_mode(); } } }
void initUART() { uart0_init(); xdev_out(uart0_putc); xdev_in(uart0_getc); }
void print_set_sendchar(int8_t (*sendchar_func)(uint8_t)) { xdev_out(sendchar_func); }