How to configure SPI1 in Nucleo L476RG in SPI_DATASIZE_8BIT mode
- July 30, 2018
- 3 replies
- 1579 views
Hello,
please can I ask how to configure SPI1 in Nucleo L476RG? I have configured SPI interface using CubeMX and then I have checked the functionality using osciloscope. When I want to send 1 byte (8 bits) CLK signal generated has 16 pulses instead of 8 pulses. My configuration of SPI is:
static void MX_SPI1_Init(void) {
/* SPI1 parameter configuration*/
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 7;
hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
if (HAL_SPI_Init(&hspi1) != HAL_OK) {
_Error_Handler(__FILE__, __LINE__);
}
}
I have checked also the registers in HAL_SPI_Init and everything seems fine. Basically when I choose some hspi1.Init.DataSize the number of CLK pulses is always doubled. It seems to me it could be some problem in HAL. Please can you help me how to configure SPI in a such way I would be able to use it for hspi1.Init.DataSize = SPI_DATASIZE_8BIT (it means 8 CLK pulses for each byte)? Attached is a screenshot from osciloscope and program.
David Krcmarik