This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

BOOST-DRV8711: DRV8711 Module (BOOSTDRV8711) SPI Communication

Part Number: BOOST-DRV8711
Other Parts Discussed in Thread: DRV8711, DRV8711EVM

Tool/software:

I am trying to read the registers of DRV8711. However, I am not able to do that. I do not know what is the issue here. I am using STM32H735IGK6 Controller. I then try to read the registers through SPI Communication but I cannot do it. Please reviewmy code and tell me whatis the issue. 

Code:-

void DRV8711_Write(uint8_t address, uint16_t data)

{

uint16_t frame = ((0 << 15) | ((address & 0x07) << 12) | (data & 0x0FFF));

uint8_t txData[2] = { (frame >> 8) & 0xFF, frame & 0xFF };

HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_SET); // CS HIGH

HAL_SPI_Transmit(&hspi5, txData, 2, HAL_MAX_DELAY);

HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_RESET); // CS = LOW

}

/**

* @brief Read a 12-bit value from DRV8711 register

* @param address : 3-bit register address (0x0–0x7)

* @return 12-bit register contents

*/

uint16_t DRV8711_Read(uint8_t address)

{

uint16_t cmd = ((1 << 15) | ((address & 0x07) << 12));

uint8_t txData[2] = { (cmd >> 8) & 0xFF, cmd & 0xFF };

uint8_t rxData[2] = {0};

// Frame 1: send read command

HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_SET); // CS HIGH

HAL_SPI_TransmitReceive(&hspi5, txData, rxData, 2, HAL_MAX_DELAY);

HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_RESET); // CS = LOW

return ((rxData[0] << 8) | rxData[1]) & 0x0FFF;

}

void DRV8711_Init(void)

{

// Example: configure CTRL register (0x0)

// MODE = 0 (Phase/Enable), ENBL=1

DRV8711_Write(0x0, 0x0001);

// Example: configure TORQUE register (0x1)

DRV8711_Write(0x1, 0x01FF);

// Example: configure DECAY register (0x2)

DRV8711_Write(0x2, 0x0000);

// ... configure other registers as needed

}

/**

* @brief Test function

*/

void DRV8711_Test(void)

{

uint16_t val;

DRV8711_Init();

val = DRV8711_Read(0x0); // Read back CTRL register

val = DRV8711_Read(0x1); // Read back TORQUE register

}

/* USER CODE END 0 */

/**

* @brief The application entry point.

* @retval int

*/

int main(void)

{

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/* MCU Configuration--------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */

HAL_Init();

/* USER CODE BEGIN Init */

/* USER CODE END Init */

/* Configure the system clock */

SystemClock_Config();

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_SPI5_Init();

/* USER CODE BEGIN 2 */

HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_RESET);

//

// HAL_GPIO_WritePin(Reset_GPIO_Port, Reset_Pin, GPIO_PIN_RESET);

// HAL_Delay(10);

HAL_GPIO_WritePin(Reset_GPIO_Port, Reset_Pin, GPIO_PIN_SET);

// HAL_Delay(10);

// HAL_GPIO_WritePin(Reset_GPIO_Port, Reset_Pin, GPIO_PIN_RESET);

HAL_GPIO_WritePin(Sleep_GPIO_Port, Sleep_Pin, GPIO_PIN_SET);

HAL_Delay(1000);

// uint16_t out = DRV8711_Read(0x00);

DRV8711_Test();

HAL_Delay(10);

/* USER CODE END 2 */

/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */

}

/* USER CODE END 3 */

}