Go Down

Topic: Arduino -Due SPI read and unexpected values (Read 290 times) previous topic - next topic

nagu3112

Hi,

I am using Arduino-Due and interfaced a sensor using below SPI pins.
I read 1 byte of data from 0x80 register and did not get the expected value from the register when I read. (I get random values every time)
Could someone help to point out if I use the APIs properly?

HW:
MISO - Physical pin #108
MOSI - Physical pin #109
MSCK - Physical pin #110
CS1 - Physical pin #137

SW:
SPI_MODE0
1MHz Baud rate
I did not set the bit order
/*********************************************************************

Arduino and sensor interfacing
   
*********************************************************************/
#include <stdint.h>
#include <SPI.h>
#include <Wire.h>


const int slaveAPin = 4;

void setup()   
{           
  Serial.begin(9600);

  sensor_spi_settings();

}

void loop()
{
  delay(1000);
  sensor_chip_id();   
}


void sensor_spi_settings(void)
{
  /* SPI Init */
  pinMode (slaveAPin, OUTPUT);
  digitalWrite(slaveAPin, HIGH);
  // initialize the bus for the device on pin 4
  SPI.begin(slaveAPin);
  SPI.setClockDivider(slaveAPin, 84);
  SPI.setDataMode(slaveAPin,SPI_MODE0);

}



void sensor_chip_id(void)
{
    uint8_t reg_adr;
    uint8_t reg_data;
    reg_adr = 0x80;
    SPI.transfer(slaveAPin,reg_adr,SPI_CONTINUE);
    reg_data = SPI.transfer(slaveAPin,0x00);
       
    Serial.print("Chip-ID : ");
    Serial.print(reg_data, HEX);
    Serial.println();
   
}






   


ard_newbie

What is the sensor you are actuelly using ? where is the link to the datasheet of the sensor ? did you read it ?


BTW, there is an example sketch of a sensor reading with SPI and an UNO that you could study and adapt to your needs with the DUE:

https://www.arduino.cc/en/Tutorial/BarometricPressureSensor

nagu3112

Thanks...
I use BMI088 sensor. I use the extended SPI APIs. I dont find a comple example with this version.
I have already seen this example as its part of the Arduino IDE.
Any further inputs?

Go Up