1wire ds2401

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear all,

I want to read 64bit data on ds2401 with 1wire.

in codevision we use 1wire_init() first

after it I don't know how use 1wire_read() or 1wire_write()..

can e.b help me?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here is an Arduino library for the DS2401 device:https://github.com/sindrehal/Ard...

 

This is a complicated device.   Study the library source code and the data sheet together until it begins to become understandable.  Or use Arduino IDE instead of CodeVision, and adapt the example code.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hasanzadeh99 wrote:
in codevision  ... I don't know how use 1wire_read() or 1wire_write().

Are these functions provided by Codevision?

 

Don't they provide documentation to tell you how to use them? And examples?

 

Maxim have application notes on how to do 1-Wire.

 

https://www.maximintegrated.com/en/design/technical-documents/tutorials/1/1796.html

 

There's also an Atmel Application note:

 

AN3320 - AVR318: Dallas 1-Wire Master on tinyAVR and megaAVR

  

http://www.microchip.com/wwwappn...

 

Should be listed in the 'Documents' tab on the Product Page for your AVR chip; eg,

 

https://www.microchip.com/wwwproducts/en/ATmega32

 

 

EDIT

 

Previously, on AVRFreaks:

 

https://www.avrfreaks.net/commen...

 

https://www.avrfreaks.net/commen...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Fri. Jan 17, 2020 - 08:54 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Googling for example code,  I get this Arduino sequence:
 

  byte i;           // This is for the for loops
  boolean present;  // device present varj
  byte data[8];     // container for the data from device
  byte crc_calc;    //calculated CRC
  byte crc_byte;    //actual CRC as sent by DS2401
  //1-Wire bus reset, needed to start operation on the bus,
  //returns a 1/TRUE if presence pulse detected
  present = ds.reset();
  if (present == TRUE)
  {
    Serial.println("---------- Device present ----------");
    ds.write(0x33);  //Send Read data command
    data[0] = ds.read();
    Serial.print("Family code: 0x");
    PrintTwoDigitHex (data[0], 1);
    Serial.print("Hex ROM data: ");
    for (i = 1; i <= 6; i++)
    {
      data[i] = ds.read(); //store each byte in different position in array
      PrintTwoDigitHex (data[i], 0);
      Serial.print(" ");
    }
    Serial.println();
    crc_byte = ds.read(); //read CRC, this is the last byte
    crc_calc = OneWire::crc8(data, 7); //calculate CRC of the data
    Serial.print("Calculated CRC: 0x");
    PrintTwoDigitHex (crc_calc, 1);
    Serial.print("Actual CRC: 0x");
    PrintTwoDigitHex (crc_byte, 1);
  }
  else //Nothing is connected in the bus
  {
    Serial.println("xxxxx Nothing connected xxxxx");
  }
  delay(3000);
}

so I would just compare with the CV functions e.g.

 present = w1_search(0xf0,rom_codes);
 if (present == TRUE) {
    printf("---------- Device present ----------\n");
    w1_write(0x33);  //Send Read data command
    data[0] = w1_read();
    printf("Family code: 0x%02x\n", data[0]);
    printf("Hex ROM data: ");
    for (i = 1; i <= 6; i++)
    {
      data[i] = w1_read(); //store each byte in different position in array
      printf("0x%02x ", data[i]);
    }
    printf("\n");
    crc_byte = w1_read(); //read CRC, this is the last byte
    printf("CRC: 0x%02x\n", crc_byte);

Untested.   If you have a problem,  post your code.    (or ZIP up your CV project and attach the ZIP)

 

David.

 

Edit.   It looks as if the DS2401 is just a modern version of the DS1990.   So I suggest that you try the DS1990.prj from the CV Examples.

Last Edited: Fri. Jan 17, 2020 - 01:53 PM