2014-10-15 03:03 AM
Hi All,
I'm trying to set-up a simple SPI communication between a STM32L0 Nucleo board and a slave device.I made the SPI and PINs configuration using the CubeMX tool and seems to work pretty well but the SPI has some problem:I'm trying to read a register that contains the value 0x21. I can see on my logic analyzer that the byte running on the bus contains the correct value, but the HAL_SPI_Receive function returns 0x20 as received value (as you can see in the attached image).I've tryed to manually check the SPI initialization but it seems correct...Here is the Cube-MX initialization:SPI_HandleTypeDef hspi2;/* SPI2 init function */void MX_SPI2_Init(void){ hspi2.Instance = SPI2; hspi2.Init.Mode = SPI_MODE_MASTER; hspi2.Init.Direction = SPI_DIRECTION_2LINES; hspi2.Init.DataSize = SPI_DATASIZE_8BIT; hspi2.Init.NSS = SPI_NSS_SOFT; hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; hspi2.Init.TIMode = SPI_TIMODE_DISABLED; hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED; hspi2.Init.CRCPolynomial = 7; hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB; HAL_SPI_Init(&hspi2);}void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi){ GPIO_InitTypeDef GPIO_InitStruct; if(hspi->Instance==SPI2) { /* Peripheral clock enable */ __SPI2_CLK_ENABLE(); /**SPI2 GPIO Configuration PB13 ------> SPI2_SCK PB14 ------> SPI2_MISO PB15 ------> SPI2_MOSI */ GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_LOW; GPIO_InitStruct.Alternate = GPIO_AF0_SPI2; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); }}The reading function I'm using is HAL_SPI_Transmit(&hspi2, dataBuffer, dataLength, 1000); where dataBuffer is a uint8_t array and dataLength is set to 1.The NSS is manually handled and it works correctly (checked with the oscilloscope).Any ideas?Thank you!Mat #stm32cube-stm32l0xx #stm32l02014-10-15 06:02 AM
Could this be the same problem as in
https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32F4%20SPI%20Communication%20-%20Last%20MISO%20Bit%20not%20received¤tviews=7 and https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fcortex%5fmx%5fstm32%2fSTM32%20SPI%20Spoiled%20Bits&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&TopicsView=https%3A%2F%2Fmy... ? Please post the content of all SPI registers. JW2014-10-16 06:28 AM
Thanks waclawek.jan for your answer!
I think I foud the problem... it seems like that the pin speed was the cause of the problem.Setting the speed to GPIO_SPEED_HIGH instead of the default GPIO_SPEED_LOW the problem seems to be disappeard.Thank you for your time!Mat