Skip to content

Commit

Permalink
Ansteuerung DI und Relais
Browse files Browse the repository at this point in the history
  • Loading branch information
shining-man committed Mar 17, 2024
1 parent 156240e commit eb5ef03
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/dio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ void initDio(bool restore)

hspi = new SPIClass(HSPI);
hspi->begin(H_CLK, H_MISO, H_MOSI);
hspi->setDataMode(SPI_MODE3);
hspi->setBitOrder(MSBFIRST);
hspi->setFrequency(1000000);

dioRwInOut();

Expand All @@ -53,21 +56,24 @@ uint8_t dioRwInOut()
{
uint8_t receivedVal = 0;

//Eingänge ins Eingangsregister des HC165 laden (High-Flanke)
// PL Pin auf LOW
digitalWrite(IO_DO_PL, LOW);
delayMicroseconds(5);
digitalWrite(IO_DO_PL, HIGH);
delayMicroseconds(5);

hspi->beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE2));
receivedVal = hspi->transfer(doOutData);
hspi->endTransaction();
//Ausgaänge ins HC595 schreiben
hspi->transfer(doOutData);

//Ausgänge setzen HC595 (High-Flanke)
digitalWrite(IO_DO_PL, LOW);
delayMicroseconds(5);
// SPI Mode wechseln
hspi->setDataMode(SPI_MODE2);

// Ausgänge von HC595 übernehmen und HC165 einlesen (HIGH-Flanke)
digitalWrite(IO_DO_PL, HIGH);

// Eingänge des HC165 lesen
receivedVal = hspi->transfer(0);

// Spi Mode wieder zurück wechseln
hspi->setDataMode(SPI_MODE3);

return receivedVal;
}

Expand Down

0 comments on commit eb5ef03

Please sign in to comment.