SPI Half Duplex receive problem : No SCK
Dear all,
I'm trying to perform a simple blocking SPI communication with a slave (TFT driver) on my STM32F769NI-disco board.
I can transmit commands without any problem but I can't receive
Here is my init code called from main():
static void MX_SPI2_Init(void)
{
/* SPI2 parameter configuration*/
hspi2.Instance = SPI2;
hspi2.Init.Mode = SPI_MODE_MASTER;
hspi2.Init.Direction = SPI_DIRECTION_1LINE;
hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
hspi2.Init.CLKPolarity = SPI_POLARITY_HIGH;
hspi2.Init.CLKPhase = SPI_PHASE_2EDGE;
hspi2.Init.NSS = SPI_NSS_SOFT;
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32; // PCLK2/8 = 10MHz
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi2.Init.CRCPolynomial = 7;
hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi2.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
if (HAL_SPI_Init(&hspi2) != HAL_OK)
{
Error_Handler();
}
HAL_NVIC_SetPriority(SPI2_IRQn, 5, 1);
HAL_NVIC_EnableIRQ(SPI2_IRQn);
}HAL_SPI_Transmit just works fine. I do not put the code for it here.
Here is the code for my SPI read data :
eST7735S_STATUS ReadData (volatile uint8_t *u8Data, uint8_t u8Size)
{
volatile uint8_t u8test[4] = { }; // replace u8Data for test purpose for now
volatile uint8_t u8SPIerror=0;
volatile uint8_t u8State=0;
while(__HAL_SPI_GET_FLAG(&hspi2, SPI_FLAG_BSY) != RESET);
vTaskSuspendAll();
HAL_GPIO_WritePin(TFT_GPIO_PORT_DC, TFT_DC, LOW); /* Set DC pin to data mode */
u8SPIerror = HAL_SPI_Receive(&hspi2, (uint8_t*) u8test, (U16)1, (U32)500);
xTaskResumeAll();
if (u8SPIerror == HAL_OK)
return TFT_SUCCESS;
}Then I perform a transmit of 1 byte to send a command to the slave and then try to read its answer.
eST7735S_STATUS ReadRDID1 (volatile U8 u8ManufacturerID)
{
HAL_GPIO_WritePin(TFT_GPIO_PORT_CS, TFT_CS, LOW); /* Set CS pin low */
if (WriteCommand(ST7735_RDID1) != TFT_SUCCESS) return TFT_ERROR;
if (ReadData(u8ManufacturerID, 1) != TFT_SUCCESS) return TFT_ERROR;
HAL_GPIO_WritePin(TFT_GPIO_PORT_CS, TFT_CS, HIGH); /* Set CS pin high */
return TFT_SUCCESS;
}I transmit well my ST7735_RDID1 char on the SPI line and then call HAL_SPI_Receive but I've no clock on the SCK line which just goes low and the SPI_Receive routine goes to HAL_TIMEOUT.
By the way, if I set Direction to SPI_DIRECTION_2LINES instead of SPI_DIRECTION_1LINE
Then SCK is well sent (there is a dummy HAL_SPI_TransmitReceive in the HAL_SPI_Receive routine for the 2LINE mode) and my slave tries to answer but obviously this creates a short circuit with MOSI which isn't in three-state in that case.
What I'm doing wrong ??? How to get SCK toggling in half duplex ?
thanks
Stephane
