Question
SPI sending out 32-bit data when configured for 16-bit
Posted on June 30, 2018 at 17:32
#16-bit-spi #spi-communication #spi-master-mode #hal-spi
I've configured the STM32F103C8 for 16-bit data transfers. On the scope I can see my 16-bit data which is followed by some garbage data that the MCU is not configured to send. Am I mis-configuring something? How do I ensure that only 16-bits are sent? Here is my code in main.c: I've not included all the other bits about clocks and gpios. Please let me know if you'd like to see those as well and I'll attach them here.
uint16_t tx_temp = 0xABCD;
__HAL_SPI_ENABLE(&hspi1);
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_SPI_Transmit(&hspi1, &tx_temp, sizeof(tx_temp), HAL_MAX_DELAY);
HAL_Delay(10);
}
/* USER CODE END 3 */�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
This is how the SPI is configured:
SPI_HandleTypeDef hspi1;
/* SPI1 init function */
void MX_SPI1_Init(void)
{
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_1LINE;
hspi1.Init.DataSize = SPI_DATASIZE_16BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 10;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
This is what I see on the scope:
#16-bit-spi #spi-communication #spi-master-mode #hal-spi