AnsweredAssumed Answered

SPI_Transmit_AND_Receive_Interrupt_FLAG_At_Same_Time

Question asked by M N on Jan 27, 2017
Latest reply on May 16, 2017 by jsureshp@gmail.com

Hi.

I have problem by SPI that is :

When i want to send data for example in slave mode during receiving from master. data will corrupt ( if i just receive data and send to UART it works fine). I think it happens Because both TXE and RXNE occurs at same time and when MCU is in ISR data will rewrite in data register before transfer to Tx/Rx buffer  . How can i Handle this in continuous transmission ?  . it's my code :

-------------------------------------------------------------------------↓

//Slave Part

void SPI2_IRQHandler(void){ 

static char counter = 0x40;

            if ( SPI2->SR & SPI_SR_RXNE ) {   
                sendToUart(SPI2->DR);
            }
            if ( SPI2->SR & SPI_SR_TXE ) {               
                SPI2->DR = counter;
                counter++;
                if(counter >= 0x5B)counter=0x40;          
            }          

 }   

-------------------------------------------------------------------------↑

Outcomes