0
\$\begingroup\$

I want to get some data from spi, but spi interrupt doesnt work. I get a message and a pause in proteus instead of a signal on LCD. How to fix this? My code:

void spi_init(){
    DDRB = (1<<PINB4); 
    SPCR |= (1<<SPIE) | (1<<SPE);
}

ISR(SPI_STC_vect)//
{
    str_lcd("            ");
    setpos(0,0);
    str_lcd("SPI"); //signal
    setpos(0,0);
}

int main(void)
{
    spi_init();
    sei();
    while(1){}
}

enter image description here

Spi debugger

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

The data is not read out from SPI data register at all, so next transferred byte will overrun the first one. Also same thing happens if the LCD write is slow. In general, don't do slow things in an interrupt, only fast things you must do.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.