Verified for CASE1

This commit is contained in:
Wesley Hofman
2025-09-17 14:53:28 +02:00
parent d1b57db444
commit 7540e5d92f

View File

@@ -1,5 +1,14 @@
#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.
// : Relay Bord 8-CH
// SENCURE SPECIFIEK
// Direct na startup is REG 0x15 = 0x00003;
// 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.
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
@@ -7,6 +16,30 @@ const uint8_t oe = 5;
const uint8_t d6 = 6; // Define pin D6
bool actionPerformed = false; // Flag to track if the action has been performed
// I2C Register Write Structure
struct I2C_Write {
uint8_t reg;
uint16_t data;
};
// Configuration Patterns
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},
{0x16, 0x0100}, {0x1F, 0x0007}, {0x53, 0x0170}
};
I2C_Write pattern2[] = {
{0x46, 0x0902}, {0x47, 0x0021}, {0x48, 0x0023}, {0x49, 0x0023}, {0x4A, 0x0023},
{0x4B, 0x0023}, {0x4C, 0x0023}, {0x4D, 0x0023}, {0x4E, 0x0023}, {0x4F, 0x005F},
{0x44, 0x0FF8}, {0x52, 0x0001}, {0x2B, 0x0001}
};
I2C_Write intermediateData[] = {
{0x55, 0x0000}, {0x56, 0x0000}, {0x57, 0x0000}, {0x58, 0x0000}, {0x59, 0x0000},
};
void relaysOn()
{
//Relays are low active
@@ -75,6 +108,49 @@ void setup() {
}
}
void sendPattern1() {
sendPattern(pattern1, sizeof(pattern1) / sizeof(pattern1[0]));
}
void sendPattern2() {
sendPattern(pattern2, sizeof(pattern2) / sizeof(pattern2[0]));
}
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);
}
}
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);
}
}
void readPattern1Data() {
readPatternData(pattern1, sizeof(pattern1) / sizeof(pattern1[0]));
}
void readPattern2Data() {
readPatternData(pattern2, sizeof(pattern2) / sizeof(pattern2[0]));
}
void readIntermediateData() {
readPatternData(intermediateData, sizeof(intermediateData) / sizeof(intermediateData[0]));
}
void printHex(uint16_t value) {
Serial.print("0x");
if (value < 0x10) {
@@ -111,17 +187,10 @@ void loop() {
// Only act if the new state is HIGH and the action hasn't been performed yet
if (currentD6State == HIGH && !actionPerformed) {
relaysOn();
uint8_t registerAddress = 0xBF;
uint16_t dataToSend = 0x0000;
// Transmit the data
transmitData(registerAddress, dataToSend); // Transmit data
sendPattern1();
// Read back data
uint16_t receivedData = readData(registerAddress); // Read back data
readPattern1Data(); // Read Data Pattern 1
relaysOff();
Serial.println("Received data : ");
// Use the method to print received data in hexadecimal format
printHex(receivedData); // Print formatted received data
Serial.println(); // New line for better readability
// Set the action performed flag to true
actionPerformed = true;
}