Announcement

Collapse
No announcement yet.

Serial port communication between gen4 43d and Teensy 3.6

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

  • Serial port communication between gen4 43d and Teensy 3.6

    Hey y'all,

    I am trying to configure the serial ports on the display to read a serial write using Teensyduino. I have the TX->RX on both boards,

    Code:
    #platform "Gen4-uLCD-43D"                          
    #inherit  "ledDigitsDisplay.inc"
    
    #inherit "4DGL_16bitColours.fnc"
    
    #inherit "VisualConst.inc"
    
    #inherit "ClusterConst.inc"
    
    func main()
    
        putstr("Mounting...\n");
    
        if (!(file_Mount()))
            while(!(file_Mount()))
                putstr("Drive not mounted...");
                pause(200);
                gfx_Cls();
                pause(200);
            wend
        endif
    
        hndl := file_LoadImageControl("CLUSTE~1.dat", "CLUSTE~1.gci", 1);
        gfx_Cls();
    
        gfx_Set(SCREEN_MODE,LANDSCAPE) ;
    
        com_SetBaud(COM1, 9600);
        COM1_RX_pin(PA2);
        COM1_TX_pin(PA3);
    
        var readVariable := 0;
    
        img_Show(hndl, iLeddigits1);
        ledDigitsDisplay(LDD, iLeddigits1+1, 162, 3, 1, 54, 0) ;
    
        while (1==1)
        readVariable := serin();
        ledDigitsDisplay(readVariable, iLeddigits1+1, 162, 3, 1, 54, 0) ;
        wend
        repeat
        forever
    endfunc
    It seems to be reading values, but it keeps printing 533 to 535 regardless of what is written into the port by the Teensy, what am I doing wrong? And how would one get a successful write communication from the display to the teensy?

    Thank you for your time,
    - Aaron

  • #2
    Hi Aaron,

    The main problem is that you are using serin() instead of serin1() to read the serial port you set up. It would also be good to set up a buffered service for Com1

    Code:
    #platform "Gen4-uLCD-43D"                          
    #inherit  "ledDigitsDisplay.inc"
    
    #inherit "4DGL_16bitColours.fnc"
    
    #inherit "VisualConst.inc"
    
    #inherit "ClusterConst.inc"
    
    var combuf[10];
    var readVariable;
    
    func main()
    
        putstr("Mounting...\n");
    
        if (!(file_Mount()))
            while(!(file_Mount()))
                putstr("Drive not mounted...");
                pause(200);
                gfx_Cls();
                pause(200);
            wend
        endif
    
        hndl := file_LoadImageControl("CLUSTE~1.dat", "CLUSTE~1.gci", 1);
        gfx_Cls();
    
        gfx_Set(SCREEN_MODE,LANDSCAPE) ;
    
        com_SetBaud(COM1, 960);
        COM1_RX_pin(PA2);
        COM1_TX_pin(PA3);
        com1_Init(combuf, 10, 0);
        //var readVariable := 0;
    
        img_Show(hndl, iLeddigits1);
        //ledDigitsDisplay(LDD, iLeddigits1+1, 162, 3, 1, 54, 0) ;
    
        //while (1==1)
        //readVariable := serin();
        //ledDigitsDisplay(readVariable, iLeddigits1+1, 162, 3, 1, 54, 0) ;
        //wend
        repeat
        
        while(com1_Count() > 0)
        readVariable := serin1();
        ledDigitsDisplay(readVariable, iLeddigits1+1, 162, 3, 1, 54, 0) ;
        wend
        
        forever
    endfunc
    I hope this helps

    Best regards

    Paul

    Comment


    • #3
      I appreciate the assistance,

      The adjustment to serin1() resolved the issue where the serial readout was greater than 255, but now the read is only outputting 254 to 255. Is there anything I am missing? The teensy code should be correct, but the issue persists.

      Thanks again,
      - Aaron

      Comment


      • #4
        Hello Aaron,

        May I know what's the range of values that you're expecting to receive?

        Please ensure that your hardware connections are correct.

        Click image for larger version

Name:	pa.PNG
Views:	1
Size:	213.4 KB
ID:	66178
        would it be possible to send a photo of your set-up?

        Best regards,

        Michael

        Comment


        • #5
          The expected range of values is 0-255. I am not using a mount, just the display connected with a tape like wire connecting to a small circuit with pins in this order:
          +5V
          TX
          RX
          GND
          Reset
          I have the teensy output directly to the RX pin, but no communication is going on. The received value is almost always 255. Which I believe is really -1. I apologize for being so vague, does this clarify anything? Does there need to be any pulldown or pull-up operations for the serial data?

          Comment


          • #6
            Hello Aaron,

            Based on the Code that we're discussing I imagine your setup should look something like this:

            gen4 Display -----FPC-Cable-----> 4D-UPA/ gen4-PA

            4D-UPA/gen4-PA------------------------------------------ Teensy3.6

            GPIO1-------------------------------------------------------> Teensy RX
            GPIO2-------------------------------------------------------> Teensy TX
            GND----------------------------------------------------------> Teensy GND
            +5V-----------------------------------------------------------> Teensy +5V

            Is this correct?
            Michael

            Comment


            • #7
              Yes sir!
              The connector is the red chip in this photo:
              https://www.4dsystems.com.au/product...3D-buy-now.png

              I do not have the device with me at the moment, but It has the RX and TX pins labelled.

              Comment


              • #8
                Hello Aaron,

                It appears your connection is incorrect.

                For that code to work, you'll need to use a 4D-UPA or gen4-PA.

                Esentially your program is waiting for inputs from GPIO1 and GPIO2, since there's nothing connected to those, you're getting 255s

                Alternatively, you could try using com0 to communicate with Teensy.

                to do this, you'll need to change com_SetBaud(COM1, 9600); to com_SetBaud(COM0, 9600);

                com1_Init(combuf, 10, 0); to com_Init(combuf, 10, 0);

                readVariable := serin1(); to readVariable := serin();

                you can disregard COM1_RX_pin(PA2); and COM1_TX_pin(PA3);


                After doing so, can you please check if the values you receive are more responsive?

                I hope this helps.

                Best regards,
                Michael

                Comment


                • #9
                  Adjusted the code, it is still not communicating. I adjusted it so that after receiving a value from serin(), it would return a value through serout. The returned value was -1.

                  Comment


                  • #10
                    As it turns out, I tested both the teensy and the display. Both are sending and receiving information, but they are not communicating with each other.

                    Comment


                    • #11
                      Hello Aaron,

                      Sorry, I forgot one other thing, you should change
                      Code:
                      while(com1_Count() > 0)
                      readVariable := serin1();
                      ledDigitsDisplay(readVariable, iLeddigits1+1, 162, 3, 1, 54, 0) ;
                      wend
                      to
                      Code:
                      while(com_Count() > 0)
                      readVariable := serin();
                      ledDigitsDisplay(readVariable, iLeddigits1+1, 162, 3, 1, 54, 0) ;
                      wend
                      this would read the character count in COM0 instead of COM1.

                      Please tell me if this resolves the issue.

                      Best regards,
                      Last edited by michael_4D; 1st December 2018, 03:52 PM.
                      Michael

                      Comment

                      Working...
                      X