SPI Learning with the mma7455 - Netduino Plus 2 (and Netduino Plus 1) - Netduino Forums
   
Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

SPI Learning with the mma7455


  • Please log in to reply
8 replies to this topic

#1 JWills

JWills

    New Member

  • Members
  • Pip
  • 7 posts

Posted 08 December 2012 - 10:06 PM

Hi,

I'm getting frustrated, I bought a Parallax MMA7455 3 axis accelerometer module. I hooked up my Netduino Plus in SPI mode. Followed the Wiki's the best I could and am having issues getting data from it. Here is the links to the PDFs from parallax- module pdf and chip set PDF

The things I noticed are:

On the module I have only has 3 com connections. CLK, DATA, and CS. I read the sheet and it is supposed to automatically switch between read and write, so I put pin 11 and 12 together on the data pin.

I put pin 10 as my CS, and pin 13 as the CLK. Im using the Netduino plus 5V reg pin and GND.

the code I did looks like the following.


using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;

namespace spi
{
    public class Program
    {
       
        public static void Main()
        {
            // write your code here
            SPI.Configuration MySPI = new SPI.Configuration(Pins.GPIO_PIN_D10, false, 0, 0, true, false, 4000, SPI_Devices.SPI1);
            SPI spibuss = new SPI(MySPI);
            byte[] wb = new byte[2];
            wb[0] = 0x16;                  //mod configuration
            wb[1] = 0x25;
            spibuss.Write(wb);

            while (true)
            {
                //const byte cmd_readdata = 06;

                byte[] WriteBuffer = { 0xff }; //send a dumb byte because you have to write somthing to the slave
                byte[] ReadBuffer = { 0x06 };  //read the x-axis data.
                spibuss.WriteRead(WriteBuffer, ReadBuffer);
                Debug.Print(ReadBuffer[0].ToString()); //put this data in the debug window so we can see if it is really doing anything.
                Thread.Sleep(1000);
            }

        }

    }
}

I am sure its something I am messing up. I just want to keep it simple and build from that. Its how I learn the best. If anyone can help I would be so grateful. There is not many examples of c# on the web for that module yet.

#2 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 08 December 2012 - 10:26 PM

i dont think netduino/netmf supports sdi/sdo on the same line. ud have to use i2c instead. (chip supports both, i2c and that strange spi)

#3 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 09 December 2012 - 09:34 AM

I agree with NooM that you may be better using I2C.
It is a shame that they did not bother to connect the third SPI pin from the chip to the module. (There is an unused pin they could have used.)

Just before you switch to I2C, you could try using a low power signal diode to connect the Netduino's SDI and SDO pins together.

Connect the Netduino's SPI input pin "MISO" directly to the device as normal.
Connect the Netduino's SPI output pin "MOSI" to the MISO pin via the diode, so that current can flow into the MOSI pin.

With this arrangement, if the Netduino pulls the MOSI pin low, the diode will conduct and a low signal will be sent to the device.
If the Netduino pulls the MOSI pin high, the diode will turn off and the line will be pulled high by the 10K pull up that is in the module.
Basically you will have turned data line of the SPI interface into a multi-drop bus.

When you want to write to the device, do it as normal. When you want to read, set the write data bits all high and the device will be able to send data back the other way.

Hope this helps - Paul

#4 JWills

JWills

    New Member

  • Members
  • Pip
  • 7 posts

Posted 09 December 2012 - 11:24 PM

Thanks for the reply, I will try the diode, if that dont work ill learn I2C first.

#5 neslekkim

neslekkim

    Advanced Member

  • Members
  • PipPipPip
  • 350 posts
  • LocationOslo, Norway

Posted 10 December 2012 - 12:53 PM

will this module work better? http://dangerousprot..._breakout_board http://www.seeedstud...tml?cPath=61_68 Looks like there is two pins marked with SDO?

--
Asbjørn


#6 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 10 December 2012 - 09:46 PM

will this module work better?
http://dangerousprot..._breakout_board
http://www.seeedstud...tml?cPath=61_68

Looks like there is two pins marked with SDO?



yes, when you follow your first link.. and scroll down a bit, its the spi interface we have on netduino.

but if it will work better, it will work for spi.
both work for i2c!

#7 neslekkim

neslekkim

    Advanced Member

  • Members
  • PipPipPip
  • 350 posts
  • LocationOslo, Norway

Posted 10 December 2012 - 09:57 PM

yes it's the same chip, but it seems like they have given you access to pins that you missed? If you look at the schema for Dangerousprototypes and compare it to PArallax, you see that parallax did not bring out pin 12, but DP did..

--
Asbjørn


#8 JWills

JWills

    New Member

  • Members
  • Pip
  • 7 posts

Posted 14 December 2012 - 02:48 AM

Thanks for the links, Ill pick up one of the cards and see if that is easier to learn on. Right now I'm trying to go ahead and learn I2C without using a library. I2C is not near as straight forward, but ill get it. Thanks everyone for all your help. I2C and SPI is the only 2 functions I have not figured out on the netduino plus and plus 2.

#9 ne_vem

ne_vem

    New Member

  • Members
  • Pip
  • 1 posts

Posted 13 January 2013 - 11:51 PM

I also had problems with SPI. I spend all Sunday to make it work. I gues we had the same problem.

If you are not sure about wiring (like me) use resistors in series to prevent the damage at miswiring (it is easy if you use protoboard). I found some diferent instructions about wiring SPI, I guess it depends on different pin labeling (SDI master -> SDO slave, SDO master -> SDI slave)

Read this datasheet (page 18): http://www.freescale...et/MMA7455L.pdf

Address of registers are only 6 bits long and mode register address is $16 (HEXA). So you need to send 2 bytes to initialize mma7455. (0xAC (R/W, register $16, don't care bit) and 0x05 (4wire, +-2g, measure mode))

Than you red registers. To read register $06(hexa) you send 0x0C (0=read, 6bit address, don't care bit) and at next yu wil get 8 bit long value of register $06 (Xout).

At 4 wire mode you transfer data in both ways at the same time, so when you read you can also prepare mma7455 for next data transfer. It is faster than I2C and less environment sensitive.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.