最近做一个东西用到了串口,串口连接是买的宇泰的TTL转232 3.3v的转换器,转换器的初始信号是高电平,不把串口插到板子上面时,用示波器观察,发送数据是正常的,但是一插到板子上面串口的输出信号就直接被拉低了,这时给串口发数据也没没有任何反应,请问各位,这是个怎么回事??
串口配置如下:
void Usart1_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* Enable USART1 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
/* Enable GPIO clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);
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;
/* Connect PA9 to USARTx_Tx */
GPIO_PinAFConfig(Test_COM_PORT, Test_COM_TX_BIT,GPIO_AF_USART1);
/* Connect PA10 to USARTx_Rx */
GPIO_PinAFConfig(Test_COM_PORT, Test_COM_RX_BIT,GPIO_AF_USART1);
/* Configure USART Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = Test_COM_TX_BIT;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(Test_COM_PORT, &GPIO_InitStructure);
/* Configure USART Rx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = Test_COM_RX_BIT;
GPIO_Init(Test_COM_PORT,&GPIO_InitStructure);
/* USART configuration */
USART_Init(Test_COM,&USART_InitStructure);
// USART_ITConfig(Test_COM, USART_IT_TXE, ENABLE);
USART_ITConfig(Test_COM, USART_IT_RXNE, ENABLE);
/* Enable USART */
USART_Cmd(Test_COM, ENABLE);
} |