Announcement

Collapse
No announcement yet.

Multiple keyboards

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

  • ESPsupport
    replied


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

    Leave a comment:


  • Valen
    replied


    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:

    Leave a comment:


  • 4dTechSupport
    replied


    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

    Leave a comment:


  • Valen
    replied


    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,

    Leave a comment:


  • meldavia
    replied


    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.

    Leave a comment:


  • Valen
    replied


    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?

    Leave a comment:


  • meldavia
    replied


    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);

    Leave a comment:


  • meldavia
    replied


    Yes sorry, was assuming you had the array already.

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

    Leave a comment:


  • ESPsupport
    replied


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

    Leave a comment:


  • Valen
    replied


    Thanks,

    and then, "datatosend" must be simply declared as

    var datatosend[5];

    or

    var datatosend:= mem_Allocz(5);

    I think is the same, excepting the necessary mem_Free(datatosend) in the last option, of course.

    Leave a comment:


  • meldavia
    replied


    I2C_Putn expects a byte array stored as a word aligned array.

    So, each array element is actually 2 bytes packed.

    Possibly easies way if you need to access as non word aligned is:-


    var p;

    p := str_Ptr(datatosend); // raise a string pointer to the buffer

    str_PutByte(p, CommandHead); // write LO byte of command
    str_PutWord(p+1, data1); // write data1 word
    str_PutWord(p+3, 0); // write zero word


    Name="Default Paragraph Font"/> iority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 1"/> xception Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 4"/> t 1 Accent 6"/>

    Leave a comment:


  • Valen
    replied


    Thanks for your answer,

    I hope my next question will be my last question, in some days:

    I am implementing a Send Commands function, in order to send command from the display to my PCB board through the I2C bus (Function is under construction...):

    // Send command to PCB board.
    func SendCommand(var CommandHead, var data1)

    // To build the command.
    datatosend[0] := LObyte(CommandHead);
    datatosend[1] := LObyte(data1);
    datatosend[2] := HIbyte(data1);
    datatosend[3] := 0;
    datatosend[4] := 0;

    // Send command by bus I2C.
    I2C_Start();
    I2C_Write(SLAVE_ADDRESS);
    I2C_Putn(datatosend , COMMAND_SIZE);
    I2C_Stop();
    endfunc

    Each command has a head (1 byte) and 4 bytes of data. Total, I have to send 5 bytes.

    but I can not find the way to define a bytes array in RAM.

    I need it to declare "datatosend" variable, as an array of bytes.

    Is there a way to do it?

    Leave a comment:


  • ESPsupport
    replied


    mem_Free(hndl) ;

    You could also open it as a file_Image(...), that would probably be slightly more efficient, although if the image wasn't at the start of the file you'd have to hardcode a file_Seek() to get to it

    Leave a comment:


  • Valen
    replied


    Hi,
    you told me: "just open, display, and close it"

    I know the way to open and display the resource:

    // Load resource from micro-SD.
    hndl := file_LoadImageControl("TESTRA~1.dat", "TESTRA~1.gci", 0);

    gfx_Cls() ;

    // Image1 1.0 generated 17/10/2012 13:55:53
    img_Show(hndl,iImage1) ;
    pause(500);

    But, what is the way to close it?

    Thanks

    Leave a comment:


  • ESPsupport
    replied


    That would still use way to much RAM.

    Why not have it in separate .GCI? and just open, display, and close it

    Leave a comment:

Working...
X