打印

请教:USART3能接收到数据,不能发送数据,是什么原因?

[复制链接]
4272|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
ggxjz|  楼主 | 2009-11-15 22:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我的配置程序如下:
void UART_Config(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USART1 Tx(PA.09) as alternate function open-drain */
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Pin = RS485_TXD1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART3 Tx(PC.10) as alternate function open-drain */
GPIO_InitStructure.GPIO_Pin = RS232_TXD4;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure USART3 Tx(PB.10) as alternate function open-drain */
GPIO_InitStructure.GPIO_Pin = ALARM_TXD3;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure USART1_Rx(PA.10) as input floating */
  GPIO_InitStructure.GPIO_Pin = RS485_RXD1;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART1_Rx(PC.11) as input floating */
GPIO_InitStructure.GPIO_Pin = RS232_RXD4;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure USART1_Rx(PB.11) as input floating */
GPIO_InitStructure.GPIO_Pin = ALARM_RXD3;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

/* USARTx configuration ------------------------------------------------------*/
  /* USARTx configured as follow:
        - BaudRate = 115200 baud  
        - Word Length = 8 Bits
        - One Stop Bit
        - No parity
        - Hardware flow control disabled (RTS and CTS signals)
        - Receive and transmit enabled
  */

USART_InitStructure.USART_BaudRate = 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 USARTx */
  USART_Init(UART4, &USART_InitStructure);
  /* Enable USART1 Receive and Transmit interrupts */
  USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
  /* Enable the USARTx */
  USART_Cmd(UART4, ENABLE);
/* Configure the USARTx */
  USART_Init(USART3, &USART_InitStructure);
  /* Enable USART1 Receive and Transmit interrupts */
  USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
  /* Enable the USARTx */
  USART_Cmd(USART3, ENABLE);

}
UART4能收能接,USART3却是不能发送数据,只能接受
沙发
winloop| | 2009-11-16 08:54 | 只看该作者
把你发送数据的代码贴出来看看[url][/url]

使用特权

评论回复
板凳
ggxjz|  楼主 | 2009-11-16 09:14 | 只看该作者
void UART3_SendByte(unsigned char Data)
{

                /* Loop until USART1 DR register is empty */
    while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET)
    {
    }
               
    USART_SendData(USART3, Data);
   
   
}

使用特权

评论回复
地板
ggxjz|  楼主 | 2009-11-16 09:17 | 只看该作者
事实上,我的串口1和串口4是正常的,使用的发送函数也是一样的
是不是有什么冲突?
但是没有用SDIO功能

使用特权

评论回复
5
xwj| | 2009-11-16 09:31 | 只看该作者
一般都是马大哈问题,就是换个端口后照搬程序,但某个地方没改到。
比如寄存器位、中断开关、入口地址、IO 方式、队列位置、标志名...等等等等

使用特权

评论回复
6
winloop| | 2009-11-16 15:51 | 只看该作者
突然想起来我好像碰到过类似问题,问题出在引脚映射顺序上,后来因为找不到原因,我就把UART4映射的函数跟其它IO映射的函数随便调了几个顺序,结果问题解决了,但直到现在我不知道真正的原因,这好像是STM32的一个问题

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

5

主题

11

帖子

0

粉丝