Avatar for kervanaslan

kervanaslan

Member since Jul 2021 • Last active Jul 2021
  • 1 conversations
  • 1 comments

Most recent activity

    • 2 comments
    • 1,121 views
  • in JavaScript
    Avatar for kervanaslan

    Hello all,

    I'm working on a HBS(Home bus system) with mitsumi MM1192 chip (http://pdf.datasheetcatalog.com/datashee­t_pdf/mitsumi-electric/MM1192XD.pdf)

    I can run this chip with Serial(19200,{tx:A2,parity='even'});

    It works like Serial but there is some differences about HBS protocol.

    in serial protocol 0x80 looks like this

    1 0 0 0 0 0 0 0
    -_ _ _ _ _ _ _
    

    but in home bus it is like (Each bits frequency is 52 micro seconds)

    1    0   0   0   0   0   0   0
    -_   _-  _-  _-  _-  _-  _-  _-
    

    Thats why I have created a function to convert hex to home bus binary array.

    And I'm trying to push this data to mitsumi MM1192 with digitalWrite.

    Please don't care the hextohomebus function, may be it is wrong, i didn't test it.

    function hextohomebus(data) {
        ret = [];
        var newBinary = "";
        for (x = 0; x < data.length; x++) {
            var binary = ("0000000" + data[x].toString(2)).slice(-8);
            newBinary = newBinary + "01";
            for (i = 0; i < binary.length; i++) {
                if (binary[i] == "0") {
                    newBinary = newBinary + "01";
                }
                if (binary[i] == "1") {
                    newBinary = newBinary + "10";
                }
            }
            var oneCount= 0;
            for (g = 0; g < binary.length; g++) {
                if (binary[g] == "1") {
                    oneCount = oneCount + 1;
                }
            }
            var parityBit = "0";
            if (oneCount % 2) {
                parityBit = "10";
            } else {
                parityBit = "01";
            }
            newBinary = newBinary + parityBit + "10";
        }
        return newBinary;
    }
    
    
    function doSend(data, i) {
        digitalWrite(A2,data[i]=="0"?0:1);
    }
    
    function send(data) {
      setInterval(function(){
        i=i+1;
        doSend(data,i);
      },0.052);
    }
    
    
    setWatch(function(e) {
      console.log("Button pressed"); send(hextohomebus([0x80,0x00,0x10,0x52,0­x80,0x00,0x10,0x12,0x10,0x00,0x10,0x32,0­x30,0x00,0x20,0x62]));
    }, BTN1, { repeat: true, edge: 'rising' });
    

    But here I'm getting a memory error, probably I'm doing something wrong.

    My question is

    1- What I am doing wrong?
    2- Is there a way to ride homebus with espruino?

    Thanks

Actions