for readability you should give B00000100 and others a meaningful name
The while (~p & B00000100) // as long as Pin PD2 is LOW (SS LOW) can keep on going creating a very long interrupt until the sender site sets SS HIGH.
if the system would get an interrupt for every bit you do not need that while loop at all (would be much better.