2021-08-03 12:56 AM
I used STM32Cube IDE ST Examples to try SPI Polling communication. I followed SPI_FullDuplex_ComPolling reading file instructions. After I pressed reset buttons of 2 boards, I pressed master board user button. The result is according to readme file is " LED5 turns ON when there is an error in transmission/reception process". What can I do?
2021-08-03 01:11 AM
Logical next steps:
2021-08-03 01:12 AM
Thank you Sebastian I will try.
2021-08-03 01:46 AM
I have checked on debugging but meaningless datas are appeared on slave side aRxBuffer( switch(HAL_SPI_TransmitReceive(&SpiHandle, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE, 5000)) ). I did not check master side but both of the boards same leds are on.
Why meaningless datas are received? How can I fix it?
2021-08-03 01:56 AM
is there any data at all (does the rxBuffer on slave side get filled up, does the data change from a default 0x0 or 0xaa content)? Does the function return an error or HAL_OK?
If it returns HAL_OK on the slave side, you may assume that clock signal is OK and CS as well (if that's even checked at all). But maybe the MOSI or MISO is floating?
2021-08-03 02:24 AM
switch(HAL_SPI_TransmitReceive(&SpiHandle, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE, 5000))
{
case HAL_OK:
/* Communication is completed ____________________________________________*/
/* Compare the sent and received buffers */
if(Buffercmp((uint8_t*)aTxBuffer, (uint8_t*)aRxBuffer, BUFFERSIZE))
{
/* Transfer error in transmission process */
Error_Handler();
}
/* Turn LED4 on: Transfer in transmission process is correct */
BSP_LED_On(LED4);
/* Turn LED6 on: Transfer in reception process is correct */
BSP_LED_On(LED6);
break;
case HAL_TIMEOUT:
/* A Timeout occurred_____________________________________________________*/
/* Call Timeout Handler */
Timeout_Error_Handler();
break;
/* An Error occurred______________________________________________________*/
case HAL_ERROR:
/* Call Timeout Handler */
Error_Handler();
break;
default:
break;
}
I inserted breakpoints inside the cases of switch but code did not jump inside the cases. The code directly jump to the Error_Handler() function.
static void Error_Handler(void)
{
/* Turn LED5 on */
BSP_LED_On(LED5);
while(1)
{
}
}
So I could not get HAL condition
2021-08-03 03:05 AM
You could change the code to
HAL_StatusTypeDef ret = HAL_SPI_TransmitReceive(&SpiHandle, (uint8_t*)aTxBuffer, (uint8_t *)aRxBuffer, BUFFERSIZE, 5000);
switch(ret) {...
but anyway, if Error_Handler is called, it means HAL_ERROR.
I think there is a lot to investigate from your side first (scope the signals, verify connection, verify that master is effectively in master mode and slave in slave mode, ...).
2021-08-03 06:09 AM
Thank you for your suggestion. I defined "ret" variable as global. "ret" varible was assigned as HAL_OK from MCU. I think datas are broken because there is a function "Buffercmp" in the HAL_OK case of switch(ret). Also, I have checked the datas on logic analyzer. MOSI line datas are correct but MISO line datas are meaningless. According to the logic analyzer datas, master to slave datas are correct but slave cannot process datas properly. It is interesting.
I also gave "Buffercmp" function.
static uint16_t Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength)
{
while (BufferLength--)
{
if((*pBuffer1) != *pBuffer2)
{
return BufferLength;
}
pBuffer1++;
pBuffer2++;
}
return 0;
}