Can't log SPI barometer(VT1000) reading to SD card with SD lib

Hello,

I log pressure sensor reading via SPI to SD memory card. I used example code to run VT1000 barometer with SPI(Chip Select Pin 7). It is OK. and I can read/write SD memory card with arduino default lib for SD based SPI(ship select Pin 10). My final code is to log pressure data into SD Memory. I shared MISO, MOSI, SCK(13,12,11) and seperated chip select pin for two device. But Final writing is OK but can't communicate with VT1000 sensor. How to use two SPI module in one master uno board?
Any comments welcome!

#include "Wire.h"
// the sensor communicates using SPI, so include the library:
#include <SPI.h>

#include <SD.h>
#define LOG_INTERVAL  1000 // mills between entries (reduce to take more/faster data)

// how many milliseconds before writing the logged data permanently to disk
// set it to the LOG_INTERVAL to write each time (safest)
// set it to 10*LOG_INTERVAL to write all data every 10 datareads, you could lose up to 
// the last 10 reads if power is lost but it uses less power and is much faster!
#define SYNC_INTERVAL 1000 // mills between calls to flush() - to write data to the card
uint32_t syncTime = 0; // time of last sync()

//Sensor's memory register addresses:
const int PRESSURE = 0x1F;      //3 most significant bits of pressure
const int PRESSURE_LSB = 0x20;  //16 least significant bits of pressure
const int TEMPERATURE = 0x21;   //16 bit temperature reading
const byte READ = 0b11111100;     // SCP1000's read command
const byte WRITE = 0b00000010;   // SCP1000's write command

// pins used for the connection with the sensor
// the other you need are controlled by the SPI library):
const int dataReadyPin = 6;
const int chipSelectPin = 7;
const int SD_chipSelectPin = 10;

#define redLEDpin 2

// the logging file
File logfile;
void error(char *str)
{
  Serial.print("error: ");
  Serial.println(str);
  
  // red LED indicates error
  digitalWrite(redLEDpin, HIGH);

  while(1);
}

void setup() {
  Wire.begin();
  SPI.begin();

  // initalize the  data ready and chip select pins:
  pinMode(dataReadyPin, INPUT);
  pinMode(chipSelectPin, OUTPUT);

  //Configure SCP1000 for low noise configuration:
  writeRegister(0x02, 0x2D);
  writeRegister(0x01, 0x03);
  writeRegister(0x03, 0x02);
  // give the sensor time to set up:
  delay(100);
  
  Serial.begin(9600);
    // initialize the SD card
  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(SD_chipSelectPin, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(SD_chipSelectPin)) {
    error("Card failed, or not present");
  }
  Serial.println("card initialized.");
  
  // create a new file
  char filename[] = "LOGGER00.CSV";
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile = SD.open(filename, FILE_WRITE); 
      break;  // leave the loop!
    }
  }
  
  if (! logfile) {
    error("couldnt create file");
  }
  
  Serial.print("Logging to: ");
  Serial.println(filename);

 
}

void loop() {
  float real_temp = 0.0;
  long  pressure = 0;
  char buffer[30];
  Serial.write(PrintDateTime());
  Serial.print(", ");
//  print_BaroTemp(); 
  get_BaroTemp(&real_temp, &pressure); 
/*  Serial.print("Temp[C]=");
  Serial.print(real_temp, DEC);
  Serial.print(" ");
  Serial.print("Pressure[Pa]=");
  Serial.println(pressure, DEC);
*/  
  int sub = 0;
  sub = (int)(100.0*(real_temp - int(real_temp)));
  sprintf(buffer,"Temp[C]=%2d.%2d, Pressure[Pa]= %4d\n",int(real_temp), sub,pressure);
  Serial.print(buffer);

  logfile.print(String(buffer));  //file writing
  // delay for the amount of time we want between readings
  delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));
  
  // log milliseconds since starting
  uint32_t m = millis();
  // Now we write data to disk! Don't sync too often - requires 2048 bytes of I/O to SD card
  // which uses a bunch of power and takes time
  if ((millis() - syncTime) < SYNC_INTERVAL) return;
  syncTime = millis();
  digitalWrite(redLEDpin, HIGH);  
  logfile.flush();
  digitalWrite(redLEDpin, LOW);


  setup_time();
}

I don't know anything about the barometer itself, but I do know a little about the SPI bus. Try this.

  pinMode(chipSelectPin, OUTPUT);
  // disable SD while read/write to barometer.
  // Once SD.begin() runs, this will be HIGH if not in a SD function
  pinMode(SD_chipSelectPin,OUTPUT);
  digitalWrite(SD_chipSelectPin,HIGH);

  //Configure SCP1000 for low noise configuration:
  writeRegister(0x02, 0x2D);
  writeRegister(0x01, 0x03);
  writeRegister(0x03, 0x02);
  // give the sensor time to set up:
  delay(100);

You may need to check if the barometer library writeRegister (and readRegister?) functions manipulate the SS pin for the barometer. The read/write functions should set the barometer SS LOW, do the read/write, then set the SS pin HIGH.

edit: My bad. I used the wrong SS pin, It should have been SD_chipSelectPin. Also if the barometer read/write routines do not manipulate the SS pin, it isn't hard. Like this:

  digitalWrite(chipSelectPin,LOW);
  writeRegister(0x02, 0x2D);
  writeRegister(0x01, 0x03);
  writeRegister(0x03, 0x02);
  digitalWrite(chipSelectPin,HIGH);

Hi SurferTim,
Thank you for comment.
PinSelectline is already inserted in writeRegister(). but SD_module not inactive, I add digitalWrite(SD_chipSelectPin, HIGH) at original code.
But problem is not fixed.

void writeRegister(byte thisRegister, byte thisValue) {

  // SCP1000 expects the register address in the upper 6 bits
  // of the byte. So shift the bits left by two bits:
  thisRegister = thisRegister << 2;
  // now combine the register address and the command into one byte:
  byte dataToSend = thisRegister | WRITE;

  // take the chip select low to select the device:
  digitalWrite(SD_chipSelectPin, HIGH);
  digitalWrite(chipSelectPin, LOW);

  SPI.transfer(dataToSend); //Send register location
  SPI.transfer(thisValue);  //Send value to record into register

  // take the chip select high to de-select:
   digitalWrite(SD_chipSelectPin, LOW);
   digitalWrite(chipSelectPin, HIGH);

}