[SOLVED] SPI communication MMA7455

Status
Not open for further replies.

YIM bunchhat

Member level 2
Joined
Oct 19, 2010
Messages
46
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Visit site
Activity points
1,580
:-(...Hello everyone, I have one question on accelero sensor. I am using Mikrobasic pro for PIC that have already SPI library. But it do not work properly when I read data from MMA7455. Data I got is always 0x00. Is there any body can show me how to read data from sensor properly. What do SPI_READ (dummy) and "dummy" means?
 

I2C will be more convenient option to use MMA7455.
please share the way you've connect your circuit.
provide the way you're communicating with sensor... I mean share your flowchart/algorithm.
And do consider I2C as your choice if possible.
 

I success with I2C already, I plan to use PIC18F4431 that have 8 PWM channels to make qaudrotor but unfortunately this PIC device have only I2C slave and SPI master so I cannot use I2C to read data from MMA7455, because of Mikrobasic pro for pic did not provide I2C library for this PIC device. I tried with Software I2C too it is possible but this library block interrupt program flow so PWM cannot use while using Software I2C. Is there any way please help me? I cannot change PIC right now because each PIC I have to order from overseas need at least 1 month to arrive.
 

please share the way you've connect your circuit.
provide the way you're communicating with sensor... I mean share your flowchart/algorithm.
and exact problem you're facing while communicating.
what signals are you sending to get data and to provide address??
 

Hello Jigar, I test with PIC16F887 and I use COM port to read data. But receive only 0 for all axis. I must use this sensor with SPI because no choice I2C master for PIC18F4431.


code:
Code:
program Accelrometer

SYMBOL CS = PORTC.0

DIM DAX,DAY,DAZ AS SHORT
DIM VX,VY,VZ AS STRING[4]

''''''''''''''''''Read data from sensor''''''''''''''''''''''''''''
SUB FUNCTION SPI_RD(DIM ADD AS BYTE) AS BYTE
    RESULT = 0
    ADD = ADD << 1
    ADD = %00000000 OR ADD
    CS = 0
    SPI1_write(ADD)
    RESULT = SPI1_read(0x00)
    CS = 1
END SUB

''''''''''''''''''''''''Write register to sensor''''''''''''''''''''''''''''''''''''
SUB PROCEDURE SPI_WR(DIM ADD AS BYTE,DIM THEDA AS BYTE)
    ADD = ADD << 1
    ADD = %10000000 OR ADD
    CS = 0
    SPI1_write(ADD)
    SPI1_write(THEDA)
    CS = 1
END SUB

main:
     DAX =0
     DAY = 0
     DAZ = 0
     Delay_ms(3000)
     UART1_Init(9600)
     SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_HIGH_2_LOW)
     SPI_WR($0D,$9D)
     SPI_WR($16,$05)
     SPI_WR($10,40)
     SPI_WR($12,90)
     SPI_WR($14,0)
          START:
           DAX = SPI_RD($06)
           DAY = SPI_RD($07)
           DAZ = SPI_RD($08)
           ShortToStr(DAX,VX)
           ShortToStr(DAY,VY)
           ShortToStr(DAZ,VZ)

''''''''''''''''''Send data to COM''''''''''''''''
           UART1_Write_Text(VX)
           UART1_Write_Text(VY)
           UART1_Write_Text(VZ)
           Delay_ms(500)
      GOTO START
end.
 
Last edited:

I use Mikrobasic pro for pic. And schema is just example to test. It is no problem, I just let other know I am not wrong connect, SPI connection is correct. But my problem is communication please help me on SPI. How can I read or write register to MMA7455 via SPI?
 
Last edited:

Please check on my code, As I tell you schema is just example. Proteus don't have MMA7455 device to test. But I have tested with real MMA7455 and I got only data 0 all axis with Nothing change. But I have already test MMA7455 with I2C and it work correctly.:sad:
 

Attachments

  • Accelerometer.rar
    27.2 KB · Views: 61

No, I just see what you post now. I will read it. Could you tell me in summery about it?:grin:

- - - Updated - - -

Could you tell me what is my problem on my code?
 
Last edited:

Sorry, Proteus don't have MMA7455 to test. I tested with real sensor MMA7455. Data received is only 0 every axis. I have read datasheet MMA7455 and follow its instruction but still not work with SPI. According to your experience on MMA7455, Is there any secret how use SPI beside datasheet? Could you tell only algorithm and code I can write by myself?
 

My uC is 5V and MMA7455 is the same. But wonder why I use I2C is OK and SIP is incorrect. Is it possible that problem is in library SPI of Mikrobasic Pro for PIC? But I used to test SPI library of this software follow its example is OK. When I want to use it with MMA7455 it not work properly.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…