help with learning SPI

Can someone offer a good walkthrough with writing code for an SPI protocol? I plan on connecting a sensor to my Arduino mega. The data sheet provides some timing diagrams for read and write, as expected, but I just don’t understand how to read them and translate into code.

Give the details of EXACTLY what sensor you are using. Ideally with a link to the datasheet.

http://www.gammon.com.au/forum/?id=10892

KenF: Give the details of EXACTLY what sensor you are using. Ideally with a link to the datasheet.

Oh crap I completely forgot. Here is the link to the data sheet. It is the LSM303C magnetometer. I have an I2C code but I need to use SPI since I plan on connecting a second LSM303C sensor and I know SPI would make it much easier. My problem is looking at the timing diagram and understanding how that relates to creating a read and write functions in my code.

http://www.st.com/web/en/resource/technical/document/datasheet/DM00089896.pdf