# 在AMEBA\_AMB21上测试UART，结果异常

**URL:** <https://forum.amebaiot.com/t/ameba-amb21-uart/2908>\
**Category:** Peripherals\
**Tags:** 中文, rtl872xd\
**Created:** [May 4, 2024, 12:49pm UTC](https://forum.amebaiot.com/t/ameba-amb21-uart/2908 "2024-05-04T12:49:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kean0048](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/kean0048/32/2076_2.png) [@kean0048](https://forum.amebaiot.com/u/kean0048)\
**Post date:** [May 4, 2024, 12:49pm UTC](https://forum.amebaiot.com/t/ameba-amb21-uart/2908/1 "2024-05-04T12:49:31Z")

</div>

from machine import UART  
uart = UART(tx=“PA\_21”, rx= “PA\_22”)  
#uart = UART(tx=“PA\_26”, rx= “PA\_25”)  
#uart = UART(tx=“PB\_1”, rx= “PB\_2”)  
uart.write(“123”)  
uart.read # read up to 5 bytes

在几乎使用默认代码的情况下，是使用以上测试代码测试串口输出，我在另一端收到的数据是“g3f”（ g

3

f），从显示数据看两端的设置都是115200 8N1，但是有一个问题，就是在设置pin的文件里看到这写串口的口都被设置为上拉，如果实际情况不是上拉会产生这种情况吗？

谢谢

---

<div class="post-metadata">

**Author:** ![kean0048](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/kean0048/32/2076_2.png) [@kean0048](https://forum.amebaiot.com/u/kean0048)\
**Post date:** [May 4, 2024, 12:50pm UTC](https://forum.amebaiot.com/t/ameba-amb21-uart/2908/2 "2024-05-04T12:50:25Z")

</div>

from machine import UART  
uart = UART(tx=“PA\_21”, rx= “PA\_22”)  
#uart = UART(tx=“PA\_26”, rx= “PA\_25”)  
#uart = UART(tx=“PB\_1”, rx= “PB\_2”)  
uart.write(“123”)  
uart.read # read up to 5 bytes

使用以上测试代码，输出 g

3

f
