Facing the problem of data hang in arduino SPI communication.

I want to transfer the data from Arduino to the FPGA by considering arduino as slave and FPGA as master .Initially the operation is perfect, but at times implementation is not proper from the slave spi ,the data is not being transferred from slave spi. I am unable to debug where the issue is present in arduino spi slave code.I am attaching my slave code .Please help me out.

Thanks in advance

slavecode.c (994 Bytes)

As it seems you don't use a UNO you should mention what type of Arduino you're using (I guess a Mega2560)!

That code doesn't implement an SPI slave but is a mix of slave and master code. Although it might work in some strange way, it will never be a reliable slave. Does it make sense in your setup to return a fixed set of values?

You should use the SPI interrupt to handle the SPDR register. Make sure to optimize the IRQ handler for performance.

I would suggest getting the Arduino cookbook and reading it. Also on line there are many videos etc showing the Arduino and how to do what you want. Also check your grounds, if they are not all connected what you will send or get is sometimes maybe.

pylon:
As it seems you don't use a UNO you should mention what type of Arduino you're using (I guess a Mega2560)!

That code doesn't implement an SPI slave but is a mix of slave and master code. Although it might work in some strange way, it will never be a reliable slave. Does it make sense in your setup to return a fixed set of values?

You should use the SPI interrupt to handle the SPDR register. Make sure to optimize the IRQ handler for performance.

I'm using Arduino Mega 2560. Could you please point out where code seems to be master-like and guide us in implementing SPI interrupts.

Thanks in advance,
suryakiran

Could you please point out where code seems to be master-like and guide us in implementing SPI interrupts.

Nick Gammon has some good explanations and example sketches for that.