Go Down

Topic: V2XE compass sensor syncrnous problem (Read 411 times) previous topic - next topic

i am new to arduino technology kindly help me out.


here  is code for v2xe mode information. once i got the correct output but later again i didn't get correct value. now the output is:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

once i saw correct information.


code is:



Code: [Select]

#include <SPI.h>
#include "pins_arduino.h"


// used pins
#define SS          10    // SPI "slave select" pin. active low. (same as the analog pin 0, used in digital)
#define SYNC_PIN    7    // Sync resets the compass' communication buffers on raising front
#define kSyncChar   0xAA
#define kTerminator 0x00

char a[8];

enum{
    // commands/frame types
    kGetModInfo = 1,    // 0x01
    kModInfoResp,       // 0x02
};


void setup (void)
{
  Serial.begin (115200);
  Serial.println ();
  SPI.begin ();
 
  pinMode(SCK, OUTPUT);
  pinMode(MOSI, OUTPUT);
  pinMode(SS, OUTPUT);

  digitalWrite(SCK, LOW);
  digitalWrite(MOSI, LOW);
  digitalWrite(SS, HIGH);
 
  pinMode(SYNC_PIN, OUTPUT);
  // Put SCK, MOSI, SS pins into output mode
  // also put SCK, MOSI into LOW state, and SS into HIGH state.
  // Then put SPI hardware into Master mode and turn SPI on
//pinMode(MISO, INPUT);
  // Slow down the master a bit
  SPI.setClockDivider(SPI_CLOCK_DIV8);
  //SPI.setDataMode(SPI_MODE0);
  delay(10);

  // sync the compass
  v2xe_sync();



}  // end of setup

void v2xe_sync(){
  digitalWrite(SYNC_PIN, LOW);
  delay(10);
  digitalWrite(SYNC_PIN, HIGH);
  delay(10);
  //digitalWrite(SYNC_PIN, LOW);
}

byte transferAndWait (const byte what)
{
  byte a = SPI.transfer (what);
  delayMicroseconds (10);
  Serial.println(a);
  return a;
}

bool v2xe_check_module(){
  bool ok = false;

  // enable Slave Select
  digitalWrite(SS, LOW);   
  delay(1);

  //for (int i = 0; i< 50; i++){
    //if
    while(kSyncChar == transferAndWait (0)) {
      //Serial.println(ok);
      ok = true;
     
      break;
    }
  //}
  Serial.println (ok);

  if (ok) {
    // receive the command
    if (kModInfoResp == transferAndWait (0)) {
      for (int i = 0; i< 8; i++){
         a[i]= transferAndWait (0);
     }
     
   
    }
  }

  // disable Slave Select
  digitalWrite(SS, HIGH);
   
  return ok;
}

void loop (void)
{

  digitalWrite(SS, LOW);
  delay(1);
  // transmit the command
  transferAndWait (kSyncChar);     // all frames always start with a sync character
  transferAndWait (kModInfoResp);   // the frame type
  transferAndWait (kTerminator);   // don't forget the terminator
  // enable Slave Select

  digitalWrite(SS, HIGH);   
  delay(1);
  if (v2xe_check_module()) {
    Serial.print ("Module Type: ");
    Serial.print (a[0]);
    Serial.print (a[1]);
    Serial.print (a[2]);
    Serial.println (a[3]);
    Serial.print ("Firmware Version: ");
    Serial.print (a[4]);
    Serial.print (a[5]);
    Serial.print (a[6]);
    Serial.println (a[7]);
  }
  delay(1000);
}  // end of loop


Kindly check it sir. According to me its having syncronous problem. i shall be thankful to you sir if you guide me sir further. i used the  voltage divider with resistor

1. 10K ohm
2. 15K ohm

i took voltage against 15K ohm that is 3v

Kindly let me know that what is mistake if i am doing sir .

Regards,
Usman Munawar


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy