Two SPI classes in DRV8316

Hi everyone i developed a custom board with drv8316 and as5047u and tested in open loop mode it worked perfectly and then i tested the as5047 separately magnetic sensor it also worked fine but when put them together the as5047 is not working i mean i’m not getting the readings from it and the initFOC can’t notice any movement.

#include "Arduino.h"
#include <Wire.h>
#include <SimpleFOC.h>
#include <Math.h>
#include "SimpleFOCDrivers.h"
#include "drivers/drv8316/drv8316.h"

MagneticSensorSPI as5047u = MagneticSensorSPI(PB2, 14, 0x3FFF);
BLDCMotor motor = BLDCMotor(7);
DRV8316Driver6PWM driver = DRV8316Driver6PWM(PA8,PB13,PA9,PB14,PA10,PB15,PB12,false,PB9,PB10); 
SPIClass SPI_2(PB5, PB4, PB3);

void printDRV8316Status() {
	DRV8316Status status = driver.getStatus();
	Serial.println("DRV8316 Status:");
	Serial.print("Fault: ");
	Serial.println(status.isFault());
	Serial.print("Buck Error: ");
	Serial.print(status.isBuckError());
	Serial.print("  Undervoltage: ");
	Serial.print(status.isBuckUnderVoltage());
	Serial.print("  OverCurrent: ");
	Serial.println(status.isBuckOverCurrent());
	Serial.print("Charge Pump UnderVoltage: ");
	Serial.println(status.isChargePumpUnderVoltage());
	Serial.print("OTP Error: ");
	Serial.println(status.isOneTimeProgrammingError());
	Serial.print("OverCurrent: ");
	Serial.print(status.isOverCurrent());
	Serial.print("  Ah: ");
	Serial.print(status.isOverCurrent_Ah());
	Serial.print("  Al: ");
	Serial.print(status.isOverCurrent_Al());
	Serial.print("  Bh: ");
	Serial.print(status.isOverCurrent_Bh());
	Serial.print("  Bl: ");
	Serial.print(status.isOverCurrent_Bl());
	Serial.print("  Ch: ");
	Serial.print(status.isOverCurrent_Ch());
	Serial.print("  Cl: ");
	Serial.println(status.isOverCurrent_Cl());
	Serial.print("OverTemperature: ");
	Serial.print(status.isOverTemperature());
	Serial.print("  Shutdown: ");
	Serial.print(status.isOverTemperatureShutdown());
	Serial.print("  Warning: ");
	Serial.println(status.isOverTemperatureWarning());
	Serial.print("OverVoltage: ");
	Serial.println(status.isOverVoltage());
	Serial.print("PowerOnReset: ");
	Serial.println(status.isPowerOnReset());
	Serial.print("SPI Error: ");
	Serial.print(status.isSPIError());
	Serial.print("  Address: ");
	Serial.print(status.isSPIAddressError());
	Serial.print("  Clock: ");
	Serial.print(status.isSPIClockFramingError());
	Serial.print("  Parity: ");
	Serial.println(status.isSPIParityError());
	if (status.isFault())
		driver.clearFault();
	delayMicroseconds(1); // ensure 400ns delay
	DRV8316_PWMMode val = driver.getPWMMode();
	Serial.print("PWM Mode: ");
	Serial.println(val);
	delayMicroseconds(1); // ensure 400ns delay
	bool lock = driver.isRegistersLocked();
	Serial.print("Lock: ");
	Serial.println(lock);
}


void setup() {
	as5047u.init();
	Serial.begin(115200);
	while (!Serial);
	delay(1);
	Serial.println("Initializing...");

	driver.voltage_power_supply = 12;
	driver.init(&SPI_2);
	motor.linkDriver(&driver);
	motor.controller = MotionControlType::velocity_openloop;
	motor.voltage_limit = 0.6;
	motor.velocity_limit = 20;
	motor.init();
	Serial.println("Init complete...");

	delay(100);
	printDRV8316Status();
}

// velocity set point variable
float target_velocity = 7.0;

void loop() {
  as5047u.update();
  // display the angle and the angular velocity to the terminal
  Serial.print(as5047u.getAngle());
  Serial.print("\t");
  Serial.println(as5047u.getVelocity());
}

the above is my code please take a look at it. Thank you

Edit : i tried creating a new spi_1 class and passing them to the as5047u.init(&spi_1); but still same response

So i tried everything i could can’t get it to work can somebody please take a look at this?

The code actually looks ok at first glance… I’m not sure what’s up there.

The driver would be using your SPI_2 object while the sensor is using the SPI object.

One thing that’s not clear from the code is which pins are being used by the standard SPI object. You’re using separate buses I assume, so SPI should be using all different pins from SPI_2?

On a seperate note we have a dedicated driver for the as5047u object. Using this you can set all the registers of the sensor… you can find it here: Arduino-FOC-drivers/src/encoders/as5047u at master · simplefoc/Arduino-FOC-drivers · GitHub