//----------------------------------------------------------------------------------- void UART1_init(uint32_t band) { USART_InitTypeDef USART_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOA, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); //---------------------------------------------------------------------------- Sbuf_init(&U1RevBuf,U1RevStack,U1REVLEN); if( Cycbuf_Init(&U1SendBuf, (uint8_t*)U1SendStack, U1SNED_MAXFRMLEN, U1SNED_MAXFRMNUM) < 0 ) { rt_kprintf("Cycle buffer init fail..\n"); } UART1_NVIC_Config(); //---------------------------------------------------------------------------- //IO init GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); //---------------------------------------------------------------------------- //UART init USART_InitStructure.USART_BaudRate = band; 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_Tx | USART_Mode_Rx; USART_Init(USART1, &USART_InitStructure); //---------------------------------------------------------------------------- //DMA init RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); USART_DMACmd(USART1, USART_DMAReq_Tx, ENABLE); UART1_DMA_init(); USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); USART_Cmd(USART1, ENABLE); //启动hook中的查询推送功能 U1StarupMark = 1; }
void Compass_Init(void) { UART1_DMA_init(9600); //ReadyMeasure(); //标定用,只需标定一次,标定完成注释掉即可 }