STM32 - Problem with sending data from PC to microcontroller

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
cabrillo
Posts: 1
Joined: Sun Jun 14, 2020 1:13 pm

STM32 - Problem with sending data from PC to microcontroller

Post by cabrillo » Sun Jun 14, 2020 1:22 pm

Hi,

I'm trying to send data from PC to STM32. Finally, the data will be displayed on the LCD.

Code on PC:

Code: Select all

import serial
import time

def main():
    ser = serial.Serial('COM5', 115200)
    time.sleep(2)
    print(ser)
    i = 0
    while i<=5:
        t = ser.write('test'.encode())
        i += 1

if __name__ == "__main__":
    main()
Code on STM32:

Code: Select all

# main.py
  
import machine
import pyb

uart = machine.UART(2, 115200)
uart.init(115200, bits=8, parity=None, stop=1, timeout=2000)

while True:
    pyb.LED(4).on()
    t = uart.read()
    if t:
        pyb.LED(1).on()
        pyb.delay(200)
        pyb.LED(1).off()
    else:
        pyb.LED(3).on()
        pyb.delay(200)
        pyb.LED(3).off()
    pyb.delay(200)
    pyb.LED(4).off()
    pyb.delay(200)
Interrupting program execution on the microcontroller (via Tera Term VT) I can see that the data is being transferred, but for unknown reasons I cannot read it in the program:

Code: Select all

Traceback (most recent call last):
  File "main.py", line 24, in <module>
KeyboardInterrupt:
MicroPython v1.12 on 2019-12-20; F4DISC with STM32F407
Type "help()" for more information.
>>> testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest
>>>

User avatar
dhylands
Posts: 3504
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: STM32 - Problem with sending data from PC to microcontroller

Post by dhylands » Mon Jun 15, 2020 7:26 pm

I'd recommend that on the host side you explicitly disable flow control.
https://github.com/dhylands/json-ipc/bl ... py#L12-L20

Post Reply