完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include "STM32f30x.h"
#define uint unsigned int #define uchar unsigned char uint i,j,k; uchar h; /*void Delay(i) { for(j=0;j<=i;j++) { for(k=0;k<=1000;k++); } }*/ void NVIC_Configuration(void); void USART1_IRQHandler(void); void RCC_Configuration(void); void UASRT_Configuration(void); void GPIO_Configyration(void); int main() { RCC_Configuration(); USART1_IRQHandler(); GPIO_Configyration(); UASRT_Configuration(); NVIC_Configuration(); //USART_SendData(USART1, 0X99); while(1); } void RCC_Configuration(void) { RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);//enable clk RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); GPIO_DeInit(GPIOA); USART_DeInit(USART1); } void NVIC_Configuration(void) { NVIC_InitTypeDef USART_InitStructure; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); USART_InitStructure.NVIC_IRQChannel=USART1_IRQn; USART_InitStructure.NVIC_IRQChannelPreemptionPriority=1; USART_InitStructure.NVIC_IRQChannelSubPriority=5; USART_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&USART_InitStructure); } void USART1_IRQHandler(void) { if(USART_GetITStatus(USART1,USART_IT_RXNE)!=RESET) { USART_SendData(USART1,USART_ReceiveData(USART1)); while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET); } } void UASRT_Configuration(void) { USART_InitTypeDef USART_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_ITConfig(USART1, USART_FLAG_RXNE, ENABLE); USART_Cmd(USART1, ENABLE);//EN UART USART_ClearFlag(USART1,USART_FLAG_TC); } void GPIO_Configyration(void) { GPIO_InitTypeDef GPIO_InitStructure; 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); } 请大神帮我看一下,为什么不能收发数据啊?谢谢了 |
|
相关推荐
7个回答
|
|
|
|
用示波器看了下,没进中断,具体原因未知,走过路过的帮我看下哈,帮我找找
|
|
|
|
#include "uart.h"
void USART_InitConfig(void) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_7); GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_7); /* * USART1_TX -> PA9 , USART1_RX -> PA10 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; 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_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_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(USART1, &USART_InitStructure); USART_Cmd(USART1, ENABLE); USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); USART_ITConfig(USART1, USART_IT_TXE, DISABLE); /*Enable the USART1 Interrupt(??USART1??)*/ NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } void UART_send_byte(uint8_t byte) //µ¥×Ö½Ú·¢ËÍ { while(!((USART1->ISR)&(1<<7))); USART1->TDR=byte; } void UART_Send(uint8_t *Buffer, uint32_t Length) { while(Length != 0) { while(!((USART1->ISR)&(1<<7)));//µÈ´ý·¢ËÍÍê USART1->TDR= *Buffer; Buffer++; Length--; } } 对照看一下,你的程序写的有点乱。。 |
|
|
|
不懂帮顶
|
|
|
|
|
|
|
|
版主 你的中断函数呢? 能给我看一下吗 |
|
|
|
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) { rx[i++] = USART_ReceiveData(USART1); } if(i == 8) { i = 0; uart_flag = 1; } |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
2049 浏览 1 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
1893 浏览 3 评论
4485 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
2040 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
2549 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-21 12:23 , Processed in 0.759584 second(s), Total 86, Slave 69 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号