Explorar o código

【修改】stm32l4_pandora 示例文件

Signed-off-by: chenyong <1521761801@qq.com>
chenyong %!s(int64=6) %!d(string=hai) anos
pai
achega
4463ef37ac

+ 3 - 3
examples/stm32l4_pandora/adc.py

@@ -10,7 +10,7 @@
 
 from machine import ADC     # Import the ADC class from machine
 
-adc = ADC(2, 5)             # Creates an ADC object that currently uses the 5 channels of an ADC device numbered 2
-adc.read()                  # Gets the ADC object sampling value
+adc = ADC(1, 13)            # Creates an ADC object that currently uses the 13 channels of an ADC device numbered 1
+print(adc.read())           # Gets the ADC object sampling value, value range 0 to 4096
 adc.deinit()                # Close ADC object
-adc.init(5)                 # Open and reconfigure the ADC object
+adc.init(13)                # Open and reconfigure the ADC object

+ 7 - 4
examples/stm32l4_pandora/pwm.py

@@ -10,11 +10,14 @@
 
 from machine import PWM     # Import PWM class from machine
 
-pwm = PWM(1, 4, 1000, 100)  # Create PWM object. Currently, 4 channels of PWM device numbered 1 are used. 
+pwm = PWM(3, 3, 1000, 100)  # Create PWM object. Currently, 3 channels of PWM device numbered 3 are used. 
                             # The initialization frequency is 1000Hz and the duty ratio value is 100 (duty ratio is 100/255 = 39.22%).
 pwm.freq(2000)              # Set the frequency of PWM object
 pwm.freq()                  # Get the frequency of PWM object
-pwm.duty(200)               # sets the duty ratio value of PWM object
+print(pwm)                  # Show PWM object information
+pwm.duty(200)               # Sets the duty ratio value of PWM object
 pwm.duty()                  # Get the duty ratio value of PWM object
-pwm.deinit()                # close PWM object
-pwm.init(4, 1000, 100)      # open and reconfigure the PWM object
+print(pwm)                  # Show PWM object information
+pwm.deinit()                # Close PWM object
+pwm.init(3, 1000, 100)      # Open and reconfigure the PWM object
+print(pwm)                  # Show PWM object information

+ 5 - 5
examples/stm32l4_pandora/rtc.py

@@ -10,8 +10,8 @@
 
 from machine import RTC
 
-rtc = RTC()                        # Create an RTC device object
-rtc.init((2019,6,5,2,10,22,30,0))  # Set initialization time
-rtc.now()                          # Get the current time
-rtc.deinit()                       # Reset time to January 1, 2015
-rtc.now()                          # Get the current time
+rtc = RTC()                            # Create an RTC device object
+rtc.init((2019,6,5,2,10,22,30,0))      # Set initialization time
+print(rtc.now())                       # Get the current time
+rtc.deinit()                           # Reset time to January 1, 2015
+print(rtc.now())                       # Get the current time

+ 27 - 0
examples/stm32l4_pandora/timer.py

@@ -0,0 +1,27 @@
+# 
+# Copyright (c) 2006-2019, RT-Thread Development Team
+# 
+# SPDX-License-Identifier: MIT License
+# 
+# Change Logs:
+# Date           Author       Notes
+# 2019-06-29     ChenYong     first version
+#
+
+def callback_periodic(obj):                                # defined  preiodic mode timeout callback
+    print("Timer callback periodic test")
+
+def callback_oneshot(obj):                                 # defined  ont shot mode timeout callback
+    print("Timer callback oneshot test")
+
+from machine import Timer
+import utime as time
+
+timer = Timer(15)                                          # Create Timer object. Timer device number 15 are used. 
+timer.init(timer.PERIODIC, 1000, callback_periodic)        # Initialize the Timer device object
+                                                           # Set Timer mode to preiodic mode, set timeout to 1 seconds and set callback fucntion
+time.sleep_ms(5500)                                        # Execute 5 times timeout callback in the delay time
+timer.init(timer.ONE_SHOT, 1000, callback_oneshot)         # Reset initialize the Timer device object
+                                                           # Set Timer mode to one shot mode, set timeout to 1 seconds and set callback fucntion
+time.sleep_ms(1500)                                        # Execute 1 times timeout callback in the delay time
+timer.deinit()                                             # Stop and close Timer device object

+ 16 - 0
examples/stm32l4_pandora/wdt.py

@@ -0,0 +1,16 @@
+# 
+# Copyright (c) 2006-2019, RT-Thread Development Team
+# 
+# SPDX-License-Identifier: MIT License
+# 
+# Change Logs:
+# Date           Author       Notes
+# 2019-06-29     ChenYong     first version
+#
+
+from machine import WDT
+
+wdt = WDT(10)                # Create an WDT device object, set the timeout to 10 seconds
+wdt.feed()                   # Perform the "feed dog" operation to clear the watchdog device count during the timout period
+                             # If not executed, the system will restart after the timeout
+print("reset system after 10 seconds")