发送程序
USART_InitStructure.USART_BaudRate = 9600;//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;
/* Configure the USARTy */
USART_Init(USARTy, &USART_InitStructure);
/* Enable the USARTy */
USART_Cmd(USARTy, ENABLE);
/* Set the USARTy prescaler */
USART_SetPrescaler(USARTy, 0x1);
/* Configure the USARTy IrDA mode */
USART_IrDAConfig(USARTy, USART_IrDAMode_Normal);
/* Enable the USARTy IrDA mode */
USART_IrDACmd(USARTy, ENABLE);
while (1)
{
USART_SendData(USARTy, i++);//i unsigned char
delay(1000000);
}
}
接收程序
USART_InitStructure.USART_BaudRate = 9600;//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;
/* Configure the USARTy */
USART_Init(USARTy, &USART_InitStructure);
STM_EVAL_COMInit(COM2, &USART_InitStructure);
printf("\n\rUSART Printf Example: retarget the C library printf function to the USART\n\r");
/* Enable the USARTy */
USART_Cmd(USARTy, ENABLE);
/* Set the USARTy prescaler */
USART_SetPrescaler(USARTy, 0x1);
/* Configure the USARTy IrDA mode */
USART_IrDAConfig(USARTy, USART_IrDAMode_Normal);
/* Enable the USARTy IrDA mode */
USART_IrDACmd(USARTy, ENABLE);
while (1)
{
/* Wait until a byte is received */
while(USART_GetFlagStatus(USARTy, USART_FLAG_RXNE) == RESET)
{
count++;
if(count > 1000000)
{
printf("\n\r 等待接收数据 \n\r");
count = 0;
}
}
/* Read the received byte */
//ReceivedData = (JOYState_TypeDef)USART_ReceiveData(USARTy);
REV = (unsigned char)USART_ReceiveData(USARTy);
//USART_SendData(USARTy,i++);
//REV = 255;
printf("\n\r 接收到的数据为:%d%d%d \n\r",REV/100,REV%100/10,REV%10);
Delay(5000000);
}
}
电路图:
现象:
发送端 TXD和RXD都有波形,用示波器,至于TFDU4300有没有将数据发出就没法检测了
接收端都没有波形
USE_STDPERIPH_DRIVER, STM32F10X_CL, USE_STM3210B_EVAL
在官方库的基础上改的
|