#define EXT_EE_ADDR 0x50 // I2C address of 1. external eeprom new #define EXT_EE_SIZE 32768 // Max address for 32k-eeprom #define EXT_EE_LIMIT 30 // Write buffer limit #define EXT_EE_PAGE 64 // Page size #define EXT_EE_MELODY 0 // Melody data start address in external eeprom #define EXT_EE_CALENDAR 5000 // Calendar data start address in external eeprom 02.06.2025 #define EXT_EE_TEST1 12000 // Test-data 1 start address in external eeprom ++++ 18.06.2025 10000 -> 12000 #define EXT_EE_TEST2 17000 // Test-data 2 start address in external eeprom ++++ 15000 -> 17000 #define EXT_EE_TEST3 22000 // Test-data 3 start address in external eeprom ++++ 20000 -> 22000 int receive_timer = 0; // Receive timer byte serbuf = 0; // Serial Buffer byte xon = 0; // Number of xoff while receiving byte xoff = 0; // Number of xoff while receiving static bool rx_flag = 0; // Flag for XOFF status char test_addr[3] = {'\0'}; // Buffer byte Ser_Arr[31]; // Array for page write int cur_byte = 0; // Array index unsigned int receive_addr=EXT_EE_TEST1; // Receive address byte rx_test[1000]; // DEBUG! buffer int rx_err = 0; // Receive error counter static bool rx_run; // Receive ongoing byte for_count = 0; // DEBUG! count for loop repeat int ram_idx = 0; // DEBUG! index for storing to ram void test_data_rec_(){ // External eeprom data receive - menu17 - page write unsigned int addr = receive_addr; int rx=0; // Set receive address for external eeprom byte hi, lo, val; char nibble; // High nibble, low nibble and value byte bytes; byte x; // Bytes left in page, no. of bytes processed by for-loop while ((Serial.available() >= 2) || // As long as data are available (receive_timer >0)) { // Or receive timeout is running if (!rx_run){receive_timer=399;rx_run=1;} // Set receive timeout counter (only once) ! if (receive_timer){receive_timer--;} // Decrease receive timeout counter for_count++; // How often is the for loop exectuted? x = Serial.available(); // Store total number of char received (max. 64) for (int i=0; i < x/2; i++){ // Process total number of bytes (=2 nibbles) received 2 4 6 8 byte y = Serial.available(); // Current buffer state = no of char! if (y > serbuf){serbuf=y;} // Buffer max size nibble = text2hex(Serial.read()); // read and convert 1. char = high nibble hi = nibble; // High nibble nibble = text2hex(Serial.read()); // read and convert 2. char = low nibble lo = nibble; // Low nibble val = hi<<4 | lo; // Combine hi + low = value //rx_test[ram_idx] = val; // DEBUG! store to RAM ram_idx++; // DEBUG! index for ram //flow_control(Serial.available()); // Flow-control (current buffer state) - not used! bytes=bytes_in_page(addr+cnt); // Determinate max. number allowed in this page if ((cur_byte < x/2) && // Not all data processed | -> collect data (cur_byte < bytes)){ // Below page-write border | Ser_Arr[cur_byte]= val; // Add data to page-write buffer | //debug_collect(); // DEBUG! show collecting state | cur_byte++; // Next index | } if ((cur_byte == x/2) || // current count = received bytes | -> page write (cur_byte == bytes)){ // Or page-write border reached | page_write(addr+cnt,cur_byte); // Perform page-write to ext ee | //debug_page_wr(addr); // DEBUG! show page write status | cnt=cnt+cur_byte; // Increase address by bytes added | -> prepare next packet cur_byte = 0; // Clear index | } } //debug_exit(x, addr, bytes); // DEBUG! show state at exit Menu_Timer=99; // DEBUG! give some more time //print_byt(17,3,receive_timer); // Receive timer } if(rx_run){ // DEBUG! rx executed before Serial.println(x); // DEBUG! x = bytes processed by for-loop Serial.println(serbuf); // DEBUG! max. buffer state Serial.println(for_count); // DEBUG! while repeats Serial.println(rx_err); // DEBUG! error counter Serial.println(Serial.available()); // DEBUG! no. of bytes left Serial.println(Serial.read()); // DEBUG! byte in buffer for_count=0; // Clear for loop counter rx_run=0; // Clear rx run flag ram_idx = 0; } char text2hex(char myChar){ // Convert text to hex byte y; // if (myChar >= '0' && myChar <= '9') { // 0-9 return myChar - '0';} // else if (myChar >= 'A' && myChar <= 'F') { // return myChar - 'A' + 10;} // //else {return -1;} // Fehlerfall - Ungültige Eingabe } byte bytes_in_page(unsigned int addr){ // Number of bytes left in page if (addr < EXT_EE_SIZE){ // Address is valid int page = addr / EXT_EE_PAGE; // Current page int border = (page + 1) * EXT_EE_PAGE; // Next page address = border int bytes = border - addr; // Number of bytes total int pakets = (bytes / EXT_EE_LIMIT)+1; // Number pf pakets int rest = bytes; int count = 0; // Rest of bytes if (rest >= EXT_EE_LIMIT){ // Enough space for 30 bytes count = EXT_EE_LIMIT;} // else if (rest < EXT_EE_LIMIT){ // Less space than 30 bytes count = rest;} // return count; // Number of bytes } else{ Serial.print(F("Illegal Address"));} }