Page 1 of 1

SPI Accelerometer

Posted: Thu Oct 23, 2008 10:25 am
by Alex@Honda
I am looking at interfacing a digital three axis accelerometer to a PIC, is there any chance of generating a custom component for this application?

The device i am looking at using is:

3 axis LIS3LV02DQ accelerometer from ST Micro

Any help people can give is greatly appreciated.

Alex

Re: SPI Accelerometer

Posted: Thu Oct 23, 2008 11:50 am
by Steve
You can use the "Custom" component to generate the necessary C functions to interface with the device.

Re: SPI Accelerometer

Posted: Thu Oct 23, 2008 12:39 pm
by Alex@Honda
Yeah i'm aware of the ability to do it that way but as a mechanical designer i'm not confident that i'd be able to do it and make it work, or not within some reasonable time frame anyway.

I know it is cheeky but I was hoping someone had done something similar or would be prepared to offer me help with setting it up as a new component.

Re: SPI Accelerometer

Posted: Thu Oct 23, 2008 2:40 pm
by Steve
That device is an SPI device, so you could use the SPI component in Flowcode to make your job easier.

Re: SPI Accelerometer

Posted: Thu Oct 23, 2008 3:04 pm
by Benj
Hello Alex

I am looking at using one of these modules (or a very similar module) in one of my current projects. I will keep you informed as to my progress as I will probably make a custom code file to drive the device. Currently I am having problems simply getting the devices onto a circuit board so I can talk to them. As soon as I get this sorted I will begin on the drivers. I've just spotted a converter board that farnell sells with the sensor so maybe this could be an option to get the device soldered into place.

Re: SPI Accelerometer

Posted: Fri Oct 24, 2008 7:47 am
by Alex@Honda
There are loads of people selling these accelerometers pre assembled onto a breakout boards, let me know if you need further details and i'll sort you out a few links and datasheets.

Re: SPI Accelerometer

Posted: Mon Oct 27, 2008 11:59 am
by Benj
Hi Alex

Ok I spent a bit of time on the accelerometer component over the weekend and its now almost ready to go. Im going to test it out tonight and if it works ok then Ill release it tomorrow. It should allow you to use either the 4-wire SPI bus via the hardware SPI bus or the I2C bus via the hardware or bitbanged I2C bus depending on the way its configured. The component will also allow for interrupt driven acquisition as well as normal polling methods. Ive managed to get hold of a LIS3LV02DQ and also managed to solder it into a circuit correctly (fingers crossed) so testing should go ok as long as my code is correct. :P

Re: SPI Accelerometer

Posted: Wed Nov 05, 2008 10:41 am
by Benj
Hello Alex

Ok Im having problems with getting my hardware up and running but I think that this is just down to my CNC circuit boards not quite being accurate enough for the SMT devices. I will pass you the driver that has been done so far. It is untested for the most part but it compiles and the code looks correct. Please will you give it a go and see how it behaives. I have now ordered some custom adapter boards so I should be able to confirm the code works as it should shortly.

Near the top of the code file you will see the following section of code.

Code: Select all

//ACCELEROMETER COMPONENT DEFINES
#define MX_ACCEL_BUS	0//%a			//0=SPI, 1=I2C
#define MX_DATA_RATE	3//%b			//0=40hz, 1=160hz, 2=640hz, 3=2560hz
#define MX_SCALE		1//%c			//0=+/-2G, 1=+/-6G
#define MX_ADDRESS		0x3A//%d		//Default address 0x3A

#define MX_INT_PIN		0//%e
#define MX_INT_TRIS		trisc//
#define MX_INT_PORT		portc//%f

#ifdef AMX_ACCEL_BUS == 0				//SPI COMPONENT DEFINES

	#define MX_EN_PIN 		1//%g
	#define MX_EN_TRIS		trisc//
	#define MX_EN_PORT		portc//%h

#else									//I2C COMPONENT DEFINES

	#define MX_HARDWARE  	1//%i		//0=Sw, 1=Hw
	#define MX_MI2C_BAUD 	60//%j		//400khz

	#ifdef MX_HARDWARE == 0

		#define MX_PORT		portd//%k
		#define MX_TRIS 	trisd//%l
		#define MX_SCL  	3//%m
		#define MX_SDA  	4//%n

	#endif

#endif
Change the definitions to suit your connection bus. If you have any queries about any of the options then let me know and I will let you know what that particular define does in the code.

To install the component simply copy the code file into your Flowcode V3/Component directory and use the custom component from within Flowcode.