niekiran / MasteringMCU

Udemy Mastering Microcontroller Course Repository
392 stars 374 forks source link

Passing SPI handle to to SPI interrupt #7

Open aman4512 opened 4 years ago

aman4512 commented 4 years ago

I don't understand how the SPI handle is passed to the SPI interrupt. Relevant lines in code file: stm32f407xx_spi_driver.c

void SPI_IRQHandling(SPI_Handle_t *pHandle)
{

    uint8_t temp1 , temp2;
    //first lets check for TXE
    temp1 = pHandle->pSPIx->SR & ( 1 << SPI_SR_TXE);
    temp2 = pHandle->pSPIx->CR2 & ( 1 << SPI_CR2_TXEIE);

    if( temp1 && temp2)
    {
        //handle TXE
        spi_txe_interrupt_handle(pHandle);
    }

    // check for RXNE
    temp1 = pHandle->pSPIx->SR & ( 1 << SPI_SR_RXNE);
    temp2 = pHandle->pSPIx->CR2 & ( 1 << SPI_CR2_RXNEIE);

    if( temp1 && temp2)
    {
        //handle RXNE
        spi_rxne_interrupt_handle(pHandle);
    }

    // check for ovr flag
    temp1 = pHandle->pSPIx->SR & ( 1 << SPI_SR_OVR);
    temp2 = pHandle->pSPIx->CR2 & ( 1 << SPI_CR2_ERRIE);

    if( temp1 && temp2)
    {
        //handle ovr error
        spi_ovr_err_interrupt_handle(pHandle);
    }

}

I'm architecting a similar application and need to pass SPI information from various applications. I'm using a different controller (dsPIC33). I do not understand how the different SPI handles declared in my application is passed to the interrupt context.

Abhiyadav0 commented 2 years ago

Recheck and debug your code

RohitAthithya commented 1 year ago

Usually such handles are declared global variable => thus scope of these vars. are for entire program! So as control goes to ISR, we still retain the updated info! - ISR is a function too, in the main file!