凌云志轩 2015-04-01 11:45 采纳率: 89%
浏览 4032

STM32F407 UART5没反应,波形也不对

#include "usart.h"
#include "stm32f4xx.h"

#define RS485tX GPIO_SetBits(GPIOE,GPIO_Pin_1);//1 拉高
#define RS485rX GPIO_ResetBits(GPIOE, GPIO_Pin_1);//0 拉低

void uart_init(void)
{
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE);

GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_UART5); //UART5_RX
GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_UART5); //UART5_TX
GPIO_PinAFConfig(GPIOE, GPIO_PinSource1, GPIO_AF_UART5); //uart5_DE

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_Init(GPIOC, &GPIO_InitStructure);

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

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_Init(GPIOE, &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(UART5, &USART_InitStructure);

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

USART_Cmd(UART5, ENABLE);
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
}

static void delay(unsigned int dl)
{
unsigned int i,y;
for(i = 0; i < 500; i++)
{
for(y = 0; y < dl; y++);
}
}

void UART5_IRQHandler(void)
{
uint8_t x,y,z;
uint16_t checksum1,checksum2;

if(USART_GetITStatus(UART5, USART_IT_RXNE) != RESET)
{

x=USART_ReceiveData(UART5);

USART_SendData(UART5,x);

}

}

void uartsend(int ch)
{
RS_485tX;
delay(100);
while(RESET == USART_GetFlagStatus(UART5,USART_FLAG_TXE));
USART_SendData(UART5, (uint8_t) ch);
RS485rX;
delay(100);
}
用的是STM32F407的片子,现在接受和发送数据都没有,这是为什么呢?

  • 写回答

4条回答 默认 最新

  • 秦时明月94 2015-04-02 09:22
    关注

    这怎么讲呢 进入硬件debug看寄存器UART5的值有没有变化,该置位的有没有置位

    评论

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 R语言 拟时序分析降维图如何减少分支
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统