ds2430 как записать данные в память
- Войдите на сайт для отправки комментариев
Ср, 20/03/2019 - 18:43
Здравствуйте всем! Не могу записать данные в память ds2430. Пользую этот код программы ,читает все хорошо , а записывать не записывает.
#include <DS2431.h>
#include <OneWire.h>
const int ONE_WIRE_PIN = 10; // One Wire pin, change according to your needs. A 4.7k pull up resistor is needed.
OneWire oneWire(ONE_WIRE_PIN);
DS2431 eeprom(oneWire);
void setup()
{
Serial.begin(115200);
while (!Serial); // wait for Serial to come up on USB boards
// Search the 1-Wire bus for a connected device.
byte serialNb[8];
oneWire.target_search(DS2431::ONE_WIRE_FAMILY_CODE);
if (!oneWire.search(serialNb))
{
Serial.println("No DS2431 found on the 1-Wire bus.");
return;
}
// Check serial number CRC
if (oneWire.crc8(serialNb, 7) != serialNb[7])
{
Serial.println("A DS2431 was found but the serial number CRC is invalid.");
return;
}
Serial.print("DS2431 found with serial number : ");
printBuffer(serialNb, 8);
Serial.println("");
// Initialize DS2431 object
eeprom.begin(serialNb);
// Read all memory content
byte data[16];
eeprom.read(0, data, sizeof(data));
Serial.println("Memory contents : ");
printLargeBuffer(data, sizeof(data));
Serial.println("");
// Write a 8-byte row
byte newData[8] = {1,2,3,4,5,6,7,8};
word address = 1;
if (eeprom.write(address, newData, sizeof(newData)))
{
Serial.print("Successfully wrote new data @ address ");
Serial.println(address);
}
else
{
Serial.print("Failed to write data @ address ");
Serial.println(address);
}
Serial.println("");
// Read again memory content
eeprom.read(0, data, sizeof(data));
Serial.println("Memory contents : ");
printLargeBuffer(data, sizeof(data));
Serial.println("");
// Read single byte
Serial.print("Data @ address ");
Serial.print(address);
Serial.print(" : ");
Serial.println(eeprom.read(address));
}
void loop()
{
// Nothing to do
}
void printBuffer(const uint8_t *buf, uint8_t len)
{
for (int i = 0; i < len-1; i++)
{
Serial.print(buf[i], HEX);
Serial.print(",");
}
Serial.println(buf[len-1], HEX);
}
void printLargeBuffer(const uint8_t *buf, uint16_t len)
{
uint8_t bytesPerLine = 8;
for (int i = 0; i < len / bytesPerLine; i++)
{
Serial.print(i * bytesPerLine);
Serial.print("\t\t:");
printBuffer(buf + i * bytesPerLine, bytesPerLine);
}
}
В даполнение выдает такие данные
No DS2431 found on the 1-Wire bus.
1. Изучите вот эту тему
2. перепостите заново (в этой же теме, новым постом)
Здравствуйте всем! Не могу записать данные в память ds2430. Пользую этот код программы ,читает все хорошо , а записывать не записывает.
#include <DS2431.h> #include <OneWire.h> const int ONE_WIRE_PIN = 10; // One Wire pin, change according to your needs. A 4.7k pull up resistor is needed. OneWire oneWire(ONE_WIRE_PIN); DS2431 eeprom(oneWire); void setup() { Serial.begin(115200); while (!Serial); // wait for Serial to come up on USB boards // Search the 1-Wire bus for a connected device. byte serialNb[8]; oneWire.target_search(DS2431::ONE_WIRE_FAMILY_CODE); if (!oneWire.search(serialNb)) { Serial.println("No DS2431 found on the 1-Wire bus."); return; } // Check serial number CRC if (oneWire.crc8(serialNb, 7) != serialNb[7]) { Serial.println("A DS2431 was found but the serial number CRC is invalid."); return; } Serial.print("DS2431 found with serial number : "); printBuffer(serialNb, 8); Serial.println(""); // Initialize DS2431 object eeprom.begin(serialNb); // Read all memory content byte data[16]; eeprom.read(0, data, sizeof(data)); Serial.println("Memory contents : "); printLargeBuffer(data, sizeof(data)); Serial.println(""); // Write a 8-byte row byte newData[8] = {1,2,3,4,5,6,7,8}; word address = 1; if (eeprom.write(address, newData, sizeof(newData))) { Serial.print("Successfully wrote new data @ address "); Serial.println(address); } else { Serial.print("Failed to write data @ address "); Serial.println(address); } Serial.println(""); // Read again memory content eeprom.read(0, data, sizeof(data)); Serial.println("Memory contents : "); printLargeBuffer(data, sizeof(data)); Serial.println(""); // Read single byte Serial.print("Data @ address "); Serial.print(address); Serial.print(" : "); Serial.println(eeprom.read(address)); } void loop() { // Nothing to do } void printBuffer(const uint8_t *buf, uint8_t len) { for (int i = 0; i < len-1; i++) { Serial.print(buf[i], HEX); Serial.print(","); } Serial.println(buf[len-1], HEX); } void printLargeBuffer(const uint8_t *buf, uint16_t len) { uint8_t bytesPerLine = 8; for (int i = 0; i < len / bytesPerLine; i++) { Serial.print(i * bytesPerLine); Serial.print("\t\t:"); printBuffer(buf + i * bytesPerLine, bytesPerLine); } }В даполнение выдает такие данные
No DS2431 found on the 1-Wire bus.
Да ответов и советов куча ! У меня все получилось . Пишите кому интересно.
Мне не интересно про 2431. Интересно другое, если в вашем софте использовать более ОДНОЙ 2431 - софт будет работать?
Нет я думаю!
Нет я думаю!
а если несколько DS2431 подключить на разные пины и создать несколько экземпляров класса DS2431 и OneWire. Будет работать?
Приветствую! Мне интересно. Судя по всему разная организация памяти. Что получилось?
Мне очень интересно. К сожалению я не большой специалист в этих вопросах, но есть насущная необходимость записать информацию на эту микросхему.
Дико извиняюсь за оффтоп, но может мне кто-нибудь из участников темы объяснить физический или экономический смысл применения 1Wire EEPROM и ее преимущества перед i2c EEPROM типа AT24хххх ?
На тиньке 1 пин занимает
Есть интерес по данному вопросу.
Напишите пожалуйста как у вас получилось записать данные?
Здесь скорее интересно, для каких задач могут понадобится 32 байта памяти с доступом через протокол?
кому нужна память ddr2?
#include <OneWire.h> OneWire ds(10); byte addr[8]; void setup(void) { Serial.begin(9600); } void loop(void) { ReadAllMem(); while(1); } void ReadAllMem() //функция чтения памяти { ds.reset(); ds.write(0xCC);//пропуск rom ds.write(0x0F,1); // запись блокнотной памяти ds.write(0x00,1);//начальный адрес с которого начинается запись в блокнот // ds.write(0x00,1); ds.write(0x8B,1); ds.write(0xCB,1); ds.write(0xF4,1); ds.write(0x90,1); ds.write(0xBB,1); ds.write(0xB8,1); ds.write(0x50,1); ds.write(0x13,1); ds.write(0x76,1); ds.write(0x8C,1); ds.write(0x33,1); ds.write(0x7,1); ds.write(0x72,1); ds.write(0xC5,1); ds.write(0xC4,1); ds.write(0x89,1); ds.write(0x8B,1); ds.write(0xCB,1); ds.write(0xF4,1); ds.write(0x90,1); ds.write(0xBB,1); ds.write(0xB8,1); ds.write(0x50,1); ds.write(0x13,1); ds.write(0x76,1); ds.write(0x8C,1); ds.write(0x33,1); ds.write(0x7,1); ds.write(0x72,1); ds.write(0xC5,1); ds.write(0xC4,1); ds.write(0x89,1); ds.reset(); ds.write(0xCC); //пропуск rom ds.write(0xAA); //чтение блокнотной памяти ds.write(0x00); // начальный адрес для чтения ds.read(); //delay(2); ds.reset(); ds.write(0xCC); //пропуск rom ds.write(0x55); // копирование блокнота в ЭСППЗУ ds.write(0xA5); //ключ достоверности delay(10); // пауза 10mc ds.reset(); ds.write(0xCC); // чтение всей памяти ЭСППЗУ ds.write(0xF0); ds.write(0x00); ds.read(); ds.reset(); ds.write(0xCC); ds.write(0x66); // чтение состояния прикладного регистра ds.write(0x00F); // ключ достоверности ds.read(); ds.reset(); ds.write(0xC3); ds.write(0x00); ds.write(0xAA); ds.read(); }[quote=star1k]
Напишите пожалуйста как у вас получилось записать данные
В сети есть документация на эту микросхему или более новую там все четко указано как записать.
Файлы в сети не работают с ардуиной на запись скорость код сЪедает тайминги не совпадают.
кому нужна память ddr2?
объём?
кому нужна память ddr2?
объём?
см. пост №14