初级会员
- 积分
- 108
- 金钱
- 108
- 注册时间
- 2014-10-29
- 在线时间
- 2 小时
|
楼主 |
发表于 2014-11-28 23:09:10
|
显示全部楼层
回复【2楼】正点原子:
---------------------------------
原子哥 我现在正在搞UART4,5串口 也看到你的寄存器版本的程序 可以写个库函数版本的吗 搞不定下面是我写串口4你看看有什么问题:
void uart4_init(u32 bound)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_Init(GPIOC, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = bound;
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_ITConfig(UART4, USART_IT_RXNE, ENABLE);
USART_Cmd(UART4, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;//NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQChannel;
//NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQHandler;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//?????3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //????3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ????
NVIC_Init(&NVIC_InitStructure); //??????????VIC???
} |
|