Re: Problem with BME280 SPI / TMC2130 SPI on MKS Gen L V2.1


jiripansky@...
 

FYI: I got it working with both sensors (DE3234 & BME280 both SPI connected).

config.h:
#define TIME_LOCATION_SOURCE DS3234
#define WEATHER BME280_SPI
#define PPS_SENSE ON

weather.h modification (as suggested by Howard):
#if! (PINMAP == MksGenL1 || PINMAP == MksGenL2 || PINMAP == MksGenL21)
Adafruit_BME280 bmx (BME280_CS_PIN); // hardware SPI
#else
Adafruit_BME280 bmx (BME280_CS_PIN, SSPI_MOSI, SSPI_MISO, SSPI_SCK); // software SPI
#endif

tls.h modification:
class timeLocationSource {
  public:
    bool active = false;

    // initialize (also enables the RTC PPS if available)
    bool init () {
      SPI.begin ();
      _Rtc.Begin ();
      if (! _Rtc.GetIsRunning ()) _Rtc.SetIsRunning (true);

      // see if the RTC is present
      if (_Rtc.GetIsRunning ()) {
        // frequency 0 (1Hz) on the SQW pin
        _Rtc.SetSquareWavePin (DS3234SquareWavePin_ModeClock);
        _Rtc.SetSquareWavePinClockFrequency (DS3234SquareWaveClock_1Hz);
        active = true;
      } else DLF ("WRN, tls.init (): DS3234 GetIsRunning () false");
#if PINMAP == MksGenL1 || PINMAP == MksGenL2 || PINMAP == MksGenL21
SPI.end ();
#endif
      return active;
    }

    // set the RTC's time (local standard time)
    void set (double JD, double LMT) {
      if (! active) return;

      int yy, y, mo, d, h;
      double m, s;
    
      greg (JD, & y, & mo, & d); yy = y; y- = 2000; if (y> = 100) y- = 100;
    
      double f1 = fabs (LMT) +0.000139;
      h = floor (f1);
      m = (f1-h) * 60.0;
      s = (m-floor (m)) * 60.0;
      
#if PINMAP == MksGenL1 || PINMAP == MksGenL2 || PINMAP == MksGenL21
SPI.begin ();
#endif
RtcDateTime updateTime = RtcDateTime (yy, mo, d, h, floor (m), floor (s));
      _Rtc.SetDateTime (updateTime);
#if PINMAP == MksGenL1 || PINMAP == MksGenL2 || PINMAP == MksGenL21
SPI.end ();
#endif
}
    
    // get the RTC's time (local standard time)
    void get (double & JD, double & LMT) {
      if (! active) return;

#if PINMAP == MksGenL1 || PINMAP == MksGenL2 || PINMAP == MksGenL21
SPI.begin ();
#endif
RtcDateTime now = _Rtc.GetDateTime ();
      if ((now.Year ()> = 2018) && (now.Year () <= 3000) && (now.Month ()> = 1) && (now.Month () <= 12) && (now.Day ()> = 1) && (now.Day () <= 31) &&
          (now.Hour ()> = 0) && (now.Hour () <= 23) && (now.Minute ()> = 0) && (now.Minute () <= 59) && (now.Second () > = 0) && (now.Second () <= 59)) {
        JD = julian (now.Year (), now.Month (), now.Day ());
        LMT = (now.Hour () + (now.Minute () / 60.0) + (now.Second () / 3600.0));
}
#if PINMAP == MksGenL1 || PINMAP == MksGenL2 || PINMAP == MksGenL21
SPI.end ();
#endif
}

    // get the location (does nothing)
    void getSite (double & LAT, double & LONG) {
    }
};

with the DS3234 each spi is terminated and restarted when the function is called. I know it's quick and dirty, but ...

thanks again everyone for the help.

Join main@onstep.groups.io to automatically receive all group messages.