MT6701 sensor - only reading half a radian? 3.14 to 6.28


I’m excited to say I’ve got my first BLDC motor and magnetic sensor set up! I’m running the “magnetic_sensor_spi_example” code to test my MT6701 sensor. I have updated the code based off the requirements in the documentation for the MT6701. Serial monitor is showing smooth and accurate angle readings, however a full rotation is only reading between 3.14 and 6.28. I am using a Teensy 4.1.

What am I missing here? Code is below. Thank you!

#include <SimpleFOC.h>
#include <SimpleFOCDrivers.h>
#include <encoders/MT6701/MagneticSensorMT6701SSI.h>

MagneticSensorMT6701SSI sensor (10);

void setup() {
Serial.println(“Sensor ready”);

void loop() {

This smells to me like you are missing a bit, maybe the MSB is stuck or something.
I think there was an issue with this with the SSI driver before? Maybe it is not fixed for all boards.
Are you sure you are on the latest version of both simpleFOC and the drivers library?

I’m using Arduino’s IDE and I downloaded the simpleFOC and drivers libraries from the included library manager about two weeks ago. Do I need to be using a non-release version for this sensor? I can also switch to a different IDE if that would make a difference. I have to say MSB and bits being stuck goes over my head.


“some MCUs only see 13 bits instead of 14” - if this is the largest bit in the transmission (most significant bit MSB), I could see how you are stuck with half the usual range.

Gotcha. That makes sense, and it would explain it. Do you have any suggestions for a workaround, or am I out of luck with this sensor/MCU combination?

I’m not sure- probably have to wait for @runger to see if that is the issue.
Could you try on some board with a different mcu from the teensy? I actually don’t know if the library has any support for NXP chips like the teensy has.

The only other MCU I have is an old Arduino Uno, but I can try it out tomorrow and see what happens. Hopefully Runger will be able to offer some further insight. Thank you for your help VIP!

First suggestion would be to see if using one of the other SPI modes helps things:

SPISettings myMT6701SSISettings(100000, MT6701_BITORDER, SPI_MODE1); // try SPI mode 1 and slower speed
MagneticSensorMT6701SSI  sensor = MagneticSensorMT6701SSI(PIN_nCS, myMT6701SSISettings);

If this doesn’t solve the problem, then you can also try to use the #define MT6701_DATA_POS, please see the header file. By setting it to either 1 or 2 you can influence which bit position is read.

I’m sorry you’re having these problems. If you can confirm that Teensy works in one way or the other, I can add it to the header file for the next release…

Amazing. I tested the SPI mode fix first and that worked. Then I reverted it and tested the bit position fix and that also worked! Two in one, well done :grinning: Should I roll with the data position fix, or go to SPI mode 1? Is one or the other going to have lower latency?

So now I’m getting a full 0 to 6.28 radians, and it lines up perfectly with a full rotation. When I continue rotating it by hand more than one full rotation it goes into negative values or upwards of 6.28 infinitely. Is that correct operation for simpleFOC?

Yes, our sensor abstraction is absolute - so in position mode you can set the position to 10000 radians, and the motor will turn through many revolutions to reach the desired position.
In velocity or torque modes it is irrelevant.

huh, good question! The SPI mode fix is better for you, I guess, because it works immediately with no modification to the library code.

The data position fix is better for everyone else, because I can add a #if in the code for the teensy, and then it will be automatic for future users…

To be clear, setting #define MT6701_DATA_POS 1 fixed the problem, right?

Yes, that’s correct! Setting #define MT6701_DATA_POS 1 fixed it. I can confirm with this change I am getting proper closed loop angle control now. So satisfying. Thanks for your help!