PDA

View Full Version : I2C MMA8452 Accelerometer



emf985
- 12th August 2013, 07:35
I connected to the I2C bus 4 chips that work perfect ,I can read and write without any problem,
(2 x PCA9532 - LED drivers,MAX17043 - Fuel Gauge, DS1307 - RTC).but the MMA8452 returns only zeros.
I tried slow ans high speeds,I2C_HOLD but failed.
I use the PIC18F2553 at 48MHz
The compiler is PBP 2.6
Help,Please....

emf985
- 12th August 2013, 08:56
I read the datasheet and it says:"Single Byte ReadThe MMA8453Q has an internal 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 11 shows the timing diagram for the accelerometer 8-bit I2C
read operation. The Master (or MCU) transmits a start condition (ST) to the MMA8453Q, slave address ($1D), with the R/W bit
set to “0” for a write, and the MMA8453Q sends an acknowledgement. Then the Master (or MCU) transmits the address of the
register to read and the MMA8453Q sends an acknowledgement. The Master (or MCU) transmits a repeated start condition (SR)
and then addresses the MMA8453Q ($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) the transmitted
data, but transmits a stop condition to end the data transfer."
How can I send a repeated start?

rsocor01
- 12th August 2013, 12:20
but the MMA8452 returns only zeros.


I assume that you are using a different address for every device. Isolate the MMA8452 and try to communicate with it first.

emf985
- 12th August 2013, 14:31
Thanks
Yes,of course ,the problem, as I see it , is that the pbp cannot produce a repeated start .
I used a logic analizer -----> the accelerometer sends acknowlage signals.
the data sheet demands an Sr (repeat start) in order to read the device.
the device resets the address register to zero if the master sends a STOP.
I can read only the top seven registers only.(there are a lot of registers).

pedja089
- 12th August 2013, 14:47
Maybe this will help you.
http://www.picbasic.co.uk/forum/content.php?r=165-Serial-EEPROM-Part-1

emf985
- 12th August 2013, 17:54
Thanks,I read it,( there is no part 2) .
I used PBP I2CREAD and I2CWRITE instructions .
Maby there is something to be done with the instructions we have,I hope I'll not be forced to write new I2C subrutines just for this device.(hopefully somone did write it)

pedja089
- 12th August 2013, 18:32
This is I2C write:
GOSUB INT_ROM
SHIFTOUT DPIN,CPIN,1,[DATO\8,%1\1]
GOSUB STOP_ROM

I2CREAD:
GOSUB INT_ROM
GOSUB START_ROM
SHIFTOUT DPIN,CPIN,1,[CONT1]
SHIFTIN DPIN,CPIN,0,[ACK\1,DATI\8]
SHIFTOUT DPIN,CPIN,1,[%1\1]
GOSUB STOP_ROM

This is start sequence:
START_ROM:
HIGH CPIN:HIGH DPIN:LOW DPIN:RETURN

Every thing is already done...

LinkMTech
- 12th August 2013, 20:45
I have a LSM330DLC accelerometer set up with a PIC18F14K50 but used the MSSP hardware module for the I2C. What a workout!
This device also calls for the "Repeated Start Condition" when reading a register.

Unfortunately, I am using PBPX 3.0. So can't say if this works the same as your version. :o

After playing around with the I2CREAD a little bit, was surprised to find that the READ statement supplied everything to read the "WHO AM I" register of the Gyro with just the I2CREAD statement.

Gyro info:
Write address = $D6
Read address = $D7
Device ID register located at $0F should contain $D4

This code provided the following as seen on the screen capture:

Start condition (1st Green dot)


Write to address $D6 to Read register $0F


Inserts the "Repeated Start Condition" (SR), (2nd Green dot)


Then the Read address $D7 followed with the clocked in Gyro register data value $D4



MAIN:
I2CREAD SDA,SCL,$D7,$0F,[Mem_data]
PAUSEUS 100 ' A little pause to visually seperate on display
GOTO MAIN


7063


I learned something new today. Hope this helps.

emf985
- 13th August 2013, 08:34
I have pbp 2.6 (by the way ,is it worth upgrading?)
my code is like this:
'
'The WHO_AM_I register is factory set to $3A
'
I2CWRITE IICData,IICScl,$3A,[$0D],IICFail 'WHO_AM_I register address = $D
I2CREAD IICData,IICScl,$3B,[STR a\7],IICFail 'Fails to read, it reads only the first 7 bytes .... after STOP the counter
I'm going to try your way
thanks

emf985
- 13th August 2013, 08:54
YES!!! IT WORKS!!!
I didn't know that the register address to read can be set in I2CREAD. I used ,by mistake I2CWRITE to set the address of the register and then read it.
This is also new to me

rsocor01
- 13th August 2013, 11:56
I have pbp 2.6 (by the way ,is it worth upgrading?)


That's another topic. It is discussed here

PBP 3.0 really needed?
http://www.picbasic.co.uk/forum/showthread.php?t=16234

ecoli-557
- 14th January 2015, 22:46
LinkMTech-
I am just now workiing with a LSM330DLC myself on a PIC18F66J11 and also PBP3.
Was wondering if I get stuck on how to set it up, read data, etc if you wouldn't mind giving me some pointers?
I plan on using I2C interface (I think its easier) and I planned on using DT's interrupt (sure miss that Guy) and reading from it.
I am working the schematic now and will have a test board made in a few days.
You can PM if you like.

Regards,
Steve

LinkMTech
- 15th January 2015, 17:28
Hi Steve,

Sure I'll help you out. My project works but on the shelf for now.
Got your PM.

Louie