CRG61 2017-08-11 20:20 采纳率: 0%
浏览 1156

STM32入门串口程序,调试许久未果,望解答(附代码)

很基本的一个程序,最开始似乎是硬件问题,换了个接口好了。然后我想写从PC发到32再发回来的程序,没反应,改回之前的程序也没反应了。弄出来打算调ADC的。
已经搞了几个小时了。现在都凌晨4点了= =
以下是配置程序:
#include
#include
void USART1_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA,ENABLE);

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA,&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(USART1,&USART_InitStructure);
USART_Cmd(USART1,ENABLE);

}

int fputc(int ch,FILE *f)
{
USART_SendData(USART1,(unsigned char)ch);
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);
return (ch);
}

main函数:
#include
#include
#include

int main(void)
{
USART1_Config();
printf("\r\n this is a printf demo \r\n");

}

串口助手始终未收到任何数据,串口打开正常

  • 写回答

1条回答 默认 最新

  • zichenxiaoxu 2017-08-12 00:50
    关注

    如果你要用中断模式的USART,那么你的USART没有进行中断初始化,而且也需要在中断函数里面写程序,完成串口通讯功能

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable