2023-01-06 06:29 AM
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
2023-01-06 10:50 AM
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... :)
2023-01-06 08:02 PM
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.