Search code examples
cstm32spihalradio-transmission

Chip Enable not setting at right moment using SPI


Am trying to set a Chip Enable (CE) of a pin to go high before a SPI transfer and go back low upon accomplishing of the transfer (either TX or RX). Am using the NRF24L01 and Nucleo-F303. It is said that when the CE is high, thats when i can do a real SPI transfer to the NRF24L01. However, the CE pin goes momentarily low and then high again even before the real transfer hasnt been accomplished

enter image description here

The rest of the pins seem to be synching accordingly. How do i get the CE pin to exactly go high prior to making a SPI transfer and then Low when am done or not doing any more transfers.

Here is how i've attempted to solve the problem

int main(void)
{
    HAL_Init();
    SystemClock_Config();
    MX_GPIO_Init();
    MX_SPI1_Init();
    MX_USART1_UART_Init();

    HAL_Delay(5);

    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3, GPIO_PIN_RESET);
    uint8_t data[6] = {0x5C, 0xBA, 0xBB, 0x4D, 0x5E, 0xFB,};
    uint8_t data1[6] = {0};

    while (1)
    {
        HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3, GPIO_PIN_SET);

        if(HAL_SPI_TransmitReceive(&hspi1, data, data1, 6, HAL_MAX_DELAY) == HAL_OK)
        {
            HAL_Delay(1);
            HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3, GPIO_PIN_RESET);
        }
    }
}

and this is how i have configured GPIO_PIN_3 to function

    GPIO_InitStruct.Pin = GPIO_PIN_3;
    GPIO_InitStruct.Pull = GPIO_PULLDOWN;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; // digital Output
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

Solution

  • I ended up going bare-metal because the libraries were giving a lot of delay and had so many abstract layers