-
Notifications
You must be signed in to change notification settings - Fork 7.6k
I2C and SPI not working alongside each other #912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I have SPI and I2C running perfectly in parallel on my ESP32. Different devices (TSL2561 light sensor and ILI9163 TFT display) but it runs without problems. Update |
Thank you for your suggestion. Unfortunately it did not work. i2c communications on ESP32 For now I will have to wait. In the meantime, there is no other option to order a SPI-compatible RTC (DS3234 )... |
Too bad it didn't help. Just out of interest, you defined
Default CS (SS) for VSPI is GPIO 5, but you chose GPIO 17, any specific reason for this? |
Thanks for pointing that out. I actually noticed that too just after you posted your first answer. I swapped the pins around but unfortunately it did not help. What do you mean by "putting * into a separate task"? Something with FreeRTOS? |
If you look into my code ESP32-Weatherstation check light.cpp or temperature.cpp. The functions are a wraparound of Arduino for FreeRTOS tasks. I use timer triggered tasks to read out the sensors. You could use these to access the RTC separate from the main loop.
around the functions that access the RTC. |
@Manuauto I have a fork of arduino-esp32 at stickbreaker/arduino-esp32 that is a rewrite of the I2C subsection. You might try it and see if your I2C process work correctly. @me-no-dev is reviewing my code for inclusion into this main branch. Chuck. |
@stickbreaker Thank you for the suggestion. I actually found out about this fork on another opened issue. |
@Manuauto yes, my fork is a dropin replacement for this branch. My fork only changes a few files If you copy these files over your existing arduino-esp32 installation you will be using my I2C revision. Chuck. |
@Manuauto Are you still having the issue? |
Currently I have decided not to implement a I2C RTC and instead to use a SPI RTC. Therefore I haven't tried further. |
@stickbreaker first, thanks for building the working version of arduino wire i2c for the esp32. Now, is there any hope this is going to get incorporated into the official repo? It seems to be in "pull request in review state" now for over a month. Also even with your changes, until I moved my sensor processing into a single high-priority task and put the wifi into a separate low priority task I was still getting i2c timeouts, but at least they were recoverable. |
@HollisTech the 'owner' of this repo @me-no-dev was working on merging it last month, but I haven't seen any posting or responses from him for 3+ weeks. So, don't know the what the current status is. My repo is just a step on the path toward SLAVE mode. Still working on it. I haven't done any priority testing. I have been rumination about a 'driver model' that would use a separate task that uses queues to pass commands and data from 'apps' to a higher priority control process. But, I haven't need it yet. Chuck. |
my concern is that I'm using platformio and that really doesn't seem to support alternate branches very well (maybe it does, but I can't seem to get it to work.) I'm back to using the mainline repo, and it works as long as I have all the sensor io on one very high priority thread locked to a cpu and wifi off on a separate cpu at low priority, but that is very fragile and hackish and your approach just looks more robust. Anyway, thanks. |
@HollisTech you can do a manual insert until @me-no-dev decides on how to transmorgifiy it.
Chuck |
@stickbreaker yeah I know that but that doesn't work for me as I keep everything under CI and git, so manual mucking with common components is fine for figuring out what the problem is, but not for checking stuff in and having a build server build and test the output. Anyway - thanks. I've worked around the issues, and hopefully i2c will actually get fixed one day. |
I have noticed similar issue when driving ePaper display with SPI and reading BMP180 sensor over I2C in separate / concurrent tasks in the esp-idf environment. I was getting randomly some corrupted readings from the BMP180. To quickly check if this is the issue of concurrent operation of SPI and I2C, I have added a semaphore to manage access to both resources, so only one of them may be active at any given moment of time. The corrupted I2C readings from the BMP180 were gone with this workaround. |
@stickbreaker please note that me and a bunch of people just got rid of our I2C problems on the esp32 by using the files you provided. I wonder how a product can be on the market that long with a major unfixed issue when there's a contributor like you who provides the necessary information on how to handle it. See the esp32 forum - only some of the people who found your working solution: |
The I2C core was changed to @stickbreaker code officially after 13dcfe5 (thanks @stickbreaker), Let's close issues with old code and if have problems with the new code, open new issues =) |
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);
//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!");
}
}
#define countof(a) (sizeof(a) / sizeof(a[0]))
void printDateTime(const RtcDateTime& dt)
{
char datestring[20];
}`
Debug Messages:
NOTE: The attached file contains both my full project and the smaller Debug file which does produce the same error.
The text was updated successfully, but these errors were encountered: