完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
#include "STM32f30x.h"
#define uint unsigned int int main() { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);//enable clk RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE); GPIO_DeInit(GPIOA); USART_DeInit(USART1); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;//RX GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;//TX GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5;//LED GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; USART_InitStructure.USART_BaudRate = 115200;//UART USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No ; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; GPIO_Init(GPIOA, &GPIO_InitStructure); USART_Init(USART1, &USART_InitStructure); USART_Cmd(USART1, ENABLE);//EN UART USART_SendData(USART1, 0X55); while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==1) { GPIO_SetBits(GPIOA, GPIO_Pin_5); } } |
|
相关推荐
19个回答
|
|
|
串口助手收到的都是000000~
|
|
|
|
|
|
引脚配置不同功能,每一个引脚都要调用一次GPIO_Init(),你这样写相当于只配置了最后一个引脚PA5,还有要调用GPIO_PinAFConfig()配置复用功能
|
|
|
|
|
|
void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF)
缺少端口复用的吧,你试试 |
|
|
|
|
|
端口复用吧?
|
|
|
|
|
|
三楼说的正确,GPIO配置不对,A9 A10默认是串口不用映射,如果是B6 B7需要映射。
|
|
|
|
|
|
#include "stm32f30x.h"
#define uint unsigned int int main() { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);//enable clk RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE); GPIO_DeInit(GPIOA); USART_DeInit(USART1); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;//RX GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA, GPIO_Pin_10, GPIO_AF_7); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;//TX GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA, GPIO_Pin_9, GPIO_AF_7); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5;//LED GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); USART_InitStructure.USART_BaudRate = 9600;//UART USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No ; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_Init(USART1, &USART_InitStructure); USART_Cmd(USART1, ENABLE);//EN UART USART_ClearFlag(USART1,USART_FLAG_TC); USART_SendData(USART1, 0X0055); while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==1) { GPIO_SetBits(GPIOA, GPIO_Pin_5); } GPIO_ResetBits(GPIOA, GPIO_Pin_5); } 修改后还是不行,主芯片是STM32F334R8 |
|
|
|
|
|
|
|
|
|
|
djw200988 发表于 2018-9-24 08:34 还是不行, |
|
|
|
|
丰盛慈爱 发表于 2018-9-24 08:51 不行呀 , 你有串口代码吗? 给我看一下呗 ,谢谢啦 |
|
|
|
|
|
我感觉是没有发出数据来,我的发送数据有问题吗?
|
|
|
|
|
|
|
|
|
|
|
|
不懂帮顶
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
结贴
#include "stm32f30x.h" #define uint unsigned int uint i,j,k; void Delay(i) { for(j=0;j<=i;j++) ; } int main() { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);//enable clk RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); GPIO_DeInit(GPIOA); USART_DeInit(USART1); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;//RX GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_7); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;//TX GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_7); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5;//LED GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); USART_InitStructure.USART_BaudRate = 115200;//UART USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No ; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_Init(USART1, &USART_InitStructure); USART_Cmd(USART1, ENABLE);//EN UART USART_ClearFlag(USART1,USART_FLAG_TC); while(1) { USART_SendData(USART1, 0X55); while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==1) { GPIO_SetBits(GPIOA, GPIO_Pin_5); Delay(500); GPIO_ResetBits(GPIOA, GPIO_Pin_5); Delay(500); } } } |
|
|
|
|
|
恭喜楼主!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
不会用库爱莫能肋
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
STM32F405驱动DS1302时钟模块,输出时间错乱该怎么排查?
2961 浏览 2 评论
stm32f405rgt6驱动DS1302ZN出现时间错乱问题
2463 浏览 1 评论
stm32用fsmc读取ad7606采集数据,数据不变,只有开发版复位才更新数据
2331 浏览 0 评论
2455 浏览 1 评论
1674 浏览 1 评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-3 02:49 , Processed in 1.250204 second(s), Total 111, Slave 93 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
3687