Skip to main content
RS009
Associate II
January 6, 2023
Question

use of HAL_SPI_Transmit()

  • January 6, 2023
  • 2 replies
  • 964 views

I am using HAL_SPI_Transmit() API to write to slave's register, how can I confirm that it has actually find the right register and write to it? is below code right?

uint8_t R44=0x2C; //register address

uint8_t R44_data[2]={0x00,0x00};// data to be written

HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12, GPIO_PIN_RESET);//CS pin low

 HAL_SPI_Transmit(&hspi1, (uint8_t *)&R44, 1, 100); // transmit address

 HAL_SPI_Transmit(&hspi1, (uint8_t *)R44_data, 2, 100);//transmit data

 HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12, GPIO_PIN_SET);//CS pin high

This topic has been closed for replies.

2 replies

AScha.3
Super User
January 6, 2023

code looks ok.

but >it has actually find the right register < can see, if read back register (if target chip can do this)

otherwise only by watching what happens... :)

If you feel a post has answered your question, please click on " Best Answer ".
S.Ma
Principal
January 7, 2023

Use transmit receive function and make sure the code wait for TXE before writing and RXNE before raising NSS. Some post said this works only for some SPI config setting about PHA and POL.