I was checking a cheap MT6701 magnetic encoder module for a SimpleFOC setup. The MT6701 chip can do I2C, SSI and ABZ, but the 23 mm module I looked at only has five pads: VDD, GND, OUT, SCL and SDA. So getting SSI or ABZ out of it would mean reworking the board.
I only noticed because I put the module’s pinout next to the chip datasheet. Is that how you guys check a sensor board before buying, or is there a shortcut I’m missing?
I almost bought some of those a while back too, but also noticed there was no SPI breakout. I don’t think there’s a particular trick, it’s always case-by-case with how each board is designed and described.
In this case there were only 5 pins whereas SPI would normally need 6 (including power and ground). But with the cheap MT6835 boards on Amazon, I had to visually follow the traces in the images to map the pinout before buying, since the listings don’t show the back side where the labeling is.
I2C would probably be fine for most use cases if the reading were done asynchronously, but I don’t think there’s any cross-platform way to set that up so it would have to be specialized to whatever MCU you’re running on. I even do SPI asynchronous for maximum speed. It took a great deal of trial and error to distill the library code down to its essential operations, but here it is for STM32G431 if anyone ever needs it. Call SPI.begin(); at startup. The I2C_ADDR checks are unrelated to the sensor code, that’s just how I switch which axis I’m compiling for on my CNC (it has a different kind of sensor on each axis, but all are SPI)
void SPIAngleStart() {
HAL_SPI_Init(SPI.getHandle());
digitalWrite(SPI1_NSS, 0);
__HAL_SPI_ENABLE(SPI.getHandle());
#if (I2C_ADDR == I2C_ADDR_X)
u8 data[2] = { AS5047_ANGLECOM_REG&0xff, (AS5047_ANGLECOM_REG|AS5047_PARITY|AS5047_RW)>>8 };
#elif (I2C_ADDR == I2C_ADDR_Y)
u8 data[4] = { (MT6835_OP_ANGLE<<4), MT6835_REG_ANGLE1, 0, 0 };
#elif (I2C_ADDR == I2C_ADDR_Z)
u8 data[2] = { AS5048A_ANGLE_REG&0xff, (AS5048A_ANGLE_REG|AS5048A_PARITY|AS5048A_RW)>>8 };
#endif
for(int i = 0; i < (I2C_ADDR==I2C_ADDR_Y?4:2); i++) *(volatile u8*)&SPI1->DR = data[i];
}
void SPIAngleFinish() {
u8 data[4];
for(int i = 0; i < (I2C_ADDR==I2C_ADDR_Y?4:2); i++) { while(!(SPI1->SR&SPI_SR_RXNE)); data[i] = *(volatile u8*)&SPI1->DR; }
#if (I2C_ADDR == I2C_ADDR_X)
spiAngle = ((((u16)data[0]<<8)|data[1]) & AS5047_RESULT_MASK) << 2;
#elif (I2C_ADDR == I2C_ADDR_Y)
spiAngle = ((u16)data[2]<<8)|data[3];
#elif (I2C_ADDR == I2C_ADDR_Z)
spiAngle = ((((u16)data[0]<<8)|data[1]) & AS5048A_RESULT_MASK) << 2;
#endif
digitalWrite(SPI1_NSS, 1);
}
Then you also have to get that result into the SimpleFOC sensor class, e.g. using a derived class with modified getSensorAngle.
Following the traces in the photos is a good trick. Did the pinout you mapped from the pictures match once the MT6835 boards arrived?
Yep. I had to fill in VCC and GND after I got them, but those were known unknowns
The only unknown unknown was that there are three surface pads on the back for PWM interface. I’m not sure what HVPP is supposed to mean, but I double checked with multimeter that it does go to pin 4 on the chip, as I had deduced by drawing a line on the image.
Maybe the HVPP pin tells you how saturated the hall-grid is?
On the front it is called CAL_EN, which might indicate you can adjust the internal gain?
Thanks both, this was really useful. I honestly thought I was the only one squinting at listing photos. Next time I’ll count the pads against the interface I need, trace the back of the board in the photos before I buy, and check the pins with a multimeter once it arrives.