中级会员
 
- 积分
- 346
- 金钱
- 346
- 注册时间
- 2013-12-20
- 在线时间
- 94 小时
|
5金钱
在USART3上面实验个自发自收的程序,都不通,有什么地方配置不对吗
//********************************************************************************
void uart_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef UART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
// activate UART3
USART_DeInit(USART3);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
// activate GPIOB (UART3-Pins)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
// assign UART3-Pins (PB10 and PB11)
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_Init(GPIOB, &GPIO_InitStructure);
// configure UART3
UART_InitStructure.USART_BaudRate = 9600;
UART_InitStructure.USART_WordLength = USART_WordLength_8b;
UART_InitStructure.USART_StopBits = USART_StopBits_1;
UART_InitStructure.USART_Parity = USART_Parity_No ;
UART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
UART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init(USART3, &UART_InitStructure);
// activate s32errupt for UART3
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);
USART_Cmd(USART3, ENABLE);
USART_SendData(USART3, 0x12) ; //test
}
//********************************************************************************
void USART3_IRQHandler(void)
{
u8 Res;
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
{
Res =USART_ReceiveData(USART3);
USART_SendData(USART3, Res);
}
}
|
最佳答案
查看完整内容[请看2#楼]
我的 UART3 用到PORTC PIN-10 PIN-11 , 若你是用到 PORTB ? 可能要更改腳位切換的功能
我是使用 F207 不過都大同小異
void debug_port_init(void){
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* USARTx configured as follow:
- BaudRate = 115200 baud
&nbs ...
|