Quantcast
Channel: Arduino Polska Forum - Wszystkie działy
Viewing all articles
Browse latest Browse all 256

Odczyt wejść z ekspandera PCF8574 z wykorzystaniem timera na ESP32

$
0
0
Mam problem z odczytem stanów wejść. 

Domyślnie każde niepodłączone do masy wejście ma przypisany stan wysoki także odczyty powinny być na 1.  Do pierwszego wejścia mam podpiętą masę, dla drugie nie.   Na Serial port otrzymuje taki wynik jak poniżej.   Żeby było ciekawiej jak wyjmę tą funkcję z przerwań i wywołuję z poziomu pętli głównej programu to odczyty są poprawne.   Działa mi też gdy używam biblioteki timer &tTimers.h&t  . O co tu chodzi? 


input1:0
Input2:1
Input3:1

Natomiast to co odczytuje to:
input1:0
Input2:0
Input3:1
==================  

Kod:
//Kod odczytujący stany wejść na ekspanderze wejść

hw_timer_t * timer = NULL;
int intP1 = 0;
int intP2 = 0;
int intP3 = 0;
#include "PCF8574.h"

TwoWire I2Cone = TwoWire(0);

// Set digital input i2c address
PCF8574 pcf8574_I1(&I2Cone, 0x21, 4, 5);
PCF8574 pcf8574_I2(&I2Cone, 0x22, 4, 5);
//
void IRAM_ATTR ScanKey()
{

        intP1 = pcf8574_I1.digitalRead(P0);
        intP2 = pcf8574_I1.digitalRead(P1);
        intP3 =1;

          Serial.print("input1:" );
          Serial.println(intP1);
          Serial.print("Input2:" );
          Serial.println(intP2);
          Serial.print("Input3:" );
          Serial.println(intP3);
    
}


void setup()
{
  Serial.begin(115200);
  delay(2000);

  pcf8574_I1.pinMode(P0, INPUT);
  pcf8574_I1.pinMode(P1, INPUT);

   Serial.print("Init pcf8574...");
  if (pcf8574_I1.begin()){
    Serial.println("pcf8574_I1_OK");
  }else{
    Serial.println("pcf8574_I1_error");
  }

  Serial.print("Init pcf8574...");
  if (pcf8574_I2.begin()){
    Serial.println("pcf8574_I2_OK");
  }else{
    Serial.println("pcf8574_I2_error");
  }

  timer = timerBegin(0, 80, true);
  timerAttachInterrupt(timer, &ScanKey, false);
  timerAlarmWrite(timer, 500000, true);  // interwal - wpisane 1000000 oznacza co sek. 20000 mikrosekund to 20 ms.
  timerAlarmEnable(timer);
}

void loop()
{


}

Viewing all articles
Browse latest Browse all 256

Trending Articles


TRX Antek AVT - 2310 ver 2,0


Автовишка HAULOTTE HA 16 SPX


POTANIACZ


Zrób Sam - rocznik 1985 [PDF] [PL]


Maxgear opinie


BMW E61 2.5d błąd 43E2 - klapa gasząca a DPF


Eveline ➤ Matowe pomadki Velvet Matt Lipstick 500, 506, 5007


Auta / Cars (2006) PLDUB.BRRip.480p.XviD.AC3-LTN / DUBBING PL


Peugeot 508 problem z elektroniką


AŚ Jelenia Góra