BRKOUT-FXLS8471Q using SPI

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

BRKOUT-FXLS8471Q using SPI

1,768 Views
inge
Contributor I

Hi, I've connected the FXLS8471Q breakout board via its SPI connection and a bi-directional level shifter to a Redboard ('same' as Arduino Uno) but get only -1 as output values. I checked the pins with an oscilloscope and it is clear that the Arduino is communicating to the CS_B, SCL and MOSI pins, but the MISO pin isn't to the Arduino.

Is there something I forgot to get the sensor 'active'? I attached the code I'm using.

I powered the breakout board by the VDD connection, but in the data sheet there is also something mentioned about the interface power. Is this already connected in the board or does it need additional wiring?

Here the .cpp file:

// FXLS8471Q registers

#define FXLS8471Q_STATUS 0x00

#define FXLS8471Q_WHOAMI 0x0D

#define FXLS8471Q_XYZ_DATA_CFG 0x0E

#define FXLS8471Q_CTRL_REG1 0x2A

int16_t slaveSelectPin = 10;

FXLS8471Q::FXLS8471Q() {

}

void FXLS8471Q::begin(int16_t chipSelectPin) {

    slaveSelectPin = chipSelectPin;

    pinMode(slaveSelectPin, OUTPUT);

    SPI.begin();

    SPI.setClockDivider(SPI_CLOCK_DIV16);                                    // 16 MHz / 16 = 1 MHz

    SPI.setDataMode(SPI_MODE0);    //CPHA = CPOL = 0    MODE = 0

    SPI.setBitOrder(MSBFIRST);

    delay(1000);

  

    // reset sensor

    SPIwriteOneRegister(0x2B, 0x40);                        // set RST in CTRL_REG2 register

    delay(100);

  

    // set range to 4g

    SPIwriteOneRegister(FXLS8471Q_XYZ_DATA_CFG, 0x01); // Write to FXLS8471Q_XYZ_DATA_CFG

  

    // set data rate to 200 Hz and enable sampling

    SPIwriteOneRegister(FXLS8471Q_CTRL_REG1, 0x15); //

void FXLS8471Q::readXYZData(int16_t &XData, int16_t &YData, int16_t &ZData){

   

      digitalWrite(slaveSelectPin, LOW);

      delay(10);

      SPI.transfer(0x01);  // send read instruction (RW=0, address=0x01)

      SPI.transfer(0x00);  // send second byte

    

      XData = SPI.transfer(0x00) << 8;      //Most significant bit(MSB) first, then LSB

      XData = XData + SPI.transfer(0x00);

      XData = XData >> 2;

      YData = SPI.transfer(0x00) << 8;

      YData = YData + SPI.transfer(0x00);

      YData = YData >> 2;

    

      ZData = SPI.transfer(0x00) << 8;

      ZData = ZData + SPI.transfer(0x00);

      ZData = ZData >> 2;

      digitalWrite(slaveSelectPin, HIGH);

}

And the header file:

#include "Arduino.h"

#ifndef FXLS8471Q_h

#define FXLS8471Q_h

class FXLS8471Q

{

public:

    FXLS8471Q();

    // Basic Device control and readback functions

    void begin(int16_t chipSelectPin = 10);

    void FXLS8471Q::readXYZData(int16_t &XData, int16_t &YData, int16_t &ZData)

};

#endif

The code I'm running

#include <SPI.h>

#include <FXLS8471Q.h>

FXLS8471Q xl;

int16_t XValue, YValue, ZValue;

void setup(){

  Serial.begin(9600);

  xl.begin(10);                   // Setup SPI protocol, issue device soft reset

}

void loop(){

  

  // read all three axis in burst to ensure all measurements correspond to same sample time

  xl.readXYZData(XValue, YValue, ZValue);

  Serial.print("XVALUE=");

  Serial.print(XValue);   

  Serial.print("\tYVALUE=");

  Serial.print(YValue);   

  Serial.print("\tZVALUE=");

  Serial.print(ZValue);

  Serial.println();    

  delay(100);                // Arbitrary delay to make serial monitor easier to observe

}

Labels (1)
0 Kudos
5 Replies

844 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Inge,

As you can see in the attached schematic, the VDDIO (I/O pins supply voltage) is not connected with VDD on the board. It is necessary to connect the following pins to your MCU, including the DVDD:

MOSI – J3-7

MISO – J4-7

CS – J4-5

SCLK – J3-6

VDD – J4-1

DVDD – J3-2

GND – J3-8

Also take a look at my example code, you might find it useful.

Please let me know whether or not this helps or if you have any further questions.

Regards,

Tomas


PS: If my answer helps to solve your question, please mark it as "Correct" or “Helpful”. Thank you.

0 Kudos

844 Views
michmar
Contributor I

Hi Tomas,

Due to issue with software reset in FXLS8417Q I prefer to use I2C communication. I've tried to find schematic for proper connection of this board: Breakout Board for FXLS8471Q Accelerometer|NXP  but there isn't any. I've tried to send you a message but for this moment I'm unable. Why NXP doesn't provide schematic design for this board?

Thanks in advance.

0 Kudos

844 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Michal,

The schematic of the FXLS8471Q breakout board is attached to my previous answer. Please let me know if you cannot download it.

As you can notice, the board is designed to communicate with a master MCU through SPI. To get the board to work in I2C mode, you will need to connect external pull-ups on both SCL (pin#4 or J3-6) and SDA (pin#6 or J3-7) lines . Also both SA0 (pin #7 or J4-7) and SA1 (pin#10 or J4-5) address select pins need to be connected to either GND or DVDD depending on the slave address you want to assign (Table 8 in the datasheet summarizes all four options).

I hope it helps.

Regards,

Tomas

0 Kudos

844 Views
michmar
Contributor I

Thanks for reply.

I can download your schematic. I don't have to remove any elements from board? What should be pull-up resistor value? Is 10K suitable?

Also have another question: I will use 3.3V to supply VDD and DVDD pins. Won't this make any problems? If you could add me to your contacts I will send you schematic of my device, because I will have some questions about NXP IC's.

Kind regards,

Michal

0 Kudos

844 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Michal,

The recommended value of the pull-up resistors is 4.7K. There is no problem to supply both VDD and VDDIO from the same 3.3V source.

If you want to send me a private message, I think that you need to follow me by clicking the “Follow” button here.

You may also consider using the newer board - BRKTSTBC-A8471, which can be modified for the I2C communication more easily. Here is the schematic. As described in note #4, populate R8 - SDA pull-up resistor, R9 - SCL pull-up resistor, R1 (or R3) - SA1, R2 (or R4) - SA0 for I2C interface.

Hope it helps.

Regards,

Tomas

0 Kudos