Tool/software:
Hi,
We've been pulling our hair out over the SPI comms with this motor controller. We're using a STM32F411 with SPI configured as following:

However, if we write like this:
uint8_t CalculateParity(uint16_t value) {
uint8_t parity = 0;
while (value) {
parity ^= (value & 1); // XOR jedes Bits
value >>= 1;
}
return parity;
}
void MCT8316ZR_WriteRegister(uint8_t reg, uint8_t data) {
uint16_t command = 0;
command = ((data) | (0 << 15)) | ((reg & 0x3F) << 9);
command |= (CalculateParity(command) & 0x01)<<8;
MCT8316ZR_Select();
HAL_SPI_Transmit(&hspi1, (uint8_t *)(&command), 1, HAL_MAX_DELAY);
MCT8316ZR_Deselect();
}
or Read like this:
uint16_t MCT8316ZR_ReadRegister(uint8_t reg) {
uint16_t command = 0;
uint16_t rxData;
command = (1 << 15) | ((reg & 0x3F) << 9);
command |= (CalculateParity(command) & 0x01) << 8;
MCT8316ZR_Select();
HAL_SPI_TransmitReceive(&hspi1, (uint8_t *)(&command), (uint8_t *)(&rxData), 1, HAL_MAX_DELAY);
MCT8316ZR_Deselect();
return rxData;
}
We get no answer on the SDO line of the Motor controller. We measure a SPI signal on the according pins with the oscilloscope which should be right if we compare it to the datasheet.
However, the configuration of the controller doesn't change and it also doesn't provide any answer on the SDO line.
That's what we get on the scope:

And this is what we send to get this data on the line:
MCT8316ZR_WriteRegister(MCT8316ZR_CONTROL_REGISTER_1, 0x03);
MCT8316ZR_WriteRegister(MCT8316ZR_CONTROL_REGISTER_2A, (0x03<<1));
MCT8316ZR_WriteRegister(MCT8316ZR_CONTROL_REGISTER_7, 1);
uint16_t test = MCT8316ZR_ReadRegister(MCT8316ZR_CONTROL_REGISTER_1);
Any idea why this isn't working properly?