Page 1 of 1

problem using UART.write('x')

Posted: Wed Dec 27, 2017 9:36 am
by nikhiledutech
Hey,
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 UART.read() 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)

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

uart.readinto(buf)
uart.write(buf)

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 uart.read() is working properly. Wishing for quick response.

Thankyou :)

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

Posted: Thu Dec 28, 2017 10:00 am
by pythoncoder
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.

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

Posted: Fri Dec 29, 2017 7:03 am
by nikhiledutech
Yes, i was able to see garbage value. Now i have used TTL logic and its working fine. Thanks for help :)