stm32f103的芯片,有没有兄弟usart改成中断方式后作过?有的话,代码搞点,谢谢。
有的是
void Uart_Init(void){
USART_InitStructure.USART_BaudRate = 9600; //9600 bps
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //8 Bits
USART_InitStructure.USART_Parity = USART_Parity_No; //One Stop Bit
USART_InitStructure.USART_StopBits = USART_StopBits_1; //One Stop Bit
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //Hardware flow control disabled (RTS and CTS signals)
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //Receive and transmit enabled
USART_Init(USART1, &USART_InitStructure);
USART_Init(USART2, &USART_InitStructure);
USART_Init(USART3, &USART_InitStructure);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //使能UART1接收中断
USART_ITConfig(USART1, USART_IT_TXE, ENABLE); //使能UART1发送中断
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); //使能UART2接收中断
USART_ITConfig(USART2, USART_IT_TXE, ENABLE); //使能UART2发送中断
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); //使能UART3接收中断
USART_ITConfig(USART3, USART_IT_TXE, ENABLE); //使能UART3发送中断
USART_Cmd(USART1, ENABLE);
USART_Cmd(USART2, ENABLE);
USART_Cmd(USART3, ENABLE);
}
还要啥,统统招来
void USART1_IRQHandler(void){
if(USART_GetITStatus(USART1, USART_IT_RXNE) == SET)
{
if(sUart1.rxTotal >= 512)
{
sUart1.rxTotal = 0;
}
sUart1.rxBuf[sUart1.rxTotal++] = USART1->DR;
}
if(USART_GetITStatus(USART1, USART_IT_TXE) == SET)
{
if(sUart1.txNum < sUart1.txTotal)
{
USART1->DR = sUart1.txBuf[sUart1.txNum++];
}
else
{
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
}
}
}
兄弟,你直接工程发给我得了
兄弟,谢谢: hjiongh@hotmail.com
发过去了
这点儿东西你倒是自己研究研究阿,他好像有中断方式的例子吧
为啥我usart进了中断,但是进不了接收部分
我现在用usart1跟pc连接,网上的例子工程是usart1,usart2互相中断通信的。 我现在屏蔽掉usart2,但是我pc串口助手发送数据,进不了接收中断,usart_getitstatus(usart1,usart_it_rxne)读出来是reset,这是为啥