low power waiting for uart rx

Discussion related to "under the hood" OpenMV topics.
User avatar
chrisPyres66
Posts: 76
Joined: Mon Jul 16, 2018 9:22 am
Location: France

low power waiting for uart rx

Postby chrisPyres66 » Tue Dec 04, 2018 10:41 am

Hello,

I would like to optimize consumption during the time the cpu wait the uart receipt.
I wrote below the different way and names i found on internet documentation about :

STM32 ------------ machine ---------- pyb --------------- time
sleep ---------------- idle ------------ wfi ---------- time.sleep(time_ms)
stop --------------- sleep ---------- stop
standby --------- deepsleep ----- standby

STMicroelectronics answered me it is possible to wake up from stop mode with uart here :
https://community.st.com/s/question/0D7 ... =1&s1ext=0
altough i dont know if i can get the first uart receipt data.

I connected Rx of uart 3 with PB3 to get an external interruption on uart receipt, then I tried this code with different ways below :

Code: Select all

import sensor,image,pyb,time, machine
red_led   = pyb.LED(1)
red_led.off()

UARTSIZE = 8
uart=pyb.UART(3,14400)
uart.init(14400, bits=8, parity=None, stop=1, timeout_char=20) #, timeout_char=20

def readUART():
   if uart.any():
      uchar=uart.read(UARTSIZE)
      if len(uchar) == UARTSIZE :
         return uchar
   return

rtc = pyb.RTC()
rtc.datetime((2014, 5, 1, 4, 13, 0, 0, 0))
#rtc.wakeup(5)

def test(arg):
   #extint.disable()
   pass

extint = pyb.ExtInt('P3', pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_NONE, test)

while(True):
   time.sleep(10)
   #rtc.wakeup(20,test)
   #extint.enable()
   #machine.idle() 
   #extint.enable()
   #pyb.stop()
   #pyb.wfi()
   uchar=readUART()
   if uchar :                     
      #red_led.toggle()
      if uchar[3] == 0x0D : 
          red_led.toggle()
Unfortunately, i dont get the full uart rx if i stop the cpu.
The time.sleep(10) is the best way to have the lowest consumption.

Am i right ?

Thanks,
User avatar
kwagyeman
Posts: 2904
Joined: Sun May 24, 2015 2:10 pm

Re: low power waiting for uart rx

Postby kwagyeman » Tue Dec 04, 2018 12:43 pm

Ibrahim can you help out here?
Nyamekye,
User avatar
iabdalkader
Posts: 732
Joined: Sun May 24, 2015 3:53 pm

Re: low power waiting for uart rx

Postby iabdalkader » Tue Dec 04, 2018 3:49 pm

It should wake up on any interrupt (including RXNE) you don't need to configure UART pins as EXTI. Please remove that and all the comments and RTC code and try it again. Also I don't understand this part: "i dont get the full uart rx if i stop the cpu." ?
User avatar
chrisPyres66
Posts: 76
Joined: Mon Jul 16, 2018 9:22 am
Location: France

Re: low power waiting for uart rx

Postby chrisPyres66 » Wed Dec 05, 2018 3:02 am

Here is the simplified code which works without activating the sleep mode

Code: Select all

import pyb, machine

red_led = pyb.LED(1)
red_led.off()

uart = pyb.UART(3,14400)
uart.init(14400, bits=8, parity=None, stop=1, timeout_char=20)

while(True):
   #machine.sleep()
   uchar=uart.read(1)
   if uchar :
      uart.writechar(uchar[0])
      red_led.toggle()
If the sleep is activated, there is no answer.

About : Also I don't understand this part: "i dont get the full uart rx if i stop the cpu." ?
I receive a uart frame (8 bytes), and when i wake up with the external interrupt, i dont get the first data when i use sleep mode.
User avatar
iabdalkader
Posts: 732
Joined: Sun May 24, 2015 3:53 pm

Re: low power waiting for uart rx

Postby iabdalkader » Wed Dec 05, 2018 6:44 pm

Actually with the clock disabled UART won't generate the interrupt (I think this should work on the H7 with LPUART). You could either use an external GPIO as EXTI (a different pin other than UART pins), or use pyb.wfi(). pyb.wfi will be interrupted by UART or SYSTICK.

Return to “Technical Discussion”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests