Sharing SPI between Ethernet / SD Shield and RTD-1000 Breakout


greetings,

i new arduino community , seek programming project.

i have built pt-1000 temperature measurement system using arduino uno board pt-1000 breakout board playwithfusion.com utilizing max31865. have working till start trying log data serial monitor onto microsd card on arduino ethernet shield. unable obtain correct reading anymore.

to honest, still bit confuse ss pin selection. know sd card reader uses ss @ pin 4 , ethernet port uses ss @ pin 10. pt-1000 breakout board uses ss/cs @ pin 10, because breakout board capable of connecting 2 pt-1000 sensors, have assigned pin 8 , pin 9 ss pins 2 pt-1000 sensors. realize there may spi conflicting because have pt-1000 breakout board , sd card sharing the spi.

here codes. show code 1 pt-1000 sensor. appreciated.

code: [select]

// sensor communicates using spi, include hardware spi library:
#include <spi.h>
// include playing fusion max31865 libraries
#include <playingwithfusion_max31865.h>              // core library
#include <playingwithfusion_max31865_struct.h>       // struct library

// sd library
#include <sd.h>

//sensor addresses:
const byte config_reg_w = 0x80; // config register write addr
const byte config_value = 0xc3; // config register value (vbias+auto+faultclear+50hz, see pg 12 of datasheet)
const byte adc_word_msb = 0x01; // addr of first byte of data (start reading @ rtd msb)
const byte adc_fault_reg = 0x07; // addr of fault reg

// cs sd card
const int chipselect = 4;

// cs pin used connection rtd sensor
// other connections controlled spi library)
const int cs_pin1 = 8;
const int cs_pin2 = 9;

pwfusion_max31865_rtd rtd_ch0(cs_pin1);
pwfusion_max31865_rtd rtd_ch1(cs_pin2);

// pt-1000 sensor characteristics curve constants
const float = 3.9083e-3; // [deg c^-1]
const float b = -5.775e-7; // [deg c^-2]
const float c = -4.183e-12; // [deg c^-4]
const int r0 = 1000; // [ohms]

// declare resistance variables
double r1;
double r2;

// decalre temperature variables
double tmp1;
double tmp2;

const float voltage = 5.0;
const int rhpin1 = 0;
const int rhpin2 = 1;

float rhreading1;
float rhreading2;

void setup()
{
 serial.begin(9600);
 
 // make sure default chip select pin set to
 // output, if don't use it:
 pinmode(10, output);
 
 serial.print("initializing sd card ... ");
   
 // see if card present , can initialized:
 if (!sd.begin(chipselect))
 {
   serial.println("card failed, or not present");
   // don't more:
   return;
 }
 serial.println("card initialized.");

 // setup the spi library:
 spi.begin();                        // begin spi
 spi.setdatamode(spi_mode3);         // max31865 mode 3 device
 
 // initalize chip select pin
 pinmode(cs_pin1, output);
 pinmode(cs_pin2, output);
     
 rtd_ch0.max31865_config();
 rtd_ch1.max31865_config();
 
 // give sensor time set up
 delay(1000);
}

void loop()
{
 static struct var_max31865 rtd_ch0;
 static struct var_max31865 rtd_ch1;
   
 // rtd_ch0.rtd_type = 1;                         // un-comment pt100 rtd
 rtd_ch0.rtd_type = 2;                        // un-comment pt1000 rtd
 
 // rtd_ch0.rtd_type = 1;                         // un-comment pt100 rtd
 rtd_ch1.rtd_type = 2;                        // un-comment pt1000 rtd
   
 struct var_max31865 * rtd_ptr0;
 struct var_max31865 * rtd_ptr1;
   
 rtd_ptr0 = &rtd_ch0;
 rtd_ptr1 = &rtd_ch1;
   
 rtd_ch0.max31865_full_read(rtd_ptr0);         // update max31855 readings
 rtd_ch1.max31865_full_read(rtd_ptr1);
 
 // open file. note 1 file can open @ time,
 // have close 1 before opening another.
 file datafile = sd.open("datalog.txt", file_write);
 
 // rtd sensor # 1    
 if(0 == rtd_ch0.status)                       // no fault, print info serial port
 {
   if(1 == rtd_ch0.rtd_type)                   // handle values pt100
   {
     // calculate rtd resistance
     r1 = (double)rtd_ch0.rtd_res_raw * 400 / 32768;
     
     // if file available, write it:
     if(datafile)
     {
       datafile.print(r1);
       datafile.print("   ");
               
       // print serial port too:
       serial.print(r1);
       serial.print("   ");
     }  
     else
     {
       serial.print(r1);
       serial.print("   ");
     }
   }
   else if(2 == rtd_ch0.rtd_type)              // handle values pt1000
   {
     // calculate rtd resistance
     r1 = (double)rtd_ch0.rtd_res_raw * 4000 / 32768;
     
     // if file available, write it:
     if(datafile)
     {
       datafile.print(r1);
       datafile.print("   ");
           
       // print serial port too:
       serial.print(r1);
       serial.print("   ");
     }  
     else
     {
       // serial.println("error opening datalog.txt");
       serial.print(r1);
       serial.print("   ");
     }
   }
   
   /*
   calculate rtd temperature (simple calc, +/- 2 deg c -100c 100c)
   more accurate curve can used outside range
   tmp1 = ((double)rtd_ch0.rtd_res_raw / 32) - 256;
   */
   
   tmp1 = (-a+sqrt(pow(a,2)-4*b*(1-r1/r0)))/(2*b);
   if(datafile)
   {
     datafile.print(tmp1);
     datafile.print("   ");
         
     // print serial port too:
     serial.print(tmp1);
     serial.print("   ");
   }
   else
   {
     // serial.println("error opening datalog.txt");
     serial.print(tmp1);
     serial.print("   ");
   }
 } // end of no-fault handling
 else
 {
   serial.print("rtd fault, register: ");
   serial.print(rtd_ch0.status);
   if(0x80 & rtd_ch0.status)
   {
     serial.println("rtd high threshold met");  // rtd high threshold fault
   }
   else if(0x40 & rtd_ch0.status)
   {
     serial.println("rtd low threshold met");   // rtd low threshold fault
   }
   else if(0x20 & rtd_ch0.status)
   {
     serial.println("refin- > 0.85 x vbias");   // refin- > 0.85 x vbias
   }
   else if(0x10 & rtd_ch0.status)
   {
     serial.println("force- open");             // refin- < 0.85 x vbias, force- open
   }
   else if(0x08 & rtd_ch0.status)
   {
     serial.println("force- open");             // rtdin- < 0.85 x vbias, force- open
   }
   else if(0x04 & rtd_ch0.status)
   {
     serial.println("over/under voltage fault");  // overvoltage/undervoltage fault
   }
   else
   {
     serial.println("unknown fault, check connection"); // print rtd temperature heading
   }
 }  // end of fault handling
 
 // humidity sensor # 1
 rhreading1 = analogread(rhpin1);
 double rh1 = ( rhreading1 / 1024.0 ) * voltage * 100.0;
 if(datafile)
 {
   datafile.print(rh1);
   datafile.print("   ");
         
   // print serial port too:
   serial.print(rh1);
   serial.print("   ");
 }
 else
 {
   // serial.println("error opening datalog.txt");
   serial.print(rh1);
   serial.print("   ");
 }

th sd card mode0 device last checked. need switch modes when accessing 1 or other, switch back.

you should disable spi devices before initializing of them. starting sd card rtd-1000 spi cs pins floating risky @ best.


Arduino Forum > Using Arduino > Programming Questions > Sharing SPI between Ethernet / SD Shield and RTD-1000 Breakout


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support