您好,我使用CH32V003J4M6的芯片,串口初始化成功了,每次都要用linke全擦,使用串口發(fā)送一個(gè)字符串,用usb轉(zhuǎn)ttl接收不到,我用V203的板子測試了usb轉(zhuǎn)ttl是可以接收到數(shù)據(jù)的,請問是什么問題,
void UART_Init(uint32_t baudrate)
{
? ? GPIO_InitTypeDef? GPIO_InitStructure = {0};
? ? USART_InitTypeDef USART_InitStructure = {0};
? ? NVIC_InitTypeDef? NVIC_InitStructure = {0};
? ? RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_USART1, ENABLE);
? ? /* USART1 TX-->D.5? ?RX-->D.6 */
? ? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
? ? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_30MHz;
? ? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
? ? GPIO_Init(GPIOD, &GPIO_InitStructure);
? ? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
? ? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
? ? GPIO_Init(GPIOD, &GPIO_InitStructure);
? ? USART_InitStructure.USART_BaudRate = baudrate;
? ? 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);
? ? //初始化環(huán)形緩沖區(qū)
? ? circle_buf_init(&rx_buf, BufferSize, RxBuffer);
? ? // 使能串口中斷
? ? USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
? ? NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
? ? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
? ? NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
? ? NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
? ? NVIC_Init(&NVIC_InitStructure);
? ? USART_Cmd(USART1, ENABLE);
}
void UART_Init(uint32_t baudrate)
{
? ? GPIO_InitTypeDef? GPIO_InitStructure = {0};
? ? USART_InitTypeDef USART_InitStructure = {0};
? ? NVIC_InitTypeDef? NVIC_InitStructure = {0};
? ? RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_USART1, ENABLE);
? ? /* USART1 TX-->D.5? ?RX-->D.6 */
? ? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
? ? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_30MHz;
? ? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
? ? GPIO_Init(GPIOD, &GPIO_InitStructure);
? ? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
? ? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
? ? GPIO_Init(GPIOD, &GPIO_InitStructure);
? ? USART_InitStructure.USART_BaudRate = baudrate;
? ? 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);
? ? //初始化環(huán)形緩沖區(qū)
? ? circle_buf_init(&rx_buf, BufferSize, RxBuffer);
? ? // 使能串口中斷
? ? USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
? ? NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
? ? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
? ? NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
? ? NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
? ? NVIC_Init(&NVIC_InitStructure);
? ? USART_Cmd(USART1, ENABLE);
}
void usart1_printf(uint8_t *fmt,...)
{
? ? uint8_t Uart1_Bufferr[256];
? ? uint16_t i,j;
? ? va_list ap;
? ? va_start(ap,fmt);
? ? vsprintf((char*)Uart1_Bufferr,fmt,ap);
? ? va_end(ap);
? ? i=strlen((char*)Uart1_Bufferr);
? ? for(j=0;j
? ? {
? ? ? ? while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
? ? ? ? USART_SendData(USART1, (uint8_t)Uart1_Bufferr[j]);
? ? }
}
我就在while(1)里一直不停的發(fā)usart1_printf("012")但是接收不到