学前班
最后登录1970-1-1
在线时间 小时
注册时间2015-2-28
|
板子是挑战者F429,按照火博士的教程,目的是按复位键后往调试助手发送255(0xFF),但是不知道我漏了哪里,粗心的我找了几遍还是找不到问题出在哪里,基础不牢,地动山摇。请火博士和各位指点指点。谢谢!
头文件gpiousart.h
#ifndef __GPIOUSART_H
#define __GPIOUSART_H
#include "stm32f4xx.h"
void gpio_usart_config(void);
void Usart_SendByte(USART_TypeDef * USARTx, uint8_t ch);
#endif
c文件gpiousart.c
#include "gpiousart.h"
static void nvic_config(void)
{
NVIC_InitTypeDef nvic_structure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
nvic_structure.NVIC_IRQChannel = USART1_IRQn;
nvic_structure.NVIC_IRQChannelCmd = ENABLE;
nvic_structure.NVIC_IRQChannelPreemptionPriority = 1;
nvic_structure.NVIC_IRQChannelSubPriority = 1;
NVIC_Init(&nvic_structure);
}
void gpio_usart_config(void)
{
GPIO_InitTypeDef gpio_usart_structure;
USART_InitTypeDef usart_structure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
RCC_AHB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
gpio_usart_structure.GPIO_OType = GPIO_OType_PP;
gpio_usart_structure.GPIO_PuPd = GPIO_PuPd_UP;
gpio_usart_structure.GPIO_Speed = GPIO_Speed_50MHz;
gpio_usart_structure.GPIO_Mode = GPIO_Mode_AF;
gpio_usart_structure.GPIO_Pin = GPIO_Pin_9;
GPIO_Init(GPIOA,&gpio_usart_structure);
gpio_usart_structure.GPIO_Mode = GPIO_Mode_AF;
gpio_usart_structure.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOA,&gpio_usart_structure);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART1);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1);
/******************************************/
usart_structure.USART_BaudRate = 115200;
usart_structure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
usart_structure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
usart_structure.USART_Parity = USART_Parity_No;
usart_structure.USART_StopBits = USART_StopBits_1;
usart_structure.USART_WordLength = USART_WordLength_8b;
USART_Init(USART1,&usart_structure);
nvic_config();
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
USART_Cmd(USART1,ENABLE);
}
void Usart_SendByte(USART_TypeDef * USARTx, uint8_t ch)
{
USART_SendData(USARTx,ch);
while (USART_GetFlagStatus(USARTx, USART_FLAG_TXE) == RESET);
}
main函数
#include "gpiousart.h"
#include "stm32f4xx.h"
int main(void)
{
gpio_usart_config();
Usart_SendByte(USART1,255);
while(1)
{
}
}
|
|