21ic问答首页 - GM32F103C-START开发板串口通讯问题
GM32F103C-START开发板串口通讯问题
Tomorrowtoday2022-07-04
想做串口通信,使用这种方式接收,但在keil中单步运行时数组中收到的全是第一个字节,全速运行时收不到数据,是这种写法不能实现串口接收吗
void usart_config(void)//串口初始化
{
/* enable GPIO clock */
rcu_periph_clock_enable(RCU_GPIOA);
rcu_periph_clock_enable(RCU_GPIOC);
/* enable USART clock */
rcu_periph_clock_enable(RCU_USART0);
/* connect port to USARTx_Tx */
gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_9);
/* reset LED GPIO pin */
/* connect port to USARTx_Rx */
gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_10);
gpio_init(GPIOC, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_7);//复位引脚
/* USART configure */
usart_deinit(USART0);
usart_word_length_set(USART0, USART_WL_9BIT);
usart_stop_bit_set(USART0, USART_STB_2BIT);
usart_parity_config(USART0, USART_PM_EVEN);
usart_baudrate_set(USART0, 9600U);
usart_hardware_flow_rts_config(USART0, USART_RTS_DISABLE);
usart_hardware_flow_cts_config(USART0, USART_CTS_DISABLE);
usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);
usart_receive_config(USART0, USART_RECEIVE_ENABLE);
usart_enable(USART0);
}
void Rece(unsigned char rece[], unsigned char k)
{
int i;
for(i=0;i<k;i++)
{
while( usart_interrupt_flag_get(USART0, USART_FLAG_RBNE) != RESET);
rece= usart_data_receive(USART0);
}
}
搜索
void usart_config(void)//串口初始化
{
/* enable GPIO clock */
rcu_periph_clock_enable(RCU_GPIOA);
rcu_periph_clock_enable(RCU_GPIOC);
/* enable USART clock */
rcu_periph_clock_enable(RCU_USART0);
/* connect port to USARTx_Tx */
gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_9);
/* reset LED GPIO pin */
/* connect port to USARTx_Rx */
gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_10);
gpio_init(GPIOC, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_7);//复位引脚
/* USART configure */
usart_deinit(USART0);
usart_word_length_set(USART0, USART_WL_9BIT);
usart_stop_bit_set(USART0, USART_STB_2BIT);
usart_parity_config(USART0, USART_PM_EVEN);
usart_baudrate_set(USART0, 9600U);
usart_hardware_flow_rts_config(USART0, USART_RTS_DISABLE);
usart_hardware_flow_cts_config(USART0, USART_CTS_DISABLE);
usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);
usart_receive_config(USART0, USART_RECEIVE_ENABLE);
usart_enable(USART0);
}
void Rece(unsigned char rece[], unsigned char k)
{
int i;
for(i=0;i<k;i++)
{
while( usart_interrupt_flag_get(USART0, USART_FLAG_RBNE) != RESET);
rece= usart_data_receive(USART0);
}
}
搜索
复制
您需要登录后才可以回复 登录 | 注册