Skip to content

Commit 4463ef3

Browse files
committed
【修改】stm32l4_pandora 示例文件
Signed-off-by: chenyong <[email protected]>
1 parent b00fa0f commit 4463ef3

File tree

5 files changed

+58
-12
lines changed

5 files changed

+58
-12
lines changed

examples/stm32l4_pandora/adc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from machine import ADC # Import the ADC class from machine
1212

13-
adc = ADC(2, 5) # Creates an ADC object that currently uses the 5 channels of an ADC device numbered 2
14-
adc.read() # Gets the ADC object sampling value
13+
adc = ADC(1, 13) # Creates an ADC object that currently uses the 13 channels of an ADC device numbered 1
14+
print(adc.read()) # Gets the ADC object sampling value, value range 0 to 4096
1515
adc.deinit() # Close ADC object
16-
adc.init(5) # Open and reconfigure the ADC object
16+
adc.init(13) # Open and reconfigure the ADC object

examples/stm32l4_pandora/pwm.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010

1111
from machine import PWM # Import PWM class from machine
1212

13-
pwm = PWM(1, 4, 1000, 100) # Create PWM object. Currently, 4 channels of PWM device numbered 1 are used.
13+
pwm = PWM(3, 3, 1000, 100) # Create PWM object. Currently, 3 channels of PWM device numbered 3 are used.
1414
# The initialization frequency is 1000Hz and the duty ratio value is 100 (duty ratio is 100/255 = 39.22%).
1515
pwm.freq(2000) # Set the frequency of PWM object
1616
pwm.freq() # Get the frequency of PWM object
17-
pwm.duty(200) # sets the duty ratio value of PWM object
17+
print(pwm) # Show PWM object information
18+
pwm.duty(200) # Sets the duty ratio value of PWM object
1819
pwm.duty() # Get the duty ratio value of PWM object
19-
pwm.deinit() # close PWM object
20-
pwm.init(4, 1000, 100) # open and reconfigure the PWM object
20+
print(pwm) # Show PWM object information
21+
pwm.deinit() # Close PWM object
22+
pwm.init(3, 1000, 100) # Open and reconfigure the PWM object
23+
print(pwm) # Show PWM object information

examples/stm32l4_pandora/rtc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
from machine import RTC
1212

13-
rtc = RTC() # Create an RTC device object
14-
rtc.init((2019,6,5,2,10,22,30,0)) # Set initialization time
15-
rtc.now() # Get the current time
16-
rtc.deinit() # Reset time to January 1, 2015
17-
rtc.now() # Get the current time
13+
rtc = RTC() # Create an RTC device object
14+
rtc.init((2019,6,5,2,10,22,30,0)) # Set initialization time
15+
print(rtc.now()) # Get the current time
16+
rtc.deinit() # Reset time to January 1, 2015
17+
print(rtc.now()) # Get the current time

examples/stm32l4_pandora/timer.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#
2+
# Copyright (c) 2006-2019, RT-Thread Development Team
3+
#
4+
# SPDX-License-Identifier: MIT License
5+
#
6+
# Change Logs:
7+
# Date Author Notes
8+
# 2019-06-29 ChenYong first version
9+
#
10+
11+
def callback_periodic(obj): # defined preiodic mode timeout callback
12+
print("Timer callback periodic test")
13+
14+
def callback_oneshot(obj): # defined ont shot mode timeout callback
15+
print("Timer callback oneshot test")
16+
17+
from machine import Timer
18+
import utime as time
19+
20+
timer = Timer(15) # Create Timer object. Timer device number 15 are used.
21+
timer.init(timer.PERIODIC, 1000, callback_periodic) # Initialize the Timer device object
22+
# Set Timer mode to preiodic mode, set timeout to 1 seconds and set callback fucntion
23+
time.sleep_ms(5500) # Execute 5 times timeout callback in the delay time
24+
timer.init(timer.ONE_SHOT, 1000, callback_oneshot) # Reset initialize the Timer device object
25+
# Set Timer mode to one shot mode, set timeout to 1 seconds and set callback fucntion
26+
time.sleep_ms(1500) # Execute 1 times timeout callback in the delay time
27+
timer.deinit() # Stop and close Timer device object

examples/stm32l4_pandora/wdt.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Copyright (c) 2006-2019, RT-Thread Development Team
3+
#
4+
# SPDX-License-Identifier: MIT License
5+
#
6+
# Change Logs:
7+
# Date Author Notes
8+
# 2019-06-29 ChenYong first version
9+
#
10+
11+
from machine import WDT
12+
13+
wdt = WDT(10) # Create an WDT device object, set the timeout to 10 seconds
14+
wdt.feed() # Perform the "feed dog" operation to clear the watchdog device count during the timout period
15+
# If not executed, the system will restart after the timeout
16+
print("reset system after 10 seconds")

0 commit comments

Comments
 (0)