Serial - bit banging

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
OutoftheBOTS_
Posts: 641
Joined: Mon Nov 20, 2017 10:18 am

Re: Serial - bit banging

Post by OutoftheBOTS_ » Fri May 31, 2019 9:45 pm

lukesky333 wrote:
Fri May 31, 2019 11:52 am
OutoftheBOTS_ wrote:
Wed May 29, 2019 11:01 pm
The STM32F407 MCUs have 5 UARTS (3 x USART and 2 X UART).


I prefer the STM32F407VGT6 with 1 mb of flash on the MCU and this board has another 16M-BIT of flash on a separate IC and is under $10US https://www.aliexpress.com/item/STM32F4 ... st=ae803_5

I am not sure if anyone has ported MP to this exact board but I know there is ports for STM32F407VET6 black which is the same but with only 512kb RAM on the MCU
Is it possible to use the same MicroPython version like for the STM32F407VET6 or does it need further development for this board?
It quite possibility will run as the 2 MCUs are exactly the same except the VG version has double the flash RAM size what may differ is the schematics the the rest of the board e.g both boards have SD card slot and external flash RAM but might be connected to different pins so there will need to be a change to the pin definitions in the micro-python firmware probably best to ask here https://github.com/mcauser/BLACK_F407VE

OutoftheBOTS_
Posts: 641
Joined: Mon Nov 20, 2017 10:18 am

Re: Serial - bit banging

Post by OutoftheBOTS_ » Fri May 31, 2019 10:04 pm

lukesky333 wrote:
Fri May 31, 2019 11:52 am
OutoftheBOTS_ wrote:
Wed May 29, 2019 11:01 pm
The STM32F407 MCUs have 5 UARTS (3 x USART and 2 X UART).


I prefer the STM32F407VGT6 with 1 mb of flash on the MCU and this board has another 16M-BIT of flash on a separate IC and is under $10US https://www.aliexpress.com/item/STM32F4 ... st=ae803_5

I am not sure if anyone has ported MP to this exact board but I know there is ports for STM32F407VET6 black which is the same but with only 512kb RAM on the MCU
Is it possible to use the same MicroPython version like for the STM32F407VET6 or does it need further development for this board?
The 2 MCUs are exactly the same just the VG version has double the flash RAM. It is possible that the boards may have some difference in the schematics but at a very quick look they seem to be the same. You can ask on this thread viewtopic.php?f=12&t=3086&hilit=Black+STM32F407VET6 or on github here https://github.com/mcauser/BLACK_F407VE

lukesky333
Posts: 37
Joined: Fri Sep 02, 2016 4:07 pm
Location: Austria

Re: Serial - bit banging

Post by lukesky333 » Thu Jun 13, 2019 1:21 pm

OutoftheBOTS_ wrote:
Wed May 29, 2019 11:01 pm
...
From the reference manual the STM32F407 supports 9 bit serial by setting the M bit in the UART control register
UART 9.JPG
I've got my NUCLEO-F446RE board and it's running with MicroPython v1.11-37 now. ...so far so good...

What is to do to read the serial connection in 9-bit mode?

I tried following code:

Code: Select all

import machine
import ubinascii

u1 = machine.UART(1, 19200)
u1.init(19200, bits=9, parity=None, stop=1)

while True:
    d1 = u1.readline()
    # d1 = u1.read(1)
    if d1 is not None:
        print(str(ubinascii.hexlify(d1)))
With this code I got following error message:

Code: Select all

OSError: [Errno 5] EIO
What is wrong with the code?

How can I set the M bit in the UART control register

lukesky333
Posts: 37
Joined: Fri Sep 02, 2016 4:07 pm
Location: Austria

Re: Serial - bit banging

Post by lukesky333 » Thu Jun 13, 2019 3:26 pm

lukesky333 wrote:
Thu Jun 13, 2019 1:21 pm
What is wrong with the code?

How can I set the M bit in the UART control register
Ok, I've found the mistake...

Code: Select all

d1 = u1.read(2)
I need to read 2 chars to all 9 bits. ;-)

But I still don't see the wakeup bit. How can i do it?

OutoftheBOTS_
Posts: 641
Joined: Mon Nov 20, 2017 10:18 am

Re: Serial - bit banging

Post by OutoftheBOTS_ » Thu Jun 13, 2019 8:05 pm

lukesky333 wrote:
Thu Jun 13, 2019 3:26 pm
lukesky333 wrote:
Thu Jun 13, 2019 1:21 pm
What is wrong with the code?

How can I set the M bit in the UART control register
Ok, I've found the mistake...

Code: Select all

d1 = u1.read(2)
I need to read 2 chars to all 9 bits. ;-)

But I still don't see the wakeup bit. How can i do it?
Ok I have not yet ever needed to use 9 bit UART so had to do a bit of googling. Seems 9 bit UART on STM32 works by it stores the 9 bits over 2 bytes. The first bytes stores the bottom 8 bits then the second byte stores the 9th bit plus bits reset values of the UART_DR register so you need to use a mask to chop off the unneeded bits in the second byte to get the 9th bit :)

lukesky333
Posts: 37
Joined: Fri Sep 02, 2016 4:07 pm
Location: Austria

Re: Serial - bit banging

Post by lukesky333 » Fri Jun 14, 2019 10:34 am

OutoftheBOTS_ wrote:
Thu Jun 13, 2019 8:05 pm
...
Ok I have not yet ever needed to use 9 bit UART so had to do a bit of googling. Seems 9 bit UART on STM32 works by it stores the 9 bits over 2 bytes. The first bytes stores the bottom 8 bits then the second byte stores the 9th bit plus bits reset values of the UART_DR register so you need to use a mask to chop off the unneeded bits in the second byte to get the 9th bit :)
It was a protocol issue - the other uart connection shows the wakeup bit like expected. :-)

Post Reply