Skip to content

Commit 48192e0

Browse files
committed
issue #102 : update exxmple esp32 and added the sample code for second spi HSPI
1 parent 8a86629 commit 48192e0

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

.github/workflows/ccpp.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ jobs:
3838

3939
- arduino-boards-fqbn: esp32:esp32:esp32doit-devkit-v1 # esp32
4040
platform-url: https://dl.espressif.com/dl/package_esp32_index.json
41-
sketch-names: esp32_position_control.ino, esp32_i2c_dual_bus_example.ino, esp32_current_control_low_side.ino
41+
sketch-names: esp32_position_control.ino, esp32_i2c_dual_bus_example.ino, esp32_current_control_low_side.ino, esp32_spi_alt_example.ino
4242

4343
- arduino-boards-fqbn: STM32:stm32:GenF1:pnum=BLUEPILL_F103C8 # bluepill - hs examples
4444
platform-url: https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json
45-
sketch-names: bluepill_position_control.ino, stm32_i2c_dual_bus_example.ino, magnetic_sensor_spi_alt_example.ino
45+
sketch-names: bluepill_position_control.ino, stm32_i2c_dual_bus_example.ino, stm32_spi_alt_example.ino
4646

4747
- arduino-boards-fqbn: STM32:stm32:Nucleo_64:pnum=NUCLEO_F411RE # one full example
4848
platform-url: https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json
49-
sketch-names: single_full_control_example.ino
49+
sketch-names: single_full_control_example.ino, stm32_spi_alt_example.ino
5050

5151

5252

examples/hardware_specific_examples/ESP32/magnetic_sensor/esp32_position_control/esp32_position_control.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// MOSI 9
99
// SCK 14
1010
// magnetic sensor instance - SPI
11-
MagneticSensorSPI sensor = MagneticSensorSPI(AS5147_SPI, 10);
11+
MagneticSensorSPI sensor = MagneticSensorSPI(AS5147_SPI, 15);
1212

1313
// I2C Magnetic sensor instance (AS5600 example)
1414
// make sure to use the pull-ups!!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <SimpleFOC.h>
2+
3+
// alternative pinout
4+
#define HSPI_MISO 12
5+
#define HSPI_MOSI 13
6+
#define HSPI_SCLK 14
7+
#define HSPI_SS 15
8+
9+
// MagneticSensorSPI(int cs, float _cpr, int _angle_register)
10+
// config - SPI config
11+
// cs - SPI chip select pin
12+
MagneticSensorSPI sensor = MagneticSensorSPI(AS5147_SPI, HSPI_SS);
13+
14+
// for esp 32, it has 2 spi interfaces VSPI (default) and HPSI as the second one
15+
// to enable it instatiate the object
16+
SPIClass SPI_2(HSPI)
17+
18+
void setup() {
19+
// monitoring port
20+
Serial.begin(115200);
21+
22+
// start the newly defined spi communication
23+
SPI_2.begin(HSPI_SCLK, HSPI_MISO, HSPI_MOSI, HSPI_SS); //SCLK, MISO, MOSI, SS
24+
// initialise magnetic sensor hardware
25+
sensor.init(&SPI_2);
26+
27+
Serial.println("Sensor ready");
28+
_delay(1000);
29+
}
30+
31+
void loop() {
32+
// iterative function updating the sensor internal variables
33+
// it is usually called in motor.loopFOC()
34+
// this function reads the sensor hardware and
35+
// has to be called before getAngle nad getVelocity
36+
sensor.update();
37+
// display the angle and the angular velocity to the terminal
38+
Serial.print(sensor.getAngle());
39+
Serial.print("\t");
40+
Serial.println(sensor.getVelocity());
41+
}

0 commit comments

Comments
 (0)