cancel
Showing results for 
Search instead for 
Did you mean: 

[solved]HAL_SPI_TransmitReceive not workin

aaslan
Associate II
Posted on July 09, 2015 at 11:40

device stm32f0discovery stm32f051r8t6

even if I get SPI2->DR = 0x9C which is correct.I even look with saleae logic analyzer.HAL_SPI_TransmitReceive function does not write to rx variable I created.

Thanks for any help
3 REPLIES 3
aaslan
Associate II
Posted on July 09, 2015 at 11:43

http://3.bp.blogspot.com/-0ldzZ3RhGYQ/VZ5B3R8xIRI/AAAAAAAAABA/5HDXvRTDjlY/s1600/fail.png

debug photo link uploaded with google blogger

/* Transmit and Receive data in 8 Bit mode */
else
{ 
while((hspi->TxXferCount > 0) || (hspi->RxXferCount > 0))
{
/* check TXE flag */
if((hspi->TxXferCount > 0) && ((hspi->Instance->SR & SPI_FLAG_TXE) == SPI_FLAG_TXE))
{
if(hspi->TxXferCount > 1)
{
hspi->Instance->DR = *((uint16_t*)hspi->pTxBuffPtr);
hspi->pTxBuffPtr += sizeof(uint16_t);
hspi->TxXferCount -= 2;
} 
else
{
*(__IO uint8_t *)&hspi->Instance->DR = (*hspi->pTxBuffPtr++);
hspi->TxXferCount--;
}
/* Enable CRC Transmission */
if((hspi->TxXferCount == 0) && (hspi->Init.CRCCalculation == SPI_CRCCALCULATION_ENABLED))
{
hspi->Instance->CR1 |= SPI_CR1_CRCNEXT;
}
}
/* Wait until RXNE flag is reset */
if((hspi->RxXferCount > 0) && ((hspi->Instance->SR & SPI_FLAG_RXNE) == SPI_FLAG_RXNE))
{
if(hspi->RxXferCount > 1)
{
*((uint16_t*)hspi->pRxBuffPtr) = hspi->Instance->DR;
hspi->pRxBuffPtr += sizeof(uint16_t);
hspi->RxXferCount -= 2;
if(hspi->RxXferCount <= 1)
{
/* set fiforxthresold before to switch on 8 bit data size */
SET_BIT(hspi->Instance->CR2, SPI_RXFIFO_THRESHOLD);
}
}
else
{
/*when I put a breakpoint here got good result dont get it*/
(*hspi->pRxBuffPtr++) = *(__IO uint8_t *)&hspi->Instance->DR;
hspi->RxXferCount--;
}
}
if((Timeout != HAL_MAX_DELAY) && ((HAL_GetTick()-tickstart) >= Timeout))
{
errorcode = HAL_TIMEOUT;
goto error;
}
}
}

aaslan
Associate II
Posted on September 02, 2015 at 08:08

I did nothing.update of hal library 1.3.0 for stm32f0 solved my problem.

Nesrine M_O
Lead II
Posted on September 02, 2015 at 10:49

Hi,

Thank you for posting your findings and how you fixed the issue, it is good to hear that it was solved. 

-Syrine-