Hi,
I'm having trouble getting accelerometer data from the MMA7455 using I2C mode and I wonder if anyone could help me interpret the datasheet?
The datasheet says (to write a byte hence set up the device):
Quote:
To start a write command, the Master transmits a start condition (ST) to the MMA7455L, slave address ($1D) with the R/W bit set
to “0” for a write, the MMA7455L sends an acknowledgement. Then the Master (MCU) transmits the 8-bit address of the register
to write to, and the MMA7455L sends an acknowledgement. Then the Master (or MCU) transmits the 8-bit data to write to the
designated register and the MMA7455L sends an acknowledgement that it has received the data. Since this transmission is complete,
the Master transmits a stop condition (SP) to the data transfer. The data sent to the MMA7455L is now stored in the appropriate
register.
I have interpreted this as:
i2c.start();
a=i2c.write(0x1C);
a1=i2c.write(0x16); //This is a register address to send data to
a2=i2c.write(0x01); //This is the data to send (sets up device)
i2c.stop();
pc.printf("Acknowledgement: %d %d %d\n\r",a,a1,a2);
wait(2);
The acknowledgement bytes all read 0, which I believe means the device has acknowledged the data.
The problem occurs when I try to read the data, the datasheet says:
Quote:
The MMA7455L has an 10-bit ADC that can sample, convert and return sensor data on request. The transmission of an 8-bit
command begins on the falling edge of SCL. After the eight clock cycles are used to send the command, note that the data returned
is sent with the MSB first once the data is received. Figure 6 shows the timing diagram for the accelerometer 8-bit I2C
read operation. The Master (or MCU) transmits a start condition (ST) to the MMA7455L, slave address ($1D), with the R/W bit
set to “0” for a write, and the MMA7455L sends an acknowledgement. Then the Master (or MCU) transmits the 10-bit address of
the register to read and the MMA7455L sends an acknowledgement. The Master (or MCU) transmits a repeated start condition
(SR) and then addresses the MMA7455L ($1D) with the R/W bit set to “1” for a read from the previously selected register. The
Slave then acknowledges and transmits the data from the requested register. The Master does not acknowledge (NAK) it received
the transmitted data, but transmits a stop condition to end the data transfer.
I have interpreted this as:
i2c.start();
a=i2c.write(0x1C); //Write to address of device, write bit reset
a1=i2c.write(0x06); //Register to read from (acceleration in X)
a2=i2c.write(0x1D); //Device address with read bit set
c=i2c.read(0); //Read the data with NACK
i2c.stop();
Returns a,a1 and a2 all=0 (hence an acknowledgement), but 'c' returns 157 regardless of the motion of the device.
Any suggestions on if I am interpreting the datasheet correctly into code?
PS: I have also tried:
// i2c.write(addr, cmd, 1);
// i2c.read(addr, cmd, 1,1);
to no avail.
Regards,
Sam Wane
Hi, I'm having trouble getting accelerometer data from the MMA7455 using I2C mode and I wonder if anyone could help me interpret the datasheet? The datasheet says (to write a byte hence set up the device):
Quote:
To start a write command, the Master transmits a start condition (ST) to the MMA7455L, slave address ($1D) with the R/W bit set to “0” for a write, the MMA7455L sends an acknowledgement. Then the Master (MCU) transmits the 8-bit address of the register to write to, and the MMA7455L sends an acknowledgement. Then the Master (or MCU) transmits the 8-bit data to write to the designated register and the MMA7455L sends an acknowledgement that it has received the data. Since this transmission is complete, the Master transmits a stop condition (SP) to the data transfer. The data sent to the MMA7455L is now stored in the appropriate register.
I have interpreted this as:
The acknowledgement bytes all read 0, which I believe means the device has acknowledged the data.
The problem occurs when I try to read the data, the datasheet says:
Quote:
The MMA7455L has an 10-bit ADC that can sample, convert and return sensor data on request. The transmission of an 8-bit command begins on the falling edge of SCL. After the eight clock cycles are used to send the command, note that the data returned is sent with the MSB first once the data is received. Figure 6 shows the timing diagram for the accelerometer 8-bit I2C read operation. The Master (or MCU) transmits a start condition (ST) to the MMA7455L, slave address ($1D), with the R/W bit set to “0” for a write, and the MMA7455L sends an acknowledgement. Then the Master (or MCU) transmits the 10-bit address of the register to read and the MMA7455L sends an acknowledgement. The Master (or MCU) transmits a repeated start condition (SR) and then addresses the MMA7455L ($1D) with the R/W bit set to “1” for a read from the previously selected register. The Slave then acknowledges and transmits the data from the requested register. The Master does not acknowledge (NAK) it received the transmitted data, but transmits a stop condition to end the data transfer.
I have interpreted this as:
Returns a,a1 and a2 all=0 (hence an acknowledgement), but 'c' returns 157 regardless of the motion of the device.
Any suggestions on if I am interpreting the datasheet correctly into code?
PS: I have also tried:
to no avail.
Regards, Sam Wane