LSM303D 3D on SPI protocol wiring help

I just got this sensor and i want to use this sensor on SPI.
I see there are 4 pins i should connect, i have arduino mega 2560.
I connect SCA on arduino board for SDA(20)
SCL on arduino board for SDL(21)
I remain 2 more pins SDO and CS , where i should connect those pins ?
DO i also need another library for that?

thank you.


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.