int main(void) { u8 R='b'; delay_init(72); //延时函数初始化 usart1_init(); //串口初始化 NRF24L01_Init(); //初始化NRF24L01 LED(); while(NRF24L01_Check()); //检查NRF24L01是否在位. while(1) { NRF24L01_TX_Mode(); if(USART_GetFlagStatus(USART1, USART_FLAG_RXNE)) { R =USART_ReceiveData(USART1); USART_ClearFlag(USART1, USART_FLAG_TC); USART_SendData(USART1, USART_ReceiveData(USART1)); USART_ClearFlag(USART1, USART_FLAG_RXNE); } NRF24L01_TxPacket(&R); if(R=='a') GPIO_ResetBits(GPIOE, GPIO_Pin_5); //PE=0,LED亮 if(R=='b') GPIO_SetBits(GPIOE, GPIO_Pin_5); //PE=1,LED灭 } }
usart_t usart_init (const usart_cfg_t *cfg) { usart_dev_t *dev = 0; uint16_t baud_divisor; if (cfg->baud_rate == 0) baud_divisor = cfg->baud_divisor; else baud_divisor = USART_BAUD_DIVISOR (cfg->baud_rate); #if USART0_ENABLE if (cfg->channel == 0) { usart0_init (baud_divisor); dev = &usart0_dev; } #endif #if USART1_ENABLE if (cfg->channel == 1) { usart1_init (baud_divisor); dev = &usart1_dev; } #endif dev->read_timeout_us = cfg->read_timeout_us; dev->write_timeout_us = cfg->write_timeout_us; return dev; }
int main(void) { usart0_init(25, 8, 1, USART_PARITY_EVEN,1); //38400 usart1_init(25, 8, 1, USART_PARITY_DISABLED,0); //TODO check oi_alternative OI_ALTERNATE_BAUD_RATE _delay_ms(333); oi_switch_baud_rate(); _delay_ms(333); oi_init(); oi_full_mode(); int i; int val; for (i = 0; i < 10; i++) { val = i % 2; oi_set_leds(val, val, val, val, 0xFF * val, 0xFF); _delay_ms(50); } oi_init(); //input_capture_test(); printf0("Hello world!\r\n"); printf0(" 0x%02X 0x%02X 0x%02X", UCSR0A, UCSR0B, UCSR0C); _delay_ms(3000); doSweepLoop(); doPingLoop(); doIrLoop(); servo_test(); }
/** * @brief Low level serial driver configuration and (re)start. * * @param[in] sdp pointer to a @p SerialDriver object * @param[in] config the architecture-dependent serial driver configuration. * If this parameter is set to @p NULL then a default * configuration is used. * * @notapi */ void sd_lld_start(SerialDriver * sdp, const SerialConfig * config) { if (config == NULL) { config = &default_config; } if (sdp->state == SD_STOP) { #if MSP430X_SERIAL_USE_USART0 == TRUE if (&SD0 == sdp) { usart0_init(config); } #endif #if MSP430X_SERIAL_USE_USART1 == TRUE if (&SD1 == sdp) { usart1_init(config); } #endif #if MSP430X_SERIAL_USE_USART2 == TRUE if (&SD2 == sdp) { usart2_init(config); } #endif #if MSP430X_SERIAL_USE_USART3 == TRUE if (&SD3 == sdp) { usart3_init(config); } #endif } }
int main(void){ SystemInit(); usart1_init(); // enable clock for CRC unit RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE); unsigned int data = 0x12345678; unsigned int result = CRC_CalcCRC(data); printf("single word crc calculation:\r\n"); printf(" data = 0x%08x\r\n", (unsigned int)data); printf(" result = 0x%08x\r\n", (unsigned int)result); CRC_ResetDR(); int len_datablock = sizeof(data_block); result = CRC_CalcBlockCRC(data_block, len_datablock); printf("block crc calculation (%d bytes):\r\n", len_datablock); printf(" data block can be found in source.\r\n"); printf(" result = 0x%08x\r\n", result); for(;;) { } return 0; }
static void init(void) { usart1_init(115200, buf_in, ARR_LEN(buf_in), buf_out, ARR_LEN(buf_out)); rtc_init(); sei(); puts_P(PSTR("Init complete\n\n")); }
int main() { // create the UART queue queue_uart_char = xQueueGenericCreate(5, 10, 0); queue_lua_commands = xQueueGenericCreate(5, MAX_STRLEN + 1, 0); queue_stepmotor = xQueueGenericCreate(5, sizeof(int), 0); dac_init(); ledlib_init(); usart1_init(9600, &queue_uart_char); task_lua_init(&queue_lua_commands); task_stepmotor_init(&queue_stepmotor); // just send a message to indicate that it worksa usart1_write_string ("\r\nInit complete with motors\r\n"); xTaskCreate(task_receive_uart_chars, (signed char*)"uart-chars", 100, 0, 1, 0); vTaskStartScheduler(); /* * Should never reach here! */ ledlib_set_error_state(); }
int main(){ SystemCoreClockUpdate(); usart1_init(9600); char c; while(1){ //TODO c = usart1_getc(); usart1_putc(c); } }
int main(void){ SystemInit(); usart1_init(); adc_init(); for(;;) { printf("core temperature %d\r\n", adc_get_coretemp()); } return 0; }
int main() { int i=500000; while(i--);; gpio_init(); usart1_init(); //init_i2c(); printf("I2C init done\n\r"); i2c_detect(); char b = i2c_read(MPU6050,0x0); printf("b == %x \n", b); }
void init(void) { // allow poer to stabilize _delay_ms(250); // port settings DDRC = 0xFF; PORTC = 0x00; // init usart usart1_init( USART_BAUD_4800, USART_FRAME_8N1 ); return; }
static void init(void) { usart1_init(115200, buf_in, ARR_LEN(buf_in), buf_out, ARR_LEN(buf_out)); sei(); printf("Running init\n"); int rc = sd_init(); if (rc == 0) { puts_P(PSTR("Init complete\n\n")); } else { puts_P(PSTR("\n\n\nInit failed\n\n")); // Hard_reset(); } }
int main(void){ usart1_init(); can1_init(); nvic_init(); dma_init(); while(1){ if((obd_mode != 0xff) && (obd_pid != 0xff)){ obd_cmd_parse(obd_mode, obd_pid); } // while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET); // while(DMA_GetFlagStatus(DMA1_FLAG_TC4) == RESET); } }
void IAC_Init(void) { delay_init(72); //延时函数初始化 Nvic_Init(); //中断初始化 LED_Init(); //led初始化 KEY_Init(); //按键初始化 OLED_Init(); //oled初始化 //Draw_LibLogo(); //logo paramLoad(); //pid参数初始化 State_Display();//OLED数据显示 Moto_Init(); //电机初始化//200hz usart1_init(72,115200); //串口1初始化 摄像头 usart2_Init(36,9600); //ks103数据 9600 usart3_config(460800); //串口3初始化 上位机 TIM3_Init(2500); //定时器初始化 2.5MS }
/** * @brief Low level serial driver configuration and (re)start. * * @param[in] sdp pointer to a @p SerialDriver object * @param[in] config the architecture-dependent serial driver configuration. * If this parameter is set to @p NULL then a default * configuration is used. * * @notapi */ void sd_lld_start(SerialDriver *sdp, const SerialConfig *config) { if (config == NULL) config = &default_config; #if USE_MSP430_USART0 if (&SD1 == sdp) { usart0_init(config); return; } #endif #if USE_MSP430_USART1 if (&SD2 == sdp) { usart1_init(config); return; } #endif }
static void init(void) { usart1_init(115200, buf_in, ARR_LEN(buf_in), buf_out, ARR_LEN(buf_out)); sysclock_init(); adc_init(1, AVCC, 4); can_init(); vnh2sp30_init(); vnh2sp30_active_break_to_Vcc(); SET_PIN_MODE(NEUT_PORT, NEUT_PIN, INPUT_PULLUP); SET_PIN_MODE(IGN_PORT, IGN_PIN, OUTPUT); IGNITION_UNCUT(); can_subscribe(PADDLE_STATUS); can_subscribe(NEUTRAL_ENABLED); can_subscribe(GEAR_STOP_BUTTON); can_subscribe(RESET_GEAR_ESTIMATE); sei(); puts_P(PSTR("Init complete\n\n")); }
void GPS_int() { NVIC_InitTypeDef NVIC_InitStructure; char GPS_init1_Char[]="unlogall true\r\n";//42 char GPS_init2_Char[]="log bestposb ontime 0.2\r\n"; char GPS_init3_Char[]="log bestvelb ontime 0.2\r\n"; uint8_t i; usart1_init(); Delay(300); for (i=0;i<15;i++) { while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET); USART_SendData(USART1, (uint16_t) GPS_init1_Char[i]); } Delay(50); for (i=0;i<25;i++) { while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET); USART_SendData(USART1, (uint16_t) GPS_init2_Char[i]); } Delay(50); for (i=0;i<25;i++) { while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET); USART_SendData(USART1, (uint16_t) GPS_init3_Char[i]); } /* Enable the USART1 通信端口 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; /* 抢占优先级 */ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); GPS_Buff[0]=0xaa; GPS_Buff[1]=0x44; GPS_Buff[2]=0x12; }
int usart_main(int argc, char *argv[]) { cli(); local::system_init(); usart0_init(57600UL); usart1_init(57600UL); sei(); PORTD = 0xFF; _delay_ms(100); PORTD = 0x00; while (1) { if (!usart0_is_empty()) { /* #if 0 uint8_t hex = usart0_top_char(); usart0_pop_char(); #else uint8_t ascii = usart0_top_char(); usart0_pop_char(); uint8_t hex = ascii2hex(ascii); #endif uint16_t num = 0xABCD; usart1_push_char(hex2ascii((num >> 12) & 0x0F)); usart1_push_char(hex2ascii((num >> 8) & 0x0F)); usart1_push_char(hex2ascii((num >> 4) & 0x0F)); usart1_push_char(hex2ascii(num & 0x0F)); */ uint8_t ascii = usart0_top_char(); usart0_pop_char(); uint8_t hex = ascii2hex(ascii); PORTA = hex; usart0_push_char(ascii); } if (!usart1_is_empty()) { /* #if 0 uint8_t hex = usart1_top_char(); usart1_pop_char(); #else uint8_t ascii = usart1_top_char(); usart1_pop_char(); uint8_t hex = ascii2hex(ascii); #endif uint16_t num = 0xABCD; usart1_push_char(hex2ascii((num >> 12) & 0x0F)); usart1_push_char(hex2ascii((num >> 8) & 0x0F)); usart1_push_char(hex2ascii((num >> 4) & 0x0F)); usart1_push_char(hex2ascii(num & 0x0F)); */ uint8_t ascii = usart1_top_char(); usart1_pop_char(); uint8_t hex = ascii2hex(ascii); PORTA = hex; usart1_push_char(ascii); } //sleep_mode(); } return 0; }
/*! Larsmarks code */ void init_usb_usart(unsigned char baudrate) { usart1_init(baudrate); //Make printf work as output to USB fdevopen((void*)usart1_transmit, (void*)usart1_receive_loopback); }
void usart_init(void) { usart1_init(); }
/** * @brief Main program. * @param None * @retval None */ int main(void) { int i; char ch = 'a'; int leftright, forwardbackward, throttle, trim; char buffer[100]; int matches; /* GPIOC Periph clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); /* Configure PC10 in output pushpull mode */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOC, &GPIO_InitStructure); /* Configure PA15 in input mode, no pullup/down */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); usart1_init(); // USART_IT_RXNE: Receive Data register not empty interrupt. //USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //USART_ITConfig(USART1, USART_IT_TXE, ENABLE); //NVIC_Config(); // disable error interrupts from USART1 (EIE=0) //USART1->CR3 &= ~(1 << 0); leftright = 126; forwardbackward = 126; throttle = 0; trim = 148; if (!writebuffer) { writebuffer = buffer1; readbuffer = buffer2; } { /* uint32_t dest[10]; */ /* uint32_t src[10] = {0,1,2,3,4,5,6,7,8,9}; */ /* __aeabi_memcpy(dest, src, 10); */ /* memcpy(dest, src, 10); */ } printf("Starting...\r\n"); i = 20; while (1) { //send_command(132, 126, 24, 150); //send_command(leftright, forwardbackward, throttle, trim); // Channel command intervals: // A: 120 ms // B: 180 ms // But it seems that the heli doesn't care, so we can have longer intervals //delay_ms(180); if (usart1_receive_char(&ch)) { usart1_send_char(ch); } //delay_ms(1000); // USART_ITConfig(USART1, USART_IT_RXNE, DISABLE); // if (new_message) { // strcpy(buffer, readbuffer); // new_message = 0; // USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); // printf("new message: \"%s\"\r\n", buffer); // matches = sscanf((const char *)buffer, "%d %d %d", &leftright, &forwardbackward, &throttle); // if (matches == 3) { // printf("new controls: %d %d %d\r\n", leftright, forwardbackward, throttle); // } // } else { // USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); // } //detect_and_print_pulses(); //delay_ms(500); // GPIOC->BSRR = BSRR_VAL; // delay_us(600); // GPIOC->BRR = BSRR_VAL; // delay_us(10); } }
void os_usart1_init(int baudrate){ usart1_init(baudrate); usart1_tx_mutex_id = osMutexCreate(osMutex(usart1_tx_mutex)); usart1_rx_mutex_id = osMutexCreate(osMutex(usart1_rx_mutex)); }
/******************************************************************************* * Function Name :void TaskStart(void) * Description :任务启动 * Input : * Output : * Other : * Date :2012.04.18 11:48:23 *******************************************************************************/ static void TaskStart(void) { OS_ERR err; led_init(); usart1_init(115200); SPI_Config() ; SysTickInit(); OSTaskCreate( (OS_TCB *)&task1TCB, (CPU_CHAR *)"Task1", (OS_TASK_PTR)Task1, (void *)0, (OS_PRIO )TASK1_PRIO, (CPU_STK *)&task1_stk[0], (CPU_STK_SIZE)TASK1_STK_SIZE / 10, (CPU_STK_SIZE)TASK1_STK_SIZE, (OS_MSG_QTY )0, (OS_TICK )0, (void *)0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err); OSTaskCreate( (OS_TCB *)&task2TCB, (CPU_CHAR *)"Task2", (OS_TASK_PTR)Task2, (void *)0, (OS_PRIO ) TASK2_PRIO, (CPU_STK *)&task2_stk[0], (CPU_STK_SIZE)TASK2_STK_SIZE / 10, (CPU_STK_SIZE)TASK2_STK_SIZE, (OS_MSG_QTY )0, (OS_TICK )0, (void *)0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err); OSTaskCreate( (OS_TCB *)&task3TCB, (CPU_CHAR *)"Task3", (OS_TASK_PTR)Task3, (void *)0, (OS_PRIO )TASK3_PRIO, (CPU_STK *)&task3_stk[0], (CPU_STK_SIZE)TASK3_STK_SIZE / 10, (CPU_STK_SIZE)TASK3_STK_SIZE, (OS_MSG_QTY )0, (OS_TICK )0, (void *)0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err); OSTaskCreate( (OS_TCB *)&dispTCB, (CPU_CHAR *)"LCD display", (OS_TASK_PTR)MainTask, (void *)0, (OS_PRIO )Disp_PRIO, (CPU_STK *)&dispStk[0], (CPU_STK_SIZE)TASK4_STK_SIZE / 10, (CPU_STK_SIZE)TASK4_STK_SIZE, (OS_MSG_QTY )0, (OS_TICK )0, (void *)0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err); OSTaskCreate( (OS_TCB *)&schedTaskEx1TCB, (CPU_CHAR *)"Sched Task Example1", (OS_TASK_PTR)SchedEx1Task, (void *)0, (OS_PRIO )Disp_PRIO, (CPU_STK *)&dispStk[0], (CPU_STK_SIZE)SCHED_TASK_STK_SIZE / 10, (CPU_STK_SIZE)SCHED_TASK_STK_SIZE, (OS_MSG_QTY )0, (OS_TICK )0, (void *)0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err); OSTaskCreate( (OS_TCB *)&schedTaskEx2TCB, (CPU_CHAR *)"Sched Task Example1", (OS_TASK_PTR)SchedEx2Task, (void *)0, (OS_PRIO )Disp_PRIO, (CPU_STK *)&dispStk[0], (CPU_STK_SIZE)SCHED_TASK_STK_SIZE / 10, (CPU_STK_SIZE)SCHED_TASK_STK_SIZE, (OS_MSG_QTY )0, (OS_TICK )0, (void *)0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err); OSSemCreate( (OS_SEM *)&taskSem, (CPU_CHAR *)"taskSem", (OS_SEM_CTR )0, (OS_ERR *)err); OSTaskDel( (OS_TCB *)&taskStartTCB, (OS_ERR *)&err); }
int main(void) { // EXT_MEM_INIT; usart0_init(USART_RS485_SLAVE, 38400); usart0_setprotocol_modbus(); usart1_init(USART_RS232, 115200); USART1_SET_8N1; USART1_RX_INT_DISABLE; timer_init(); kbd_init(); shift_init(); sensor_init(); menu_init(); menu_items_init(); beep_init(); GLOBAL_INT_ENABLE; beep_ms(1000); _delay_ms(500); beep_ms(200); _delay_ms(200); beep_ms(200); _delay_ms(200); lcd_init(); for (;;) { //do_kbd(); do_lcd(); do_shift(); do_sensor(); menu_doitem(); process_usart(); process_soft_controls(); process_siren(); //process_foil(); //process_kbd(); // simple process foil soft_sensors = sensors; if (TEST_SOFT_CONTROL(SOFT_CONTROL_BUNKER_MOTOR) && TEST_SENSOR(SENSOR_END_OF_FOIL)) SOFT_CONTROL_OFF(SOFT_CONTROL_BUNKER_MOTOR); /* if (!TEST_SENSOR(SENSOR_END_OF_FOIL) && TEST_SENSOR(SENSOR_SEC_REEL)) SOFT_CONTROL_ON(SOFT_CONTROL_BUNKER_MOTOR); */ } return 0; }
int main(void) { set_canit_callback(CANIT_RX_COMPLETED, rx_complete); set_canit_callback(CANIT_TX_COMPLETED, tx_complete); set_canit_callback(CANIT_DEFAULT, can_default); usart1_init(); CAN_INIT_ALL(); //Can setup sei(); //Enable interrupt usart1_printf("\n\n\nSTARTING\n"); // Set MOB 8 to listen for messeges with id 4 and length 7 can_msg_t rx_msg = { .mob = 8, .id = 4, .dlc = 7, .mode = MOB_RECIEVE }; can_setup(&rx_msg); usart1_printf("Listning for id %d on mob %d with a msg length %d\n", rx_msg.id, rx_msg.mob, rx_msg.dlc ); while(1){ // Main work loop _delay_ms(250); // send a message with id 4 on MOB 10 can_msg_t tx_msg = { .mob = 10, .id = 4, .data = {'H', 'E', 'L', 'L', 'O', '!', '!'}, .dlc = 7, .mode = MOB_TRANSMIT }; can_send(&tx_msg); usart1_printf("CAN Tx\t id %d, mob %d, :: ", tx_msg.id, tx_msg.mob); // As tx_msg.data is a byte array we cant treat it as a string usart1_putn(sizeof(tx_msg.data)/sizeof(tx_msg.data[0]), tx_msg.data); usart1_putc('\n'); } return 0; } // Callback to be run when rx comletes on the CAN static void rx_complete(uint8_t mob) { can_msg_t msg = { .mob = mob // mob is the MOB that fired the interrupt }; can_receive(&msg); // Fetch the message and fill out the msg struct // Print out the received data. Please dont print inside can callbacks // in real code as these are run inside the can ISR usart1_printf("CAN Rx\t id: %d on mob %d :: ", msg.id, msg.mob); usart1_putn(msg.dlc, msg.data); usart1_putc('\n'); } static void tx_complete(uint8_t mob) { // We clear the mob so it can be used again MOB_ABORT(); // Freed the MOB MOB_CLEAR_INT_STATUS(); // and reset MOB status CAN_DISABLE_MOB_INTERRUPT(mob); // Unset interrupt }