2018-06-30 08:32 AM
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-spi2018-06-30 01:34 PM
Try changing:
sizeof(tx_temp)
...to '1'.
2018-06-30 01:34 PM
Suggests that HAL_SPI_Transmit takes a count of units to transmit, not bytes, right
HAL_SPI_Transmit(&hspi1, &tx_temp, sizeof(tx_temp)/sizeof(uint16_t), HAL_MAX_DELAY);
2018-07-01 03:14 AM
Thank you. That worked!
:)
2018-07-01 03:15 AM
Thank you for that clarification. I wasn't aware of that.