Hardware details :Atmega128, 8MHz, 3.3v operation)
I am using spi to interface memory.
I am using spi interrupt with following settings.
I am using portb.4 as chip select for my memory.
My problem is
1) When I am loading the data in SPDR resistor the interrupt is invoked only if there is delay of 4 microsecond or more.
2) If delay is removed then program doesn't invoke the interrupt for next SPDR loading.
3) I have checked SPSR, if delay is not provided, wcol bit( SPSR.6) is set. Why?
4) I tried to clear it by setting it and reading spsr & spdr.How to clear it?
4)I don't want to include this delay. How to solve it ?
5) After sending a command(0x9f is command) to memory, I need to receive bytes from memory. But I am always getting 1st byte as 0 & actual byte is received in next cycle. Why?
pls see the following code.
PORTB=0xef; // portb.4=0 asserting chip select
SPDR = 0x9f; //send read id command to memory
delay_us(4); // want to remove it
SPDR=0; // to receive 1st data byte
byt=spi_data; // 1st byte received
PORTB.4=1; // de-assert chip select
// following is interrupt routine
interrupt [SPI_STC] void spi_isr(void)
spi_data=SPDR; // store received byte from memory
cnt++; // to check intr invoked or not
please help me