大学生
最后登录1970-1-1
在线时间 小时
注册时间2016-8-30
|
用STM32F405的板子,调试串口时发现用中断的方式接收,进入中断后无论在中断内部用printf函数发送数据还是main函数里面都没有问题,而用sendbyte函数时程序就会停掉。单独在main函数里使用sendbyte函数是没问题的,就是中断触发的方式不行,不知道什么问题。sendbyte函数用的是野火STM32F429例程里面的。
程序如下所附
void USART_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHB1PeriphClockCmd(Open_USART_TX_GPIO_CLK,ENABLE);
RCC_AHB1PeriphClockCmd(Open_USART_RX_GPIO_CLK,ENABLE);
#ifdef USART1_OPEN
RCC_APB2PeriphClockCmd(Open_USART_CLK,ENABLE);
#else
RCC_APB1PeriphClockCmd(Open_USART_CLK,ENABLE);
#endif
GPIO_PinAFConfig(Open_USART_TX_GPIO_PORT, Open_USART_TX_SOURCE, Open_USART_TX_AF);
GPIO_PinAFConfig(Open_USART_RX_GPIO_PORT, Open_USART_RX_SOURCE, Open_USART_RX_AF);
/*
* Open_USART_TX -> PA9 , Open_USART_RX -PA10
*/
GPIO_InitStructure.GPIO_Pin = Open_USART_TX_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(Open_USART_TX_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = Open_USART_RX_PIN;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(Open_USART_RX_GPIO_PORT, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
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(Open_USART, &USART_InitStructure);
/* Enable the Open_USART Transmit interrupt: this interrupt is generated when the
Open_USART transmit data register is empty */
USART_ITConfig(Open_USART,USART_IT_RXNE,ENABLE);
USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);
USART_Cmd(Open_USART, ENABLE);
}
void USART_NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the USARTx Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = Open_USART_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
main函数里面如果把所有的sendbyte都注释掉,使用printf函数是可以正常响应中断的(中断里面flag置1),而sendbyte不行,哪位遇到过类似的问题,或者有STM32F405可用的例程。
int main(void)
{
uint32_t i;
USART_Configuration();
USART_NVIC_Config();
for(k=0;k<7;k++)
{
Usart_SendByte(Open_USART,a[k]);
}
i=0x1ffffff;
//printf("\r\nWelcome to WaveShare STM32F4 series MCU Board Open405R\r\n");
while (1)
{
Usart_SendByte(Open_USART,flag);
if(flag==1)
{
//printf("\r\Welcome to WaveShare STM32F4 series MCU Board Open405R\r\n");
for(k=0;k<7;k++)
{
Usart_SendByte(Open_USART,a[k]);
}
flag=0;
}
while(i--);
i=0x1ffffff;
}
}
|
|