PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DS250x_PROM.pde 4.0KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. DS250x add-only programmable memory reader w/SKIP ROM.
  3. The DS250x is a 512/1024bit add-only PROM(you can add data but cannot change the old one) that's used mainly for device identification purposes
  4. like serial number, mfgr data, unique identifiers, etc. It uses the Maxim 1-wire bus.
  5. This sketch will use the SKIP ROM function that skips the 1-Wire search phase since we only have one device connected in the bus on digital pin 6.
  6. If more than one device is connected to the bus, it will fail.
  7. Sketch will not verify if device connected is from the DS250x family since the skip rom function effectively skips the family-id byte readout.
  8. thus it is possible to run this sketch with any Maxim OneWire device in which case the command CRC will most likely fail.
  9. Sketch will only read the first page of memory(32bits) starting from the lower address(0000h), if more than 1 device is present, then use the sketch with search functions.
  10. Remember to put a 4.7K pullup resistor between pin 6 and +Vcc
  11. To change the range or ammount of data to read, simply change the data array size, LSB/MSB addresses and for loop iterations
  12. This example code is in the public domain and is provided AS-IS.
  13. Built with Arduino 0022 and PJRC OneWire 2.0 library http://www.pjrc.com/teensy/td_libs_OneWire.html
  14. created by Guillermo Lovato <glovato@gmail.com>
  15. march/2011
  16. */
  17. #include <OneWire.h>
  18. OneWire ds(6); // OneWire bus on digital pin 6
  19. void setup() {
  20. Serial.begin (9600);
  21. }
  22. void loop() {
  23. byte i; // This is for the for loops
  24. boolean present; // device present var
  25. byte data[32]; // container for the data from device
  26. byte leemem[3] = { // array with the commands to initiate a read, DS250x devices expect 3 bytes to start a read: command,LSB&MSB adresses
  27. 0xF0 , 0x00 , 0x00 }; // 0xF0 is the Read Data command, followed by 00h 00h as starting address(the beginning, 0000h)
  28. byte ccrc; // Variable to store the command CRC
  29. byte ccrc_calc;
  30. present = ds.reset(); // OneWire bus reset, always needed to start operation on the bus, returns a 1/TRUE if there's a device present.
  31. ds.skip(); // Skip ROM search
  32. if (present == true) { // We only try to read the data if there's a device present
  33. Serial.println("DS250x device present");
  34. ds.write(leemem[0],1); // Read data command, leave ghost power on
  35. ds.write(leemem[1],1); // LSB starting address, leave ghost power on
  36. ds.write(leemem[2],1); // MSB starting address, leave ghost power on
  37. ccrc = ds.read(); // DS250x generates a CRC for the command we sent, we assign a read slot and store it's value
  38. ccrc_calc = OneWire::crc8(leemem, 3); // We calculate the CRC of the commands we sent using the library function and store it
  39. if ( ccrc_calc != ccrc) { // Then we compare it to the value the ds250x calculated, if it fails, we print debug messages and abort
  40. Serial.println("Invalid command CRC!");
  41. Serial.print("Calculated CRC:");
  42. Serial.println(ccrc_calc,HEX); // HEX makes it easier to observe and compare
  43. Serial.print("DS250x readback CRC:");
  44. Serial.println(ccrc,HEX);
  45. return; // Since CRC failed, we abort the rest of the loop and start over
  46. }
  47. Serial.println("Data is: "); // For the printout of the data
  48. for ( i = 0; i < 32; i++) { // Now it's time to read the PROM data itself, each page is 32 bytes so we need 32 read commands
  49. data[i] = ds.read(); // we store each read byte to a different position in the data array
  50. Serial.print(data[i]); // printout in ASCII
  51. Serial.print(" "); // blank space
  52. }
  53. Serial.println();
  54. delay(5000); // Delay so we don't saturate the serial output
  55. }
  56. else { // Nothing is connected in the bus
  57. Serial.println("Nothing connected");
  58. delay(3000);
  59. }
  60. }