You are on page 1of 2

InitAccelerometerService:

Call InitAccSSI
Call ConfigAccHW
Initialize accelerometer update timer
Move state into Measuring

RunAccelerometerService:
Switch on current state:
Measuring:
If the event is ES_TIMEOUT from update timer
Call SPISend
Calculate the angle from the X/Y accelerations
Compute a blanket offset for problem regions
Restart the update timer
End if

QueryAngle:
Returns the angle

Acc_ISR: (ISR)
Disable the local interrupt
Run through the data registers stored in query to read data
Store accelerations into 16-bit integers
Clip the accelerations to avoid rollover
Correct with a fixed offset
Subtract oldest data point from sum
Add in newest data point to sum
Replace the old data point with new data point in array
Increment pointer in our array
Calculate array size for the first NUM_DATA iterations
Compute the average (sum over size of array)
At the end of the array, set pointer back to first element

InitAccSSI:
Enable the clock to GPIO port D
Enable the clock to SSI module 1
Wait for GPIO port D to be ready
Program GPIO to use alternate functions to SSI pins
Set mux position in GPIOCTL to select SSI use of pints
Program port lines for digital I/O
Program SCK, SS, and MOSI for output, MISO for input
Program pull-up on the clock line
Wait for SSI1 to be ready
Make sure we disable the SSI
Select master mode and EOT interrupt
Configure SSI clock source to system clock
Configure clock pre-scalar
Configure clock rate, phase and polarity, mode, and data size
Locally enable interrupts
Enable SSI for operation
Enable the NVIC interrupt
Lower the priority of this interrupt
Enable global interrupts

ConfigAccHW:
Configure the accelerometer in measurement mode
Make sure local interrupts are enabled

SPISend:
Read the first DATAX0 address
Pulse the clock for every subsequent register to fill the queue
Make sure local interrupts are enabled

You might also like