jiankunkun 2015-07-31 09:01 采纳率: 60%
浏览 1668
已结题

stm32F4DISCOVERY串口通信问题

void RCC_Configuration(void)
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
}

void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USART Tx and Rx as alternate function push-pull */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_Init(GPIOD, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_Pin =GPIO_Pin_9;
GPIO_Init(GPIOD, &GPIO_InitStructure);

 GPIO_PinAFConfig(GPIOD,GPIO_PinSource8,GPIO_AF_USART3);

GPIO_PinAFConfig(GPIOD,GPIO_PinSource9,GPIO_AF_USART3);

}
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;

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;     
USART_Init(USART3,&USART_InitStructure); /* Configure USART1 basic and asynchronous paramters */  

    //USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);
    USART_ITConfig(USART3,USART_IT_TXE,ENABLE);

USART_Cmd(USART3, ENABLE);   /* Enable USART1 */  

    USART_ClearITPendingBit(USART3,USART_IT_TC);

}

void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;//?????

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);   

NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);
}

int main(void)
{
RCC_Configuration();
GPIO_Configuration();
NVIC_Configuration();
USART_Configuration();

while(1);

}

volatile char StringLoop[] = "The quick brown fox jumps over the lazy dog";

void USART3_IRQHandler(void)
{
static int tx_index = 0;

// static int rx_index = 0;

if (USART_GetITStatus(USART3, USART_IT_TXE) != RESET) // Transmit the string in a loop

{

USART_ClearITPendingBit(USART3, USART_IT_TXE);
USART_SendData(USART3, StringLoop[tx_index++]);

if (tx_index >= (sizeof(StringLoop) - 1))  
  tx_index = 0;  

}
}

就是这个程序为什么会不停的发送数据,PC接收端一直在接收,不是清除了标志位吗,想问问大家啊

  • 写回答

1条回答

  • threenewbee 2015-07-31 13:30
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog