Hi @Owen_Williams ,
Nucleo-64
STM32F446RE
The SPI pins is as described in the pinout. PA5, PA6, PA7.
The 3 sensors uses different CS. PB8 PC9 PB9.
This works on 1 board now. The other board just refuse to work and keep displaying 6.28.
Iām more pleplexed by the PWMs. The current setting uses 9,5,6,8. i.e. PC7, PB4, PB10, PA9.
One board can move the motor in this setting, the other board canāt.
i.e.
board 1) -> can move motor, cannot use SPI.
board 2) -> cannot move motor can use SPI.
Codes are the same. Driver is the same. Wiring is the same. Arduino Uno uses the same driver and works perfectly.
Weird behaviour,
The board take cannot move, I tried the following pins, PA8, PA9, PA10, PA11 (because the timers are the same, 1/1, 1/2, 1/3/, 1/4 from the pinout diagram). The motor oscillate between 2 points. However, this is also the only time where the motor can move without power supply to the driver. Previously only the Uno can move the motor without power supply to the driver.
Codes for motor motion uses the example given above, with the only differences below.
BLDCMotor motor = BLDCMotor(7);
BLDCDriver3PWM driver = BLDCDriver3PWM(PA8, PA9, PA10, PA11);
or
BLDCDriver3PWM driver = BLDCDriver3PWM(PC7, PB4, PB10, PA9);
Sensor codes,
#include <SPI.h>
//simplefoc
#include <SimpleFOC.h>
MagneticSensorSPI sensor1 = MagneticSensorSPI(PB9, 14, 0x3FFF);
MagneticSensorSPI sensor2 = MagneticSensorSPI(PB8, 14, 0x3FFF);
MagneticSensorSPI sensor3 = MagneticSensorSPI(PC9, 14, 0x3FFF);
//SPIClass SPI_1(PA7, PA6, PA5);//mosi miso, sclk
void setup() {
// put your setup code here, to run once:
SPI.begin();
//simplefoc sensor init
sensor1.spi_mode = SPI_MODE1; // spi mode - OPTIONAL
sensor1.clock_speed = 500000; // spi clock frequency - OPTIONAL
//sensor1.init(&SPI_1);
sensor1.init();
delay(10);
sensor2.spi_mode = SPI_MODE1; // spi mode - OPTIONAL
sensor2.clock_speed = 500000; // spi clock frequency - OPTIONAL
sensor2.init(&SPI_1);
delay(10);
sensor3.spi_mode = SPI_MODE1; // spi mode - OPTIONAL
sensor3.clock_speed = 500000; // spi clock frequency - OPTIONAL
sensor3.init(&SPI_1);
delay(10);
//serial setup
Serial.begin(115200);
delay(1000);
}
void loop() {
// put your main code here, to run repeatedly:
//sensor1.spi_mode = SPI_MODE0; // spi mode - OPTIONAL
//sensor1.clock_speed = 500000; // spi clock frequency - OPTIONAL
//sensor1.init();
//sensor1.init(&SPI_1);
sensor1.init();
Serial.print(sensor1.getAngle());
Serial.print("\t");
sensor2.init(&SPI_1);
Serial.print(sensor2.getAngle());
Serial.print("\t");
sensor3.init(&SPI_1);
Serial.println(sensor3.getAngle());
delay(10);
}