This commit is contained in:
Wesley Hofman
2025-09-19 10:58:01 +02:00
parent 7540e5d92f
commit 469c5cd7a6

View File

@@ -1,5 +1,3 @@
#include <Wire.h>
// Programma voor het sturen van patronen benodigd voor LATCH-UP.
// I2C : LETOP Little Endian ! , I2C is normaalgesproken Big Endian
// Benodigd : OpzetBord met Logic Level Converter TXS108E.
@@ -9,6 +7,13 @@
// Wanneer 0x00001 naar REG 0xBF word gestuurd zal de chip rond de ~60uA gaan trekken (geverifieerd!).
// Na het script zal de chip rond de 1.5mA trekken.
//Duur van het script in DEBUG_MODE met serial op 115200 baud ~220ms + 20ms opstarttijd chip = 240ms ==> 300ms settling time scimitar
//Duur van het script NOT in DEBUG_MODE mode ~40ms + 20ms opstarttijd chip = 60ms ==> 100ms settling time scimitar
#include <Wire.h>
#define DEBUG_MODE // Uncomment this line to enable debug mode
const int deviceAddress = 0x68; // I2C address of the device (change as needed)
const uint8_t relay1 = 2; // LOW ACTIVE
const uint8_t relay2 = 3; // LOW ACTIVE
@@ -26,7 +31,7 @@ struct I2C_Write {
I2C_Write pattern1[] = {
{0xBF, 0x0001}, {0x00, 0x0143}, {0x01, 0x0143}, {0x02, 0x0143}, {0x03, 0x0143},
{0x04, 0x0143}, {0x05, 0x0143}, {0x06, 0x0143}, {0x07, 0x0143},
{0x11, 0x00C0}, {0x12, 0x0001}, {0x14, 0x0028}, {0x15, 0x0002},
{0x11, 0x00C0}, {0x12, 0x0001}, {0x14, 0x0028}, {0x15, 0x000D},
{0x16, 0x0100}, {0x1F, 0x0007}, {0x53, 0x0170}
};
@@ -37,7 +42,7 @@ I2C_Write pattern2[] = {
};
I2C_Write intermediateData[] = {
{0x55, 0x0000}, {0x56, 0x0000}, {0x57, 0x0000}, {0x58, 0x0000}, {0x59, 0x0000},
{0x55, 0x0000}, {0x56, 0x0000}, {0x57, 0x0000}, {0x58, 0x0000}
};
void relaysOn()
@@ -77,7 +82,9 @@ uint16_t readData(uint8_t registerAddress) {
Wire.endTransmission();
if (Wire.endTransmission() != 0) {
Serial.println("Device not found");
#ifdef DEBUG_MODE
Serial.println("Device not found");
#endif
digitalWrite(oe,LOW);
return 0; // Return 0 or some error code
}
@@ -93,7 +100,9 @@ uint16_t readData(uint8_t registerAddress) {
}
void setup() {
Serial.begin(9600);
#ifdef DEBUG_MODE
Serial.begin(115200);
#endif
Wire.begin(); // Initialize I2C
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
@@ -118,23 +127,27 @@ void sendPattern2() {
void sendPattern(const I2C_Write* pattern, size_t size) {
for (size_t i = 0; i < size; i++) {
transmitData(pattern[i].reg, pattern[i].data);
// Print the register address and data being transmitted using Serial
Serial.print("Transmitting to Register: 0x");
Serial.print(pattern[i].reg, HEX); // Print register address in hexadecimal
Serial.print(", Data: ");
printHex(pattern[i].data);
transmitData(pattern[i].reg, pattern[i].data);
#ifdef DEBUG_MODE
// Print the register address and data being transmitted using Serial
Serial.print("Transmitting to Register: 0x");
Serial.print(pattern[i].reg, HEX); // Print register address in hexadecimal
Serial.print(", Data: ");
printHex(pattern[i].data);
#endif
}
}
void readPatternData(const I2C_Write* pattern, size_t size) {
for (size_t i = 0; i < size; i++) {
uint16_t receivedData = readData(pattern[i].reg);
//Print the register address and received data
Serial.print("Reading from Register 0x");
Serial.print(pattern[i].reg, HEX);
Serial.print(": ");
printHex(receivedData);
#ifdef DEBUG_MODE
//Print the register address and received data
Serial.print("Reading from Register 0x");
Serial.print(pattern[i].reg, HEX);
Serial.print(": ");
printHex(receivedData);
#endif
}
}
@@ -164,7 +177,7 @@ void printHex(uint16_t value) {
}
unsigned long lastDebounceTime = 0; // Last time the pin state changed
unsigned long debounceDelay = 50; // Debounce delay in milliseconds
unsigned long debounceDelay = 5; // Debounce delay in milliseconds
int lastD6State = LOW; // Last stable state of D6
int currentD6State; // Current state of D6
@@ -186,10 +199,19 @@ void loop() {
// Only act if the new state is HIGH and the action hasn't been performed yet
if (currentD6State == HIGH && !actionPerformed) {
relaysOn();
// Switch Relay ON
relaysOn();
// Send Pattern 1
sendPattern1();
// Read back data
readPattern1Data(); // Read Data Pattern 1
// Read Data Pattern 1
readPattern1Data();
// Read back intermediat registers
readIntermediateData();
// Send Pattern 1
sendPattern2();
// Read Data Pattern 1
readPattern2Data();
// Switch Relay OFF
relaysOff();
// Set the action performed flag to true
actionPerformed = true;