problem using UART.write('x')

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

problem using UART.write('x')

Post by nikhiledutech » Wed Dec 27, 2017 9:36 am

Currently i am working on STM32F407discovery board. So i am programming USART6 ( tx pin PC6 and rx pin pc7) for asynchronous communication. So at present i am able to read values with the help of but UNABLE to use UART.write() function.

Below is my code , kindly go through it and help me :)

import pyb
from pyb import Pin, UART
tx = pyb.Pin('PC6', Pin.OUT_PP, Pin.PULL_UP)
rx = pyb.Pin('PC7', Pin.OUT_PP, Pin.PULL_UP)

uart = UART(6,9600,8,None,1)
buf = bytearray(20)


So in the above code i have created array of size 20. When i use uart.readinto(buf) the keys pressed on terminal2 (baudrate 9600) are stored in the buffer. But whenever, i try to print it on terminal using uart.write(buf) , it give some sort of garbage value. I have checked the baud rate of both UART6 and terminal it's same.

Also simple functions like uart.write('123') are also not working. I think their is some mistake in my steps because is working properly. Wishing for quick response.

Thankyou :)

User avatar
Posts: 3214
Joined: Fri Jul 18, 2014 8:01 am
Location: UK

Re: problem using UART.write('x')

Post by pythoncoder » Thu Dec 28, 2017 10:00 am

I'm not familiar with your board but in general it isn't necessary to initialise the pins to use a UART: creating the UART object does this for you. That said, I can't see why uart.write(b'123') won't work. Do you see garbage at the other end or nothing? If you have access to a scope or logic analyser it would be worth looking at the tx pin.
Peter Hinch

Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

Re: problem using UART.write('x')

Post by nikhiledutech » Fri Dec 29, 2017 7:03 am

Yes, i was able to see garbage value. Now i have used TTL logic and its working fine. Thanks for help :)

Post Reply