cancel
Showing results for 
Search instead for 
Did you mean: 

use of HAL_SPI_Transmit()

RS009
Associate III

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

2 REPLIES 2
AScha.3
Chief III

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 "Accept as Solution".
S.Ma
Principal

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.