I'm using the DRV8350SRTVT chip which interfaces with STM32H7IGT6 MCU. The STM MCU is the master device and the gate driver is the slave device.
The configuration registers in the gate driver have to be set using SPI communication protocol. The code and settings for this have been attached below.
I'm able to read the configuration registers using SPI (able to see the default values), but writing or modifying the registers is not happening.
I have also set the LOCK bits in the Gate Drive HS to 011 (unlocked, so that I can modify the SPI registers). The gate drivers are enabled.
I'm not receiving any faults/errors in the SPI communication.
SCLK minimum period = 0.1 s
SPI speed: 537.109 Kbits/s ⇒ Time to transfer 1 bit = 1.86 s (verified value on the scope)
1) Write OCP register
Default value - 00101101101
Value to be written - 00100100000
Value received in Rx buffer as expected (value before modification)
2) Read OCP register AFTER writing the modified value to it
Value not being written to the register - there are no SPI errors but not able to modify the register
When I do a read, the default value is still being returned.
3) Read GATE DRIVER HS register (to check is SPI register bits are locked)
MSB of data bits - 011 (unlocked SPI registers)
CODE
//SPI6 parameter settings for gate driver
hspi6.Instance = SPI6;
hspi6.Init.Mode = SPI_MODE_MASTER;
hspi6.Init.Direction = SPI_DIRECTION_2LINES;
hspi6.Init.DataSize = SPI_DATASIZE_16BIT;
hspi6.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi6.Init.CLKPhase = SPI_PHASE_2EDGE;
hspi6.Init.NSS = SPI_NSS_SOFT;
hspi6.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
hspi6.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi6.Init.TIMode = SPI_TIMODE_DISABLE;
hspi6.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi6.Init.CRCPolynomial = 0x0;
hspi6.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
hspi6.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
hspi6.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
hspi6.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
hspi6.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
hspi6.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
hspi6.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
hspi6.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
hspi6.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
hspi6.Init.IOSwap = SPI_IO_SWAP_DISABLE;
#define GATEDRIVER_CSA_CONTROL_REGISTER_ADDRESS 0x6
void access_gate_driver_register{
/*Enable the gate driver - set the GPIO pin high*/
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_3, GPIO_PIN_SET);
HAL_Delay(1);
uint16_t commandword_read = (0x8000 | (reg_address << 11));
uint16_t commandword_write = ((reg_address << 11) | data_bits);
if (read_or_write_bit == GATEDRIVER_READ)
{
spi_tx_buffer_gate_driver = commandword_read;
}
else if (read_or_write_bit == GATEDRIVER_WRITE)
{
spi_tx_buffer_gate_driver = commandword_write;
}
HAL_GPIO_WritePin(NSS_port_gate_driver[hjoint->id], NSS_pin_gate_driver[hjoint->id], GPIO_PIN_RESET);
if(HAL_SPI_TransmitReceive(&hspi6, (uint8_t*)&spi_tx_buffer_gate_driver, (uint8_t*)&spi_rx_buffer_gate_driver, 1, HAL_TIMEOUT) != HAL_OK)
{
gate_driver_spi_error++;
}
HAL_GPIO_WritePin(NSS_port_gate_driver[hjoint->id], NSS_pin_gate_driver[hjoint->id], GPIO_PIN_SET);
}
ASYSTR_write_gate_driver_register(hjoint, GATEDRIVER_OCP_CONTROL_REGISTER_ADDRESS, 0b00100100000);
HAL_Delay(1);
ASYSTR_read_gate_driver_register(hjoint, GATEDRIVER_GATEDRIVER_HS_REGISTER_ADDRESS);