mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
i2c reset utility
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user