cancel
Showing results for 
Search instead for 
Did you mean: 

I could not convert the HAL_SPI_TransmitReceive function to LL

YBAYR.1
Associate III

I AM TRYING TO CONTROL WITH CLRC SPI. MY PROJECT IS WRITTEN WITH LL. I CANNOT ADAPTE THIS FUNCTION. CAN YOU PLEASE HELP ME?

 

https://github.com/CodElecCz/STM32F1-CLRC663

11 REPLIES 11
YBAYR.1
Associate III

These are the codes I tried to use to replace HAL_SPI_TransmitReceive with LL-based code, but they are not working. How can I explain this more clearly? I can receive data from my CLRC663 module using full-duplex communication with HAL, but I cannot receive anything with the LL version.

 

uint8_t SPI2_ByteSend (uint8_t val)
{
	LL_SPI_TransmitData8(SPI2, val);
	while (LL_SPI_IsActiveFlag_BSY(SPI2));
	return(LL_SPI_ReceiveData8(SPI2));
}

 

void mfrc630_SPI_transfer(const uint8_t* tx, uint8_t* rx, uint16_t len)
{
	
	
    LL_GPIO_ResetOutputPin(SPI2_NSS_GPIO_Port, SPI2_NSS_Pin); // Slave Select aktif

    for (uint16_t i = 0; i < len; i++) {
        if (rx != NULL) {
            rx[i] = SPI2_ByteSend(tx[i]);
        } else {
            (void)SPI2_ByteSend(tx[i]); // RX kullanilmiyorsa sadece gönder
        }
    }

    LL_GPIO_SetOutputPin(SPI2_NSS_GPIO_Port, SPI2_NSS_Pin); // Slave Select deaktif
}

 

I WANT TO RUN THIS LIBRARY:

https://github.com/CodElecCz/STM32F1-CLRC663


 

YBAYR.1
Associate III

I found an example related to STM32L4, and I think the issue is related to DMA. After the first bit is sent, the slave responds immediately, but the processor misses it. This needs to be handled with DMA to avoid the issue. However, I couldn't find a suitable LL-based example. I need to rewrite the HAL_SPI_TransmitReceive function using LL, whether with DMA or another method—but it must do exactly the same job without missing anything.

HAL_SPI_TransmitReceive(&hspi2, tx, rx, len, 1000)