Just to check: you are using our LSM303D carrier with voltage regulator, right? You mentioned you wanted to use SPI, but the SDA(20) and SCL(21) connections you have made to your Mega are for I2C. For SPI, you should connect “SDA” (aka SDI) to MOSI (51), “SCL” (aka SPC) to SCK (52), SDO to MISO (50), and CS to a pin of your choice that you want to use for slave select. GND on both boards should also be connected together. You can learn more about why those connections are the appropriate ones for SPI by reading the pin descriptions in our pin assignment table under the “Pinout” section of the LSM303D’s product page. The third paragraph of the “Connections” section also describes how to interface with the board over SPI . You can also refer to the LSM303D’s datasheet, which you can find under the “Resources” tab of its product page.
We do not have a library that uses SPI to communicate with the LSM303D, so you would have to write your own code to do that. (You can find the GitHub page for our I2C library here.) Is there a reason I2C won’t work for your application?
By the way, if you do want to use I2C, you can keep your current SDA(20) and SCL(21) connections. Don’t forget to connect GND, too.