2017-09-07 06:40 AM
Below is the SPI register configuration:
CR1 Register
Register Bit parameter
Config value
Description
BIDIMODE
0
2-line unidirectional data mode
BIDIOE
0
Receive-only mode
CRCEN
0
CRC calculation disabled
CRCNEXT
0
Next transmit value is from TX buffer
CRCL
0
8-bit CRC length
RXONLY
1
Output disabled (Receive-only mode)
SSM
1
Software slave management enabled
SSI
0
LSBFIRST
0
data is received with the MSB first
SPE
1
Peripheral enabled
BR[2:0]
0
fPCLK/2
MSTR
0
Slave mode
CPOL
1
CK to 1 when idle
CPHA
1
The second clock transition is the first data capture edge
CR2 Register
Register Bit parameter
Config value
Description
DS [3:0]:
0x07
8 - bits data length for SPI transfers
Are we missing any configurations ? Could you please guide us to resolve this issue ?
Below is the SPI & GPIO initialization code:
[NOTE : The function HAL_SPI_MspInit() is getting invoked inside the HAL_SPI_Init() ]
SPI_HandleTypeDef stSpiHandle = { 0 }; // SPI handler declaration
void SPIInit( void )
{ /* Set the SPI parameters */ stSpiHandle.Instance = SPI1;stSpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
stSpiHandle.Init.Direction = SPI_DIRECTION_2LINES_RXONLY; stSpiHandle.Init.CLKPhase = SPI_PHASE_2EDGE; stSpiHandle.Init.CLKPolarity = SPI_POLARITY_HIGH; stSpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; stSpiHandle.Init.DataSize = SPI_DATASIZE_8BIT; stSpiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB; stSpiHandle.Init.NSS = SPI_NSS_SOFT; stSpiHandle.Init.NSSPMode = SPI_NSS_PULSE_DISABLE; stSpiHandle.Init.TIMode = SPI_TIMODE_DISABLE; stSpiHandle.Init.Mode = SPI_MODE_SLAVE;if ( HAL_SPI_Init( &stSpiHandle ) != HAL_OK )
{ SET_FAULT_STATUS( FAULT_SPI_CONFIG_FAILED ); }}void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)
{ GPIO_InitTypeDef GPIO_InitStruct;if(hspi->Instance == SPI1)
{ /* Enable peripherals and GPIO Clocks */ SPI1_SCK_GPIO_CLK_ENABLE(); SPI1_MOSI_GPIO_CLK_ENABLE(); SPI1_CLK_ENABLE();/* SPI SCK GPIO pin configuration */
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Pin = SPI1_SCK_PIN; GPIO_InitStruct.Alternate = SPI1_SCK_AF; HAL_GPIO_Init(SPI1_SCK_GPIO_PORT, &GPIO_InitStruct);/* SPI MOSI GPIO pin configuration */
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Pin = SPI1_MOSI_PIN; GPIO_InitStruct.Alternate = SPI1_MOSI_AF; HAL_GPIO_Init(SPI1_MOSI_GPIO_PORT, &GPIO_InitStruct); }}Thanks & Regards,
Kishor
#stm32f030-spi-clock #stm32f0-spi #spi2017-09-07 07:29 AM
Hello!
I suppose , when you say '
Data is being sampled' you mean that the previously cleared RXNE flag is set.
Is the SCK pin grounded or floated?
If floated it could intercept 50/60 HZ from mains.
regards.
vf
2017-09-08 12:00 AM
And what happens if you don't set the RXONLY bit?
It shouldn't matter, as long as you don't assign any pin to Tx (MISO ).
JW
2017-09-08 01:13 AM
Hello Thanks for your reply.
The SCK pin is pulled HIGH (Its not floated).
I have observed that RXNE flag is getting set right after SPI GPIO initialization and it is always set.
I am using 'HAL_SPI_Init()' for SPI initialization.
Regards,
Kishor
2017-09-08 01:24 AM
Below is the SPI register configuration:
Are these values read out from the running chip after SPI initialization?
JW
2017-09-08 01:42 AM
Yes, these values were read out (at Keil->System Viewer->SPI->SPI1 )
from the running chip right after SPI initialization.
2017-09-08 02:26 AM
Yes, I tried doing that also (
RXONLY bit is not set ). I got the same result.
2017-09-08 02:35 AM
Hello!
In errata sheet there is not such an issue.
It would help to post the initialization code of SPI and GPIO.
2017-09-08 03:39 AM
I have updated the
SPI and GPIO initialization code in the main question.
2017-09-08 08:10 AM
Hello!
You wrote that RXNE is set after initialization. In your posted CR1 Reg. SPE bit is enabled.
During initialization SPE bit is normaly not enabled by HAL_SPI_Init() . So some other code enables the SPE after initialization. Check if this code is doing also something else relevant with issue.
Also check If macros SPI1_MOSI_AF, SPI1_SCK_AF lead both to AF0 (0x00) and if the SPI1_SCK_GPIO_CLK_ENABLE(), SPI1_MOSI_GPIO_CLK_ENABLE() enable both the same GPIOA clock. (pins PA7 and PA9) .
At your project->options ->C/C++ the STM32F030x6 must be defined (x4 and x6 uses the same headers)