Your part is very similar to the LIS302, so Simon's library should make a good reference.
A few hints:
Replace the register definitions and constants in lines 26 - 55 of the LIS302 library with their equivalents for the MMA7455L (see page 21 of the data sheet). For example,
// Start with register address definitions
#define MMA7455_XOUTL 0x00
#define MMA7455_XOUTH 0x01
#define MMA7455_YOUTL 0x02
...
#define MMA7455_TW 0x1E
// Then add bit definitions as needed
#define MMA7455_READ 0x00 // RD bit flag for serial commands
#define MMA7455_WRITE 0x80 // WR bit flag for serial commands
#define MMA7455_I2CAD_I2CDIS 0x80 // Mode bit "I2CDIS" is D7. Located in register "I2CAD"
#define MMA7455_MCTL_MEASURE 0x01 // Measurement mode = 01. Located in register "MCTL"
...
Now you are ready to put in general purpose routines to read or write to the MMA7455. These routines will then be called by higher level logic in your driver.
Be sure you have set up the spi port for proper pin assignment, speed, mode, etc. Then you will need something like this:
SPI spi(p5, p6, p7); // mosi, miso, sclk
DigitalOut ncs(p8);
void devicewrite(char targetregister, char command) {
ncs = 0;
spi.write(MMA7455_WRITE | targetregister);
spi.write(command);
ncs = 1;
}
unsigned char deviceread (char targetregister) {
unsigned char result;
ncs = 0;
spi.write(MMA7455_READ | targetregister);
result = spi.write(0x00);
ncs = 1;
return(result);
}
Then you need to initialize the part. Looking over the spec quickly, it seems that the I2C port needs to be disabled, and the operational mode selected. So your init code should include:
devicewrite(MMA7455_I2CAD, MMA7455_I2CAD_I2CDIS); // Disable I2C access
devicewrite(MMA7455_MCTL, MMA7455_MCTL_MEASURE); // Set mode to "Measurement"
You will need to convert the "C" code examples above into the proper form for a C++ driver. The LIS302 driver should be an excellent guide for this, and for implementing the rest of the methods.
Good luck.
Hello,
I have buy an accelerometer their communicate with SPI.
I need some explication for the SPI with mbed.
How communicate with the $16 register for exemple ?
just :
<<code>>mySpi.write(0x16);<</code>>
For exemple if i want modifie the range of my accelerometer ( see the picture ).
How i do ??
Thanks & sorry for my english so bad !