SPI 16-bit data transmit

100 views Asked by At

hi i m currently using STM32H7A2 SPI to transmit 8 bit data out and its working successfully, see code below with address and data respectively, can anyone advise how to transmit 16 bit data only code base on the following code? the code below is working fine when sending SPi with address bit and data bit, but now i need to modify to send 16 bit data out with only data address on SPI, Anyone can advise?

uint8_t dataOut = 0x50;
uint8_t regAddr = 18; // address of register

HAL_StatusTypeDef spi_write(uint8_t regAddr, uint8_t *pData)
{
  HAL_StatusTypeDef ret;
  uint8_t sendData[2] = {regAddr, *pData};

  // Start communication
  HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, 0);

  // send reg addr and data to write into
  ret = HAL_SPI_Transmit(&hspi1, sendData, 2, 20);
  if (ret != HAL_OK) {
    HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, 1);
    return ret;
  }
}
1

There are 1 answers

0
Jib On

The ST HAL provides an initialisation structure which exposes a field Init.DataSize that you can use to change de default data unit to be transfered on the bus.

This field can take one of the following values: SPI_DATASIZE_8BIT, SPI_DATASIZE_16BIT.