Announcement

Collapse
No announcement yet.

send data to microcontroller

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

  • send data to microcontroller

    Hello,
    I bought a 32'' LCD ( http://www.4dsystems.com.au/prod.php?id=168 a week ago and now I am trying to write my application.
    I was able to create a GUI using the ViSi Environment, but I also need to send data from the LCD to a microcontroller, using UART or I2C (I made a keypad that is stored on the LCD, and I need to send to the microcontroller the values that are written on the buttons (the captions), when a button is pressed).
    Can I do this using ViSi? Or do I have to use the Designer?
    If it's possible to send data to a uC using the ViSi environment, can you please guide me to some samples? (I know about the samples that you can access via the Designer 4 IDE, but for ViSi there is no sample for UART/I2C communication...or at least I didn't see any)

    Also, can I just paste code written in Designer to a ViSi file? Will it work?

    Thank you,
    Alex

  • #2


    Also, can I just paste code written in Designer to a ViSi file? Will it work?
    Sure, ViSi just adds a graphical level to Designer, anything you can do in designer you can do in ViSi.
    Mark

    Comment


    • #3
      It is quite simple. Define the target port and baudrate and receive buffer:

      Code:
      #constant COM_PORT          COM1
      #constant COM_BAUDRATE      11520      // baudrate/10 eg. 960 for 9600 baud/sec
      #constant COM_BUFSIZE       100
      
      var comReceiveBuffer[COM_BUFSIZE];     // circular buffer for the communication
      Initialization:


      Code:
      func comInit()
          // Setup comm
          var stat;
          stat := com_SetBaud(COM_PORT, COM_BAUDRATE);
          if (!stat)
              gfx_Cls();                    // clear the screen
              print("Wrong Baud value for COM port.");
          endif
      
          #IF (COM_PORT == COM1)
              com1_Init(comReceiveBuffer, COM_BUFSIZE*2,0);
          #ELSE
              com_Init(comReceiveBuffer, COM_BUFSIZE*2,0);
          #ENDIF
      
      endfunc
      Receive data (It is buffered by Picaso to the comReceiveBuffer, so you have time to process it):

      Code:
      func comReceive()
              var ch;
              repeat
                  #IF (COM_PORT == COM1)
                      ch := serin1();
                  #ELSE
                      ch := serin();
                  #ENDIF
                  if (ch < 0) break;
      
                  // TODO process the received byte
      
              forever
      endfunc
      Send data:
      Code:
      to(COM_PORT); print("Index =", [DEC] idx, "\n");
      Best regards,
      Mris






      Comment


      • #4


        Hi!
        I am trying to receive some data form serial port, my test code is:

        #constant COM_PORT COM0 // COM0, COM1
        #constant COM_BAUDRATE BAUD_9600 // baudrate/10 eg. 960 for 9600 baud/sec

        func comInit()
        // Setup comm
        var stat;
        stat := com_SetBaud(COM_PORT, COM_BAUDRATE);
        if (!stat)
        gfx_Cls(); // clear the screen
        print("Wrong Baud value for COM port.");
        endif
        #IF (COM_PORT == COM1)
        com1_Init(comRX, CMDRXLenMAX*20,0);
        #ELSE
        com_Init(comRX, CMDRXLenMAX*20,0);
        #ENDIF
        endfunc

        func comReceive()
        var ch;
        print("R");
        repeat
        #IF (COM_PORT == COM1)
        ch := serin1();
        #ELSE
        ch := serin();
        #ENDIF
        if (ch < 0) break;
        print("+");
        forever
        endfunc

        func main()
        comInit();
        gfx_Cls(); // clear the screen
        repeat
        comReceive();
        pause(100);
        forever
        endfunc

        In screen you can see RRRRRR..., when I send somethig with Terminal, I NEVER see a "+", so never receive a byte.

        I´m doing something wrong.... please some help...
        Thanks.

        Comment


        • #5


          Have a look at the parameter to com_SetBaud(), it is baudrate/10.

          The BAUD_9600 constant is only for setbaud().

          Using it for com_SetBaud() will result in some 'impossibly' low baud rate and what you are seeing
          Mark

          Comment


          • #6


            It works !!!!
            Thanks !

            Comment

            Working...
            X