Snippet - LIS302DL Accelerometer Driver

LIS302DL Accelerometer Driver

This is an SPI driver for the LIS302DL Accelerometer (as found on the STM discovery board). I built this based on Architect’s FezMonoOled example and it hopefully provides another example template that can be used for less complicated drivers.

The driver supports multiple constructors that allow you to specify most configuration parameters without having to dig into the code. It also supports a debug constant that can be used to provide feedback.
The example shows the usage (its pretty easy). This version doesn’t support programing the accelerometer to trigger an interupt, it simply allows you to obtain the X,Y,Z values.

I’m just getting started in .NETMF (and C# in general) so feedback is welcome.

Instructions on how to use this on the STM32F4 discovery using the Cerberus firmware are provided in the example code.

Thanks for sharing that code.

I am using the STM32F4Discovery with the firmware from That means I can use PE3 which corresponds to

(Cpu.Pin)(4 * 16 + 3)

for Chip Select.

Hint: If you cast the byte to sbyte, like

return (sbyte)ReadRegister(OUT_X_ADDR);

you even get the sign right.