|
楼主 |
发表于 2017-7-26 07:54:52
|
显示全部楼层
测试了还是不行,把源码贴上:
int main(void)
{
/* System Clocks Configuration */
SystemInit();
/* Configure the GPIO ports */
GPIO_Configuration();
TIM2_Configuration();
UTRA3_Configuration();
/* NVIC configuration */
NVIC_Configuration();
Uart_InterruptsendY(USART3,ddd1,3);///wwwwwwwwwwwwwwwwwwwwwwwwwww
while (1)
{
}
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART3 | RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
/* Configure USARTx_Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//10
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure USARTx_Rx as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;//11
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
void UTRA3_Configuration(void)
{
/* USARTy and USARTz configuration ------------------------------------------------------*/
/* 9600 8 n 1
*/
USART_InitStructure.USART_BaudRate = 9600;
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;
/* Configure USARTy */
USART_Init(USART3, &USART_InitStructure);
/* Configure USARTz */
/* Enable USARTy Receive and Transmit interrupts */
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
// USART_ITConfig(USART1, USART_IT_TXE, ENABLE);//使能中断 这里先不使能 在后面中断发送之前发送
USART_Cmd(USART3, ENABLE);
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the NVIC Preemption Priority Bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* Enable the USARTy Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void Uart_InterruptsendY(USART_TypeDef *USARTx,vu8* Uart0_sended,u8 NbOfBytes )
{
Uart_send_counter=NbOfBytes;
Uart_send_pointer=Uart0_sended;
USART_SendData(USARTx, *Uart_send_pointer++);
USART_ITConfig(USARTx, USART_IT_TXE, ENABLE);
//UART_ITConfig(UARTx,UART_IT_TxEmpty, ENABLE);
} |
|