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.

orange's Content

There have been 29 items by orange (Search limited from 25-September 23)


By content type

See this member's


Sort by                Order  

#20858 SPI (with ADXL345)

Posted by orange on 22 November 2011 - 03:46 PM in General Discussion

Thanks for looking into this. Below was a typo.

NO, the original wiring is correct and it matches all documents (two above) and what you say below.

When reading http://www.sparkfun....ter/ADXL345.pdf page 8 Figure 4. 4, I see:

/CS (pin 7 on the ADXL345, which must to a random GPIO for Netduino indeed)
SDI (also known as SDA/SDIO, pin 13 on the ADXL345, which must go to netduino MOSI; Netduino pin D11)
SDO (also known as ALT ADDRESS, pin 12 on the ADXL345, which must go to netduino MISO; Netduino pin D12)
SCLK (also known as SCL, pin 14 on the ADXL345, which must go to netduino SPCK; Netduino pin D13)

So you switched pins 11 and 12.




#20854 SPI (with ADXL345)

Posted by orange on 22 November 2011 - 03:05 PM in General Discussion

Thanks for the reply. Both seem to be acting the same. Both compile and both are available in auto complete. Both randomly fail Device ID between each compile.

I changed it to suggested
Pins.GPIO_Pin0
since it matches documentation to be on safe side.

but the same issues exist.

It's safer to use your suggestion due to my original reference to Wiki page: http://wiki.netduino...figuration.ashx and http://wiki.netduino...SPI.ashx?HL=spi

Orange, to solve one problem, just change:

Cpu.Pin.GPIO_Pin0
To:
Pins.GPIO_Pin0
Basically, the Pins enumeration is a Netduino remapping of the abstract Cpu.Pin set exposed by the Micro Frameowrk.

I know, it's confusing...
Cheers




#20853 SPI (with ADXL345)

Posted by orange on 22 November 2011 - 02:59 PM in General Discussion

Hi,

Connections are similar in Netduino and Arduino (as demonstrated in above article).

To be more specific:

ND 13 SCL, ND 12 SDA, ND 11 SD0, ND Digital 0 (GPIO 0, also tried 1,2 and 10 and matched the SPI.config) to CS, ND 3V3 to VS, ND 3V3 to VIO, ND Gnd to Gnd

It's probably not an issue with physical connections. It randomly changes on multiple compiles and also hack of connecting CS to VCC then Gnd works for passing the initial Device ID check. Not helpful for X/Y/Z reads.

Hi Orange,

When using SPI mode, can you tell us how you've got it connected? To which pins on the netduino?




#20849 SPI (with ADXL345)

Posted by orange on 22 November 2011 - 01:31 PM in General Discussion

I'm trying to use SPI and talk to ADXL345. I can do that with I2C with no problem so I know the sensor is working properly.

There is an article for Arduino and I'm trying to the the same with Netduino (Plus).

http://www.sparkfun.com/tutorials/240

Issue 1) Unfortunately, the SPI.Configuration doesn't work as intended.

The first issue I have is that when I read Device ID it's incorrect but if I manually VCC then GND the Chip Select (inverted) actually works to this point and I can read correct Device ID ! GPIO_Pin0 didn't work neither GPIO_Pin1..GPIO_Pin10 in below configuration as GPIO.

Here is a simple code:
            SPI.Configuration config = new SPI.Configuration(
                        Cpu.Pin.GPIO_Pin0, // I have Chip Select of Sensor connected but it didn't work. See below tests
                        false, // CS is inverted to it's active on low
                        0, // tried both 0 and 1 
                        0, // tried both 0 and 1
                        true, // High on Idle. See figure 37 and 38 in here: http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf, also see http://wiki.netduino.com/SPI-Configuration.ashx
                        true, // Seems to be stable on rising edge. See figure 37 and 38 in here: http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf, also see http://wiki.netduino.com/SPI-Configuration.ashx
                        500, // 500 KhZ, it can be upto 2MHz
                        SPI.SPI_module.SPI1
                        );

            SPI accel = new SPI(config);

            Byte[] wBuff = new Byte[1];
            Byte[] rBuff = new Byte[1];

            wBuff[0] = 0x00;
            accel.WriteRead(wBuff, rBuff);

            Debug.Print("Reading device id from register: " + wBuff[0]);
            Debug.Print("Received device id: " + rBuff[0]);

2) Second issue is after passing this point by VCC/Gnd hack is that data read for X/Y/Z Axis doesn't make sense (changes randomly, stays at zero or has specific numbers) so there is something I'm missing but several tries didn't help. Again, the sensor works well in I2C mode and change of sensor didn't help, wiring is simply so issue should be software, register settings etc.

Here is the code:

            //Put the ADXL345 into full resolution(+/- 2g) mode with the DATA_FORMAT register.
            wBuff[0] = DataFormat;
            accel.Write(wBuff);

            // 0x08 for full resolution (+/- 2g)
            wBuff[0] = 0x08;
            accel.Write(wBuff);

            //Put the ADXL345 into Measurement Mode by writing 0x08 to the POWER_CTL register.
            wBuff[0] = PowerControl;
            accel.Write(wBuff);

            wBuff[0] = 0x08;
            accel.Write(wBuff);

            // Setting FIFO to stream 0x80 also tried no FIFO 0x00 (commenting out following)
            wBuff[0] = FifoStatus;
            accel.Write(wBuff);
            wBuff[0] = 0x80;
            accel.Write(wBuff);


            


            double yAxisGs, xAxisGs, zAxisGs;
 
 
                    Thread.Sleep(100);

                    yAxisGs = 0.0; 
                    xAxisGs = 0.0; 
                    zAxisGs = 0.0; 

                    //
                    Byte[] rBuff6 = new Byte[6];
                    Byte[] wBuff6 = new Byte[6];

                    //wBuff6[0] = 0xFF;
                    //wBuff6[1] = 0xFF;
                    //wBuff6[2] = 0xFF;
                    //wBuff6[3] = 0xFF;
                    //wBuff6[4] = 0xFF;
                    //wBuff6[5] = 0xFF;

                    wBuff[0] = DataX_0 | 0x80 | 0x40; // Also tried without 0x80 (read mode) or (0x40) multiple-byte read mode
                    accel.WriteRead(wBuff6,0,6,rBuff6,0,6,0);

                    const double scale = 0.0039d; // Scale for 2G, full scale

                    xAxisGs = (rBuff6[0] | rBuff6[1] << 8) * scale; // I tried  (rBuff6[0] + rBuff6[1] *256) * scale to make sure it's not a logic, data type issue between byte, uint and double.
                    yAxisGs = (rBuff6[2] | rBuff6[3] << 8) * scale;
                    zAxisGs = (rBuff6[4] | rBuff6[5] << 8) * scale;


                    Debug.Print("x received data is " + xAxisGs);
                    Debug.Print("y received data is " + yAxisGs);
                    Debug.Print("z received data is " + zAxisGs);





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.