STM32F103 - Правим примеры
- Войдите на сайт для отправки комментариев
Чт, 01/11/2018 - 22:01
Столкнулся с тем, что примеры из аддона STM32 на процессоре STM32F103 не работают.
Добавлю исправленные примеры:
BLINK
/* Blink Turns on an LED on for one second, then off for one second, repeatedly. Most Arduinos have an on-board LED you can control. On the Uno and Leonardo, it is attached to digital pin 13. If you're unsure what pin the on-board LED is connected to on your Arduino model, check the documentation at http://arduino.cc This example code is in the public domain. modified 8 May 2014 by Scott Fitzgerald Modified by Roger Clark. www.rogerclark.net for Maple mini 25th April 2015 , where the LED is on PB1 */ // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin PB1 (PC13) as an output. pinMode(PC13, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(PC13, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(PC13, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second }
AnalogInOutSerial
/* Analog input, analog output, serial output Reads an analog input pin, maps the result to a range from 0 to 65535 and uses the result to set the pulse width modulation (PWM) of an output pin. Also prints the results to the serial monitor. (You may need to change the pin numbers analogInPin and analogOutPin if you're not using a Maple). The circuit: * Potentiometer connected to analog pin 15. Center pin of the potentiometer goes to the analog pin. Side pins of the potentiometer go to +3.3V and ground. * LED connected from digital pin 9 to ground created 29 Dec. 2008 by Tom Igoe ported to Maple by LeafLabs */ // These constants won't change. They're used to give names // to the pins used: const int analogInPin = PA0; // Analog input pin that the potentiometer // is attached to const int pwmOutPin = 9; // PWM pin that the LED is attached to // These variables will change: int sensorValue = 0; // value read from the pot int outputValue = 0; // value output to the PWM void setup() { // Configure the ADC pin pinMode(analogInPin, INPUT_ANALOG); // Configure LED pin pinMode(pwmOutPin, PWM); Serial.begin(115200); // Ignored by Maple. But needed by boards using Hardware serial via a USB to Serial Adaptor } void loop() { // read the analog in value: sensorValue = analogRead(analogInPin); // map it to the range of the analog out: outputValue = map(sensorValue, 0, 4096, 0, 65535); // change the analog out value: pwmWrite(pwmOutPin, outputValue); // print the results to the serial monitor: Serial.print("sensor = " ); Serial.print(sensorValue); Serial.print("\t output = "); Serial.println(outputValue); }
/* Analog input, serial output Reads an analog input pin, prints the results to the serial monitor. The circuit: * Potentiometer connected to analog pin 15 (на пин A0). * Center pin of the potentiometer goes to the analog pin. * Side pins of the potentiometer go to +3.3V (VCC) and ground created over and over again by Tom Igoe and everyone who's ever used Arduino Ported to Maple 27 May, 2010 by Bryan Newbold */ // Analog input pin. You may need to change this number if your board // can't do analog input on pin PA0. const int analogInputPin = PA0; void setup() { // Declare analogInputPin as INPUT_ANALOG: pinMode(analogInputPin, INPUT_ANALOG); Serial.begin(115200); // Ignored by Maple. But needed by boards using Hardware serial via a USB to Serial Adaptor } void loop() { // Read the analog input into a variable: int analogValue = analogRead(analogInputPin); // print the result: Serial.println(analogValue); }
Пример работы с сервой, подправил для проверки работы двух функций, перемещение по углу и отработка по длительности импульса ШИМ (из-за нелинейности вычисления получилась простая игрушка - найдите точку бифуркации)
ua6em - если хотите, что топик был полезным - в каждом случае пишите что именно поправили и почему. Прямо-таки теряюсь в догадках, что можно было поправитьв Блинке - номер пина? :)))
И про другие примеры тоже интересно
ua6em - если хотите, что топик был полезным - в каждом случае пишите что именно поправили и почему. Прямо-таки теряюсь в догадках, что можно было поправитьв Блинке - номер пина? :)))
И про другие примеры тоже интересно
Действительно!
1. Блинк - изменен номер пина с 33 на номер пина к которому подключен светодиод на плате - PC13
2. AnalogInOutSerial - исправлена строка 48, приведена в соответствии с разрешающей способностью АЦП
3. AnalogInputSerialOutput - исправлены строки 19,20 порты обозначены в соответствии с маркировкой платы
4. Пример работы с сервой - исправлены строки 20,25, добавлены строки 30-34 для проверки отработки фунции позиционирования по передаваемому значению длительности импульса в микросекундах.