|
建议用示波器先看看TX 有没有波形输出吧。 没有输出就是软件哪里 没配置好。希望对你有帮助。
#include "stm32f10x.h"
#include
/*** 注:
调试程序前,需将PB4-Buzzer跳线(红色)取下,待程序调试结束后,
再接好跳线。
PB4引脚上电默认为JTAG-RST引脚。
********************************************************************/
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
u8 txbuffer1[] = "00:00:00";
u8 txbuffer2[] = "=========================";
u8 txbuffer3[] = {0x0A,0x0D};
void GPIO_Configuration(void);
void NVIC_Configuration(void);
void USART_Configuration(void);
void USART_SendString(u8 *str,u8 length);
unsigned char a;
unsigned char inputstr[128];
int main(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
GPIO_Configuration();
USART_Configuration();
USART_Cmd(USART1, ENABLE);
//USART_SendString("\r\n\n\n WWW.ARMJISHU.COM your input is:\n\r[%s]\n\r",50);
//printf("\r\n\n\n WWW.ARMJISHU.COM your input is:\n\r[%s]\n\r", inputstr);
while(1)
{
USART_SendData(USART1,'1');
a=USART_ReceiveData(USART1);
if(a=='\r')
{ USART_SendData(USART1,'1');
USART_SendData(USART1,'2'); }
else
{;}
//a=USART_GetData();
//USART_SendString(txbuffer3,sizeof(txbuffer3)-1); //Enter
//USART_SendString(txbuffer1,sizeof(txbuffer1)-1);
//USART_SendString(txbuffer3,sizeof(txbuffer3)-1); //Enter
//USART_SendString(txbuffer2,sizeof(txbuffer2)-1);
//USART_SendString(txbuffer3,sizeof(txbuffer3)-1); //Enter
}
//while(1);
}
//
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//RX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//TX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
//
void USART_Configuration(void)
{
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_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
}
//
void USART_SendString(u8 *str,u8 length)
{
u8 temp;
for(temp=0;temp
{
USART_SendData(USART1,str[temp]);
while(USART_GetITStatus(USART1, USART_IT_TXE) == RESET);
}
} |
|