请教大牛关于STM32 USART 硬件流控的问题

[复制链接]
15608|17
 楼主| adofu2008 发表于 2012-11-30 16:51 | 显示全部楼层 |阅读模式
在STM32 的数据手册中看到对USART的硬件流控有这样的描述:贴子太大,已做附件上传。

我在串口配置中已经把
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_RTS;

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;   //PA12 RTS
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  /* Configure USART1 CTS as input floating PA11 CTS*/
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
但是在发送数据时,用示波器观察PA12管脚并没有发现这种高电平脉冲。请教一下大牛们,是不是我哪儿配置出问题了?串口收发数据正常。RTS管脚一直是低电平。谢谢!
cts.JPG
 楼主| adofu2008 发表于 2012-12-3 10:45 | 显示全部楼层
自已顶!
airwill 发表于 2012-12-3 14:58 | 显示全部楼层
没有用过这个功能.
不过, 我想除了GPIO, USART 里也应该做设置吧.
IJK 发表于 2012-12-3 17:45 | 显示全部楼层
印象里STM32有使用RTS、CTS流控的例子, 建议用用看,问题就清楚了。

我用过RTS、CTS流控,记得RTS、CTS 信号都变过。
windzyf 发表于 2013-1-16 20:48 | 显示全部楼层
这个按照例子 测试 无法测试到接收的RTS低有效信号
xuzhiya64423951 发表于 2013-5-4 14:42 | 显示全部楼层
问题解决没?
hawksabre 发表于 2013-5-4 17:48 | 显示全部楼层
楼主   问题解决了吗   应该问题不大    呵呵   帮你顶一个
jun503380 发表于 2013-10-30 16:33 | 显示全部楼层
你的问题解决了没?我也遇到了同样的问题,一起讨论啊
steeven_lee 发表于 2015-5-9 23:35 | 显示全部楼层
成功!我是用的stm32f411re和mbed, 步骤如下:
1. serial_api.c中init_uart:
UartHandle.Init.HwFlowCtl  = UART_HWCONTROL_NONE;
UartHandle.Init.HwFlowCtl  = UART_HWCONTROL_RTS_CTS;
2. 初始化UART1的CTS/RTS引脚:
        PinMap rts =  {PA_12,  UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)};
        PinMap cts =  {PA_11,  UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)};
    pin_function(rts.pin, rts.function);
    pin_function(cts.pin, cts.function);
    pin_mode(rts.pin, PullNone); //output, uart request peer to send
    pin_mode(cts.pin, PullUp); // input, peer send 0 to allow uart send
以上代码写好后, 只有把PA_11也就是CTS拉低才能往uart写数据。下面是测试代码:

  1. #include "mbed_stm_demo.h"
  2. #include "BreathLed/BreathLed.h"
  3. #include "PeripheralPins.h"

  4. using namespace steeven;

  5. BreathLed led1(LED1);

  6. Serial pc(USBTX, USBRX);
  7. Serial uart1(PA_9, PA_10);

  8. int main() {
  9.         char ch;
  10.         int i = 0;
  11.         int j = 0;
  12.         led1.loop(0.5, 0.2);
  13.         pc.baud(115200);
  14.         PinMap rts =  {PA_12,  UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)};
  15.         PinMap cts =  {PA_11,  UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)};
  16.     pin_function(rts.pin, rts.function);
  17.     pin_function(cts.pin, cts.function);
  18.     pin_mode(rts.pin, PullNone); //output, uart request peer to send
  19.     pin_mode(cts.pin, PullUp); // input, peer send 0 to allow uart send

  20.         uart1.baud(115200);

  21.         pc.printf("hello world!\n");
  22.         while (1) {
  23.                 if (pc.readable()) {
  24.                         i++;
  25.                         ch = pc.getc();
  26.                         if (uart1.writeable()) {
  27.                                 uart1.putc(ch);
  28.                         } else {
  29.                                 pc.printf("%d/%d ", i,j); //if
  30.                         }
  31.                         if (i%50 == 49){
  32.                                 pc.printf("\r\n%d lost: %d \r\n", i,i-j);
  33.                         }
  34.                 }
  35.                 if (uart1.readable()) {
  36.                         ch = uart1.getc();
  37.                         j++;
  38.                 }
  39.         }
  40. }

用串口调试工具不停地定时发送数据,可以看到:
  如果cts悬空, 不停地打印 x/y, 表示数据丢失
  如果cts接地,只有满50才打印一次,没丢
kingpxl 发表于 2015-6-29 18:22 | 显示全部楼层
@steeven_lee
我刚好在调试串口RTS/CTS,遇到些问题。
steeven_lee,不写调试程序的话,直接用串口调试工具可以测试RTS/CTS吗?
lefeng 发表于 2015-6-29 18:51 | 显示全部楼层
只有把PA_11也就是CTS拉低才能往uart写数据,楼主是不是忽视了这个呢
kingpxl 发表于 2015-6-30 09:55 | 显示全部楼层
@lefeng
我现在是用PC和模块进行串口通信,用串口工具来测试。如何测试模块是否支持硬流控RTS/CTS?
以下是我的理解,用串口工具如何测试?
当PC的RTS为低时,模块的CTS则为低,此时模块向PC发送数据,PC接收数据。
当模块的RTS为低时,PC的CTS则为低,此时PC向模块发送数据,模块接收数据。

谢谢
豆腐块 发表于 2015-6-30 11:31 | 显示全部楼层
9楼的大师能把大概的电路传上来吗
kingpxl 发表于 2015-7-1 09:40 | 显示全部楼层
大师呢?
steeven_lee 发表于 2015-8-11 16:45 | 显示全部楼层
要看你的工具是否支持cts/rts测试了.... 多找几个板子试试, 看看波形电压比较容易找到原因.
Mrjiang88178 发表于 2015-8-14 13:39 | 显示全部楼层
jsh560 发表于 2019-1-14 12:44 | 显示全部楼层
你好,你用的硬件流程序还在吗?能否给我借鉴下。谢谢
hyhjhnhg 发表于 2019-1-14 14:17 | 显示全部楼层
没用过硬件流控制,进来学习下!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

13

主题

142

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部