Announcement

Collapse
No announcement yet.

Multiple keyboards

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16


    For the example given
    var datatosend[5];
    is correct
    Mark

    Comment


    • #17


      Yes sorry, was assuming you had the array already.

      And yes, it could use mem_Alloc / mem_Free if required.
      Regards,
      Dave

      Comment


      • #18


        Oh, almost - dont forget that a var array is 2 bytes per element,
        and mem_Alloc uses a byte count, so to equal

        var datatosend[5];

        you would need


        var datatosend;

        datatosend := mem_Alloc(10);
        Regards,
        Dave

        Comment


        • #19


          Then, as I am only writing 5 bytes in the buffer, I could declare:

          var datatosend[3];

          (3 elements x 2 bytes/element = 6 bytes)

          or even:

          datatosend := mem_Alloc(5);

          Is it Ok?

          Comment


          • #20


            Yes, either way is fine,
            just to note though (if you thought it might be saving some memory using mem_Alloc)
            mem_Alloc aligns to word boundary, so 6 bytes will be allocated, and there is 4 bytes used to
            'chain' the heap - so it will actually consume 10 bytes.
            Regards,
            Dave

            Comment


            • #21


              Hi,

              I have a problem with the I2C connection between the Display (master) and the micro-controller (slave).

              At the start up, I would like that the Display checks if the connection is OK, but if I try to read anything from the micro-controller and the cable is unplugged, the program hangs up. Display MCU waits for an answer from slave, but it can not come...

              I need to recover the system control, in order to show a message box explaning the error.

              What can I do?

              Thanks in advance,

              Comment


              • #22


                Hi Valen,
                Could you please post your code and the connections diagram so we could have a look at it? Please also advise the I2C device part name that you are trying to connect to the Display module.
                -Bilal

                Comment


                • #23


                  Hi, I am testing this issue without nothing connected to the Display uLCD28-PT (please, see picture), so it is vary easy to try to reproduce the problem:




                  I need to check connections before any other thing, in order to show something like this:




                  When the I2C cable is unplugged, it does not have 5 volts in SDO and SDI cables, from the pull-up resistor in the main board, and it could be the problem..... may be?

                  I am using this code:


                  in main function:
                  // Open the I2C port.
                  I2C_Open(I2C_SLOW); // 100khz


                  when we press any button:

                  // To check bus, trying to read one data from Slave.
                  func readData(var DataName)

                  // Received data: 1 byte of Header + 4 bytes of data.
                  var b[5];

                  var trash:= 0;

                  var pBuffer;
                  pBuffer := str_Ptr(b);

                  // Aux var.
                  var t := 0x00;
                  var u := 0x00;
                  var v := 0x00;

                  // Send "Read 5 bytes" command, through bus I2C.

                  I2C_Start();

                  I2C_Write(SLAVE_ADDRESS);

                  I2C_Write(DataName);

                  // Send padding with zeros, for compatibility with the system.
                  I2C_Write(0x00);

                  I2C_Write(0x00);

                  I2C_Write(0x00);

                  I2C_Write(0x00);


                  I2C_Restart();

                  I2C_Write(SLAVE_ADDRESS +WR);

                  // Start to read 5 bytes from slave.
                  trash:= I2C_Read();
                  I2C_Ack();

                  pBuffer[0] := I2C_Read();
                  I2C_Ack();

                  pBuffer[1] := I2C_Read();
                  I2C_Ack();

                  pBuffer[2] := I2C_Read();
                  I2C_Ack();

                  pBuffer[3] := I2C_Read();

                  I2C_Nack();
                  I2C_Stop();

                  // Composing of bytes [1] and [2] in one Var (the other bytes are unnecessary)
                  t := pBuffer[1];
                  u := pBuffer[2];
                  u := ByteSwap(u);

                  // return value
                  return (t|u);
                  endfunc



                  And this a very short video, showing the system, when it is working. It is in Spanish language, but images are descriptives enough:

                  Comment


                  • #24


                    It's very important that the Pullups are there at all times when using I2C.
                    Mark

                    Comment

                    Working...
                    X