i2c reset utility

This commit is contained in:
2023-11-09 09:48:51 +03:00
parent e3d84a1a02
commit fe054c3c4e
4 changed files with 36 additions and 8 deletions

View File

@@ -4,6 +4,7 @@
#include "Streaming.h"
#include "item.h"
#include "main.h"
#include "Wire.h"
#if defined(M5STACK)
#include <M5Stack.h>
@@ -63,8 +64,10 @@ delay(2000); */
return 1;
}
int in_hdc1080::Setup()
{
//i2cReset();
if (HDC1080ready) {debugSerial<<F("hdc1080 is already initialized")<<endl; return 0;}
debugSerial.println("HDC1080 Init ");
Wire.begin(); //Inialize I2C Harware
@@ -81,15 +84,7 @@ HDC1080ready = true;
return 1;
}
void i2cReset(){
#if defined (SCL_RESET)
Wire.endTransmission(true);
SCL_LOW();
delay(300);
SCL_HIGH();
#endif
}
int in_hdc1080::Poll(short cause)
{

View File

@@ -26,6 +26,7 @@ e-mail anklimov@gmail.com
#include "options.h"
#include "main.h"
#include "aJSON.h"
//#include "twi.h"
extern aJsonObject *owArr;
extern uint32_t timerCtr;
@@ -125,6 +126,9 @@ int owSetup() {
//// todo - move memory allocation to here
if (oneWire) return true; // Already initialized
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
//twi_setTimeoutInMicros()
i2cReset();
debugSerial<<F("DS2482_100_I2C_TO_1W_BRIDGE init")<<endl;
debugSerial<<F("Free:")<<freeRam()<<endl;
oneWire = new OneWire;

View File

@@ -876,5 +876,32 @@ bool checkToken(char * token, char * data)
return false;
}
void i2cReset(){
#if defined (SCL_RESET)
Wire.endTransmission(true);
SCL_LOW();
delay(300);
SCL_HIGH();
#endif
Wire.endTransmission(true);
Wire.end();
pinMode(SCL,OUTPUT);
pinMode(SDA,INPUT);
//10 сигналов клок
bool pulse=false;
for (int i=0; i<20;i++) {
//i2c_scl_toggle(i2c);
digitalWrite(SCL,pulse?HIGH:LOW);
pulse=!pulse;
delay(10);//10us мкс
}
Wire.begin();
}
#pragma message(VAR_NAME_VALUE(debugSerial))
#pragma message(VAR_NAME_VALUE(SERIAL_BAUD))

View File

@@ -79,3 +79,5 @@ bool getPinVal(uint8_t pin);
int str2regSize(char * str);
bool checkToken(char * token, char * data);
bool isProtectedPin(short pin);
void i2cReset();