Skip to content

I2C and SPI not working alongside each other #912

Closed
@Manuauto

Description

@Manuauto

EBikeMainProject_V2_ESP32_RTCDebug.zip

Hardware:

Board: DOIT ESP32 Devkit v1
Core Installation/update date: 10. Dec. 2017
IDE name: Arduino IDE 1.8.5 / Visual Micro
Flash Frequency: 80Mhz
Upload Speed: 921600

DS3231, ILI9341
Libraries: Adafruit_GFX, Adafruit_ILI9341, RTClib or Rtc by Makuna

RTC on Pins:
22, 21
Display:
16, 17, 5, 18, 19, 23
(GPIO Pin Numbers)

Description:

I want to use an ILI9341 SPI Display and an I2C RTC Module (DS3231) in a project of mine.
These devices themselves work fine with no problems. Whenever I initialize the instance for the Display, the RTC Data seems to be corrupted or invalid.
I have tried two different RTC Libraries with no difference.

The strange thing is that I get valid time and date information from the RTC with a display running after my projects was without power for about a day. I have added pull-up resistors (4.7k) with no success. The RTC should be OK with 3.3V, I have tested it on an Arduino down to 2.3V.

Sketch:

`//Libraries
#include <Wire.h> //required for I2C
#include <RtcDS3231.h>

#include <SPI.h> //For Display
#include <Adafruit_GFX.h> //For Display
#include <Adafruit_ILI9341.h> //For Display

#define _cs 17 // goes to TFT CS
#define _dc 16 // goes to TFT DC
#define _mosi 23 // goes to TFT MOSI
#define _sclk 18 // goes to TFT SCK/CLK
#define _rst 5 // goes to TFT RESET
#define _miso 19 // Not connected

RtcDS3231 Rtc(Wire);
Adafruit_ILI9341 tft = Adafruit_ILI9341(_cs, _dc, _rst);

//////////////////////////

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

Serial.print("compiled: ");
Serial.print(__DATE__);
Serial.println(__TIME__);

Rtc.Begin();

RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
printDateTime(compiled);
Serial.println();

if (!Rtc.IsDateTimeValid()) 
{
    
    Serial.println("RTC lost confidence in the DateTime!");

    Rtc.SetDateTime(compiled);
}

if (!Rtc.GetIsRunning())
{
    Serial.println("RTC was not actively running, starting now");
    Rtc.SetIsRunning(true);
}

RtcDateTime now = Rtc.GetDateTime();
if (now < compiled) 
{
    Serial.println("RTC is older than compile time!  (Updating DateTime)");
    Rtc.SetDateTime(compiled);
}
else if (now > compiled) 
{
    Serial.println("RTC is newer than compile time. (this is expected)");
}
else if (now == compiled) 
{
    Serial.println("RTC is the same as compile time! (not expected but all is fine)");
}

// never assume the Rtc was last configured by you, so
// just clear them to your needed state
Rtc.Enable32kHzPin(false);
Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeNone);

//tft.begin(); //UNCOMMENT THIS and RTC stops working
//tft.setRotation(3);
//tft.fillScreen(BLACK);
Serial.println("Started");
}

void loop() {

if (!Rtc.IsDateTimeValid())
{
// Common Causes:
//1) the battery on the device is low or even missing and the power line was disconnected
Serial.println("RTC lost confidence in the DateTime!");
}

RtcDateTime now = Rtc.GetDateTime();
printDateTime(now);
Serial.println();

RtcTemperature temp = Rtc.GetTemperature();
Serial.print(temp.AsFloat());
Serial.println("C");

delay(1000); // ten seconds

}

#define countof(a) (sizeof(a) / sizeof(a[0]))

void printDateTime(const RtcDateTime& dt)
{
char datestring[20];

snprintf_P(datestring, 
        countof(datestring),
        PSTR("%02u/%02u/%04u %02u:%02u:%02u"),
        dt.Month(),
        dt.Day(),
        dt.Year(),
        dt.Hour(),
        dt.Minute(),
        dt.Second() );
Serial.print(datestring);

}`

Debug Messages:

Sketch uses 167906 bytes (12%) of program storage space. Maximum is 1310720 bytes.
Global variables use 11708 bytes (3%) of dynamic memory, leaving 283204 bytes for local variables. Maximum is 294912 bytes.
esptool.py v2.1
Connecting........__
Chip is ESP32D0WDQ6 (revision 1)
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 8192 bytes to 47...

Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.0 seconds (effective 10922.6 kbit/s)...
Hash of data verified.
Flash params set to 0x022f
Compressed 11120 bytes to 7467...

Writing at 0x00001000... (100 %)
Wrote 11120 bytes (7467 compressed) at 0x00001000 in 0.1 seconds (effective 977.6 kbit/s)...
Hash of data verified.
Compressed 169056 bytes to 95319...

Writing at 0x00010000... (16 %)
Writing at 0x00014000... (33 %)
Writing at 0x00018000... (50 %)
Writing at 0x0001c000... (66 %)
Writing at 0x00020000... (83 %)
Writing at 0x00024000... (100 %)
Wrote 169056 bytes (95319 compressed) at 0x00010000 in 1.4 seconds (effective 993.0 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 122...

Writing at 0x00008000... (100 %)
Wrote 3072 bytes (122 compressed) at 0x00008000 in 0.0 seconds (effective 3072.0 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting...

NOTE: The attached file contains both my full project and the smaller Debug file which does produce the same error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions