Picproje Elektronik Sitesi

DİJİTAL & ANALOG ELEKTRONİK => Malzeme Bilgisi => Konuyu başlatan: 94onur94 - 18 Temmuz 2018, 20:01:30

Başlık: DS2431 Hakkında Yardım
Gönderen: 94onur94 - 18 Temmuz 2018, 20:01:30
Arkadaşlar DS2431 eeprom'a data yazmaya çalışıyorum. Read ve Write Scratch bölümlerinde sorun yok. Ancak Scratch'daki 8 byte datayı hafızaya kopyalama çalıştığımda 0xFF hata kodu veriyor. Daha önceden bu eeprom ile çalışan var mı?

#include <OneWire.h>
OneWire ds(2);
byte addr[8];
byte crc[2];
byte scratch[8];
byte data[144];
int offset = 0;
int address = 0;
void setup()
{
 Serial.begin(9600);

 if (ds.search(addr))
 {
 Serial.println("\nEEPROM Bulundu");
 }
 Serial.print("ROM =");
 for (int i = 0; i < 8; i++) {
 Serial.print(' ');
 Serial.print(addr[i], HEX);
 }
 
  // Read Scratch
  Serial.print("\n\nScratch Reset = ");
  Serial.println(ds.reset());
  ds.select(addr);
  ds.write(0xAA); // read scratch pad
  Serial.println("Scratch;");
  Serial.print(" TA1: ");
  Serial.println(ds.read(), HEX);
  Serial.print(" TA1: ");
  Serial.println(ds.read(), HEX);
  Serial.print(" Read E/S: ");
  Serial.println(ds.read(), HEX);
  Serial.println(" Data;");
  for (int i = 0; i < 8; i++) {          // we need 13 bytes for scratch
    Serial.print("      ");
    scratch[i] = ds.read();
    Serial.println(scratch[i], HEX);
  }
  Serial.print("Read CRC =");
  for (int i = 0; i < 2; i++) { // we need 2 bytes for CRC
    Serial.print(" ");
    crc[i] = ds.read();
    Serial.print(crc[i], HEX);
  }
 
  // Write Scratch
 Serial.print("\n\nWrite Reset = ");
 Serial.println(ds.reset());
 ds.select(addr); // ds.write(0xCC); // skip rom
 ds.write(0x0F); // write scratch pad
 ds.write(offset); // starting adress = *8
 ds.write(address); // begin address byte 2
 //ds.write(0xA1); // data
 for(int i=0; i<8; i++)
    ds.write(i); // data
 Serial.print("Write CRC =");
 for (int i = 0; i < 2; i++) { // we need 2 bytes for CRC
 Serial.print(" ");
 crc[i] = ds.read();
 Serial.print(crc[i], HEX);
 }
  Serial.print("\nWrite Completed");
 
 // Read Scratch
 Serial.print("\n\nScratch Reset = ");
 Serial.println(ds.reset());
 ds.select(addr);
 ds.write(0xAA); // read scratch pad
 Serial.println("Scratch;");
  Serial.print(" TA1: ");
  Serial.println(ds.read(), HEX);
  Serial.print(" TA1: ");
  Serial.println(ds.read(), HEX);
  Serial.print(" Read E/S: ");
  Serial.println(ds.read());
  Serial.println(" Data;");
 for (int i = 0; i < 8; i++) { // we need 13 bytes for scratch
 Serial.print("      ");
 scratch[i] = ds.read();
 Serial.println(scratch[i], HEX);
 }
  Serial.print("Read CRC =");
  for (int i = 0; i < 2; i++) { // we need 2 bytes for CRC
    Serial.print(" ");
    crc[i] = ds.read();
    Serial.print(crc[i], HEX);
  }
 
 //Copy Scratch
 Serial.print("\n\nCopy Reset = ");
 Serial.println(ds.reset());
 ds.select(addr);
 ds.write(0x55); // Copy scratch
 ds.write(offset); // begin address byte 1
 ds.write(address); // begin address byte 2
 ds.write(0x07);
 delay(15);
 Serial.print("Status: ");
  Serial.println(ds.read(), HEX);
 /*if (ds.read() == 0xAA)
 {
 Serial.print("Success");
 }
 else
 {
 Serial.print("Error");
 }*/

 //Read Memory
 Serial.print("\nRead Reset = ");
 Serial.println(ds.reset());
 ds.select(addr);
 ds.write(0xF0); // Read memory
 ds.write(0x00); // begin address byte 1
 ds.write(0x00); // begin address byte 2
 Serial.println("Memory;");
 for (int i = 0; i < 144; i++) { // we need 144 bytes for memory
 Serial.print("      ");
 data[i] = ds.read();
 Serial.println(data[i], HEX);
 }
}

void loop()
{

}