Home AMX User Forum NetLinx Studio
Options

1-wire and ds9097U

Good day!

Please, tell me how to work with 1-wire bus. I can not understand how it's done.

I need to display the temperature on the touch panel ... I have sensors Ds18S20 and Ds9097U-009#

maybe somebody has a ready code for the bus?
I would be very grateful for any help

I read the datasheet for ds9097 and ds2480b, but did not understand how to apply this data to AMX equipment.

seen on this forum on this topic... http://www.amxforums.com/showthread.php?62-iButton-code&highlight=1-wire, but did not understand how to get the data to display to user interface.

Please, HELP ME!

Comments

  • Options
    DHawthorneDHawthorne Posts: 4,584
    I replied in the original thread.
  • Options
    patriot_stvpatriot_stv Posts: 26
    Correct me if I'm wrong:

    1. To start working with 1-wire, I need to perform "master reset cycle".

    "These include making the UART generate a break signal, sending a NULL character at a data rate of 4800bps and sending any character with parity enabled and selecting space polarity for the parity bit."
    (datasheet for DS2480B)

    how to do it on the NetLinx?

    2. Switching to command mode
    send_string dvOW, $E3

    2. Send to 1-wire reset command.
    send_string dvOW, $C5 (11000101 bitwise)

    Get in return $CD ....
    According to the datasheet, it is a normal response. But it does not change when you disconnect from DS9097 all sensors. In theory, should be changed ...

    3. Switching to data mode
    send_string dvOW, $E1

    4. Send to 1-wire Read ROM command
    send_string dvOW, $33

    Then, just send eight send_string dvOW, $FF and get in return 8 0 0 2 8A 64 0 0. it must be 64-bit ROM code ))
    How to encode it into an understandable form do not know yet!
    If I do send_string dvOW, $FF more than eight times, In response I receive only "FF" .....

    While all right?

    5. Send to 1-wire CONVERT T command
    send_string dvOW, $44

    6. Send to 1-wire READ SCRATCHPAD command
    send_string dvOW, $BE

    To read data send send_string dvOW, $FF ....... but, In response I receive only "FF" ....


    what am I doing wrong?
  • Options
    I got a little work to understand how the protocol DS2480B ....
    I wrote a little program, but it is not working properly



    DEFINE_FUNCTION integer DS_Detect () {

    SEND_COMMAND dvow, 'SET BAUD 4800,N,8,1'
    SEND_STRING dvow, $0
    SEND_COMMAND dvow, 'SET BAUD 9600,N,8,1'
    WAIT 2
    SEND_STRING dvow, $C1
    wait 2
    SEND_STRING dvow, "$17, $45, $5B, $0F, $91"

    }



    DEFINE_FUNCTION integer ow_read (n) {

    local_var integer i

    for (i = 1; i<=n; i++) {

    wait 10
    send_string dvow, "$FF"

    }
    }



    DEFINE_FUNCTION integer ow_reset () {

    send_string dvow, "$e3,$c5"

    }



    DEFINE_FUNCTION integer convert_t () {

    ow_reset ()
    wait 2
    send_string dvow, "$E1,$CC,$44"

    }


    DEFINE_FUNCTION integer readSCRpad () {

    ow_reset ()
    wait 2
    send_string dvow, "$E1,$CC,$BE"


    }



    DEFINE_START

    CREATE_BUFFER dvow, ow_buffer


    DEFINE_EVENT
    data_event [dvOW] {string: {


    f_backOW = ITOHEX (GET_BUFFER_STRING(ow_buffer,50))
    OWReadData = "f_backOW,' ',OWReadData"

    SEND_COMMAND dvPult, "'^TXT-860,0,', OWReadData"

    }}


    I perform the functions assigned to the buttons. And push them consistently........

    BUTTON_EVENT [dvPult, 21] {PUSH:{ DS_Detect( ) }} ...........get in return 17

    BUTTON_EVENT [dvPult, 22] {PUSH:{ convert_t( ) }} ...........get in return CD CC

    BUTTON_EVENT [dvPult, 23] {PUSH:{ readSCRpad() }} ............ get in return CD CC

    BUTTON_EVENT [dvPult, 24] {PUSH:{ ow_read (9) }} ............. get in return only one byte. Although, I have to get 9 bytes in a row. Cycle is not working.

    What could be the problem?

    I would be grateful for your advice.
  • Options
    ericmedleyericmedley Posts: 4,177
    I'm having a hard time understanding the issue. I've never encountered a serial device that required you to change baud rates in the middle of a conversation. Not saying it's not possible. But if I had a box in front of me that required this I'd probably put an ice pick through it repeatedly.

    Another thing is if you need to send a string with multiple $FFs then jus do it in one command.

    Send_string MySerialPort, "$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF"

    I'm guessing you may not have taken the programming class.

    You might want to post the protocol document.
  • Options
    I tried to send differend commands:
    ... And send_string rs232, "$ff, $ff......$ff"
    ...and {send_string rs232, $ff
    Wait 5
    Send_string rs232, $ff
    Wait 5
    .......n times}

    get in return or one (first byte) or nothing


    But, if I write Button_event [dvPult, 23] {push : { send_string rs232, $ff}} and push this button 9 times, I get in return 9 byte. (one by one on each press)


    Protocol http://pdf.datasheetcatalog.com/datasheet/maxim/DS2480B.pdf
  • Options
    The artificial break (switching to 4800 and sending a 0 then back to 9600) only needs to be done once when the adapter is first connected. Once you have done that you send it a $C1, you should get back a $CD, $CE, or $CF depending on the alarm condition of the buss. Then send it a reset:

    SEND_STRING TEMPERATURE_NET,"$E3,$C5" (* COMMAND MODE,RESET BUSS *)


    Then send it the convert command, this will trigger all the devices on the buss to do a temperature conversion:

    SEND_STRING TEMPERATURE_NET,"$E1,$CC,$44" (*DATA MODE,SKIP ROM,CONVERT T*)

    wait 200ms then send another reset command then you can read the individual devices by reading their scratchpads


    Here is the read scratchpads string:


    ROM_DATABASE[1] = "$10,$71,$18,$01,$01,$08,$00,$44"

    // this is the serial number of your device

    SEND_STRING TEMPERATURE_NET,"$E1,$55,ROM_DATABASE[1],$BE,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF" (*READ SCRATCHPAD*)

    make sure that the serial number is in that order. It seems to me the documentation has them in reverse order The $10 is the device type (For a temp sensor) and that needs to be first. (this one threw me for a while) after that send another onewire reset and read the next sensor or if you only have one send another convert command. I had 20 sensors on my network, I would send a convert command then read all 20 individually then start it all over. I could get readings every 15 seconds or so.

    once you get the data back from the sensor you need to parse it out to get the actual temprature. This works for me. It is little strange, because it was originally written for an axcent 3 (no Floats!!) and I dont remember how I came up with it (its been 10 years) but the math works. This gives you Temperature in Fahrenheit. The precision is .9 Fahrenheit ( .5 degree Celsius)

    RAW_SIGN = (MID_STRING (TEMPERATURE_NET_BUFFER,2,1))
    RAW_TEMP = (MID_STRING (TEMPERATURE_NET_BUFFER,1,1))
    IF (RAW_SIGN = $FF)
    {
    TMP = (((RAW_TEMP[1] * 18)/2)-1984)
    }
    IF (RAW_SIGN = $00)
    {
    TMP =(((RAW_TEMP[1] * 18)/2)+320)
    }
    Temprture = (TMP / 10)


    There you have the basics you can come up with the rest of the 1900 lines it took to control the furnace.

    I fired mine up again last week for the fun of it and it still works.
    Good Luck...Jim...
  • Options
    Jim Johnson, thank you very much for the detailed description.

    I had already figured out how to send commands.
    I was wondering how to take a response from the device. I sent the command, but each time received only one byte in response or nothing. Today I have everything worked out! ))) I am, as always, did not consider trifles to get the result.
    Did so, and it worked:

    data_event [dvOW] {string: {

    stack_var integer i
    stack_var integer n
    stack_var char OwReadBuf [50]

    OwReadBuf =0

    f_backOW = data.text
    n = length_array (f_backOW)

    for (i=n; i>=1; i--) {
    OwReadBuf = "ITOHEX (f_backOW), ' ',OwReadBuf"
    }

    SEND_COMMAND dvPult, "'^TXT-860,0,', OwReadBuf"

    }}



    Now I do not understand how to write code to search for devices on the bus.
    If you share your experience in this matter and tell me how to do it, I will be very grateful.
  • Options
    I didn't get into searching for devices on the network. My network was pretty static so it was unnecessary. Maxium used to have some programs written in C++ that I used to figure out what I did. They probably have code for the search functions as well. It usually can be translated pretty easily, but like I said I haven't gone down that road.
    ...Jim...
  • Options
    how you made the algorithm updates the temperature? (i mean netlinx code)
Sign In or Register to comment.