CH32F203CBT6芯片UART4配置

芯片的示例程序里面沒有有關UART的配置,所以根據手冊自己寫了UART4配置(重映射PB0和PB1),實測下來沒有數據輸出,也沒有進接收中斷,能否看看是哪里配置有問題,具體配置如下:

void UART4_Init (uint32_t band)

{

? ? USART_InitTypeDef USART_InitStructure;

? ? GPIO_InitTypeDef GPIO_InitStructure;

? ? NVIC_InitTypeDef? NVIC_InitStructure;


RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOB, ENABLE);

? ? RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);

? ? GPIO_PinRemapConfig( GPIO_FullRemap_USART4, ENABLE );

? ??

? ? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;?

? ? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

? ? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

? ? GPIO_Init(GPIOB, &GPIO_InitStructure);

? ??

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;?

GPIO_Init(GPIOB, &GPIO_InitStructure);


? ? 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_Rx | USART_Mode_Tx;??


? ? USART_Init(UART4, &USART_InitStructure);?

? ? USART_ClearFlag(UART4, USART_FLAG_RXNE);?

? ? USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);

? ? USART_Cmd(UART4, ENABLE);?


? ? //NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);? //采用組別2?


? ? NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;

? ? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

? ? NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

? ? NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

? ? NVIC_Init( &NVIC_InitStructure );

}


void UART4_IRQHandler(void)

{

? if(USART_GetITStatus(UART4, USART_IT_RXNE) != RESET) //若接收數據寄存器滿

? {

printf("%d\r\n", USART_ReceiveData(UART4));

? }

?// printf("INT\r\n");

? USART_ClearITPendingBit(UART4,USART_IT_ORE);

}


您好,CH32F203CBT6沒有串口4,只有3個串口。關于外設具體數量,可查看對應數據手冊,手冊下載鏈接如下:

http://www.findthetime.net/downloads/CH32F203DS0_PDF.html?

image.png


只有登錄才能回復,可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频