SPI communication and connection

Hi So I am narrowing down a problem I am having with an spi conection.
When a button is pressed the mega1284 tries to transmit some data using SPI communication. It never seems to finish. Within the code I can see that it an leave the do while based on two conditions:

		//stop if max_retries reached
		if((mirf_read_register(OBSERVE_TX) & 0b1111) == mirf_RETR)
			breaked = 1;
	while( !(mirf_get_status() & _BV(TX_DS)) );

I dont completely understand the if conditon that breaks the loop but the while condition I do.
If SPDR returns 1 here it will leave the loop:

uint8_t spi_writeread(uint8_t data)
    SPDR = data;
    while((SPSR & (1<<SPIF)) == 0);
    return SPDR;

I have checked it and it never is not 0.
My question is does this suggest a connection problem i.e hardware? I have checked my connections and everything is good as far as I can tell.
I am currently trying to understand the output of my scope…


What is the significance of the first snippet of code you posted? How does it relate to spi_writeread()? I don’t think you have given enough context for us to be able to tell what might be going wrong.

Did you write this code yourself? If not, where did you get it from? Are you running the code on an Orangutan SVP-1284?

- Kevin