问题描述
我使用的是 stm32f407vg 板。我正在编写关于原子真的程序。另外,我使用D-SUN USB TLL。我还使用 Termite 来查看数据接收和发送屏幕。
当我向白蚁发送 1 或 0 时,我无法离开端口 B。但是如果我想发送数据(“HelloGuys”),它工作正常。你的原因可能是什么?
/* --------------------------- System Libraries --------------------------------------*/
#include "stm32f4xx.h"
#include "stm32f4_discovery.h"
/* --------------------------- STRUCTURES--------------------------------------------*/
GPIO_InitTypeDef GPIO_InitStruct;
USART_InitTypeDef UART_InitStruct;
NVIC_InitTypeDef NVIC_InitStructure;
/* --------------------------- Variables --------------------------------------------*/
static char test[25] = "HelloGuys \r\n";
static uint16_t data = 0;
/* --------------------------- System Clocks Configuration ---------------------------*/
void RCC_Configuration()
{
/* GPIOC clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE);
/* USART3 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
/*LED clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE);
}
/* --------------------------- GPIO Configuration -----------------------------------*/
void GPIO_Config1(){
//UART 3 ___PC10 TX___PC11 RX
//TX Configure
GPIO_InitStruct.GPIO_Mode =GPIO_Mode_AF;
GPIO_InitStruct.GPIO_OType =GPIO_OType_PP;
GPIO_InitStruct.GPIO_Pin =GPIO_Pin_10;
GPIO_Init(GPIOC,&GPIO_InitStruct);
//RX Configure
GPIO_InitStruct.GPIO_Mode =GPIO_Mode_IN;
GPIO_InitStruct.GPIO_OType =GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd =GPIO_PuPd_NOPULL;
GPIO_InitStruct.GPIO_Pin =GPIO_Pin_11;
GPIO_Init(GPIOC,&GPIO_InitStruct);
/* Connect USART pins to AF */
GPIO_PinAFConfig(GPIOC,GPIO_PinSource10,GPIO_AF_USART3);
GPIO_PinAFConfig(GPIOC,GPIO_PinSource11,GPIO_AF_USART3);
//LED
GPIO_InitStruct.GPIO_Mode =GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_Pin =GPIO_Pin_0;
GPIO_InitStruct.GPIO_Speed =GPIO_Speed_25MHz;
GPIO_Init(GPIOB,&GPIO_InitStruct);
}
/* --------------------------- USART Configuration ----------------------------------*/
void USART_Config1(){
UART_InitStruct.USART_BaudRate =9600;
UART_InitStruct.USART_HardwareFlowControl =USART_HardwareFlowControl_None;
UART_InitStruct.USART_Mode =USART_Mode_Rx | USART_Mode_Tx;
UART_InitStruct.USART_Parity =USART_Parity_No;
UART_InitStruct.USART_StopBits =USART_StopBits_1;
UART_InitStruct.USART_WordLength =USART_WordLength_8b;
USART_Init(USART3,&UART_InitStruct);
USART_Cmd(USART3,ENABLE);
}
//--------------------------- DATA_STRING SETTING -----------------------------------/
void Send_String_Data(char *str){
while(*str)
{
while(! (USART3->SR & 0x00000040));
USART_SendData(USART3,*str);
str++;
}
}
/**************************************************************************************/
int main(void)
{
SystemInit();
RCC_Configuration();
GPIO_Config1();
USART_Config1();
while (1)
{
//Send_String_Data(test);
data = USART_ReceiveData(USART3);
if(data=='1') {
GPIO_SetBits(GPIOB,GPIO_Pin_0);
}
if(data=='0') {
GPIO_ResetBits(GPIOB,GPIO_Pin_0);
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)