Announcement

Collapse
No announcement yet.

Serial ports have stopped working

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

  • Serial ports have stopped working

    At a certain point in time, the serial ports stop working, either send (serout / serout1) or receive (serin / serin1), for example:
    - On the (FORM) 1 screen, when you turn on (or turn off) LED 1, it turns on (or off) depending on the status
    - On the (FORM) 2 screen, when you turn on (or turn off) LED 2, it turns on (or off) depending on the status
    - On the (FORM) 3 screen, when you turn on (or turn off) LED 3, it turns on (or off) depending on the status

    But at a certain point, the serial does not work and I have to reset the screen before it can work again. Below, the protocols sent by the screen, through the module (ESP8266)

    0x11 0x22 0x33 0x44 0x01 0x66 (on LED 1)
    0x11 0x22 0x33 0x44 0x01 0x65 (off LED 1)
    0x11 0x22 0x33 0x44 0x02 0x66 (on LED 2)
    0x11 0x22 0x33 0x44 0x02 0x65 (off LED 2)
    0x11 0x22 0x33 0x44 0x03 0x66 (on LED 3)
    0x11 0x22 0x33 0x44 0x03 0x65 (off LED 3)


    What can it be? Attached an image, to illustrate the scenario Click image for larger version

Name:	Desenho1.jpg
Views:	1
Size:	83.8 KB
ID:	55836

  • #2
    uart speed

    Comment


    • #3
      It's at 9600:

      setbaud(BAUD_9600);
      com_SetBaud(COM1, 960);

      Comment


      • #4
        have you tried higher? what screen?

        Comment


        • #5
          Didn't try yet and model display is PICASO 32PTU

          Comment


          • #6
            try 115200

            Comment


            • #7
              I tried 115200 and it did not work, it was worse than 9600, so I put 4800 and I noticed an improvement, but the problem persists

              Comment


              • #8
                Dear Nunes,

                Could you please tell me how did you determine which of the two (4D LCD or ESP8266) stopped working?
                If you can, please send your code so I can try to determine what is the root cause? Is the Wireless network
                where the ESP8266 is connected congested? Is the WIFI signal adequate or strong enough?

                Best regards,

                Comment


                • #9
                  The comunication stop working on the screeen side, most of the time, because when i reboot the screen, starts working again.
                  i've observed some of that fails, happened when the module sends information via serial and the screen dont read it right away.
                  i'm trying to use COM1 to do it, because i'm going to use COM0 to other things in the future

                  Comment


                  • #10
                    Dear Nunes,

                    We have encountered this problem and it has something to
                    do with the Serial Port Baud rate of the ESP8266.
                    This is especially true if the ESP8266 is using the
                    latest firmware.

                    After boot, the ESP8266 defaults to a baud rate of 115200.
                    You can confirm this using a USB-Serial Bridge like the
                    uUSB-PA5 and use a Terminal program and try to send
                    AT commands. Like for example when you type AT the
                    ESP8266 must answer OK.

                    To change the baud rate of the ESP8266 to something
                    lower you can issue this command:

                    com_SetBaud(COM1, 11520); // Set up COM Port connected to ESP8266

                    to(COM1) putstr("AT+UART_DEF=19200,8,1,0,0"); //Change the baud rate of ESP8266

                    com_SetBaud(COM1, 19200); //Adjust the baud rate of the COM Port connected to ESP8266

                    Best regards,

                    Comment


                    • #11
                      This doesn't resolve our problem because we are not using the esp8266 in AT comands mode, we are program it, using arduino IDE.

                      i think is some buffer problem on the screen, the serial comunication stop working and if we hook up to as USB serial after the problem happen doesn't work either, only restarting the screen bring the serial comunication back.

                      in our program at some point we want to get information from serial, but we receive most of the time the serial stops working.

                      Comment


                      • #12
                        Dear Nunes,
                        Could you please upload your code so I can try to find out what is causing this problem?

                        Best regards,

                        Comment


                        • #13
                          Below is a part of the code, which basically represents the whole

                          var loadingIndex := 0;
                          var s1:=0;
                          var s2:=0;
                          var s3:=0;
                          var mx:=0;
                          var ti := 0;
                          var tf := 0;
                          var c2:=-1;

                          func main()

                          putstr("Mounting...\n");
                          if (!(file_Mount()))
                          while(!(file_Mount()))
                          putstr("Drive not mounted...");
                          pause(200);
                          gfx_Cls();
                          pause(200);
                          wend
                          endif

                          touch_Set(TOUCH_ENABLE);
                          setbaud(BAUD_4800);
                          com_SetBaud(COM1, 480);

                          hndl := file_LoadImageControl("inovar_2.dat", "inovar_2.gci", 1);

                          dimmer();

                          repeat
                          dimmer_input();
                          forever
                          endfunc

                          func dimmer()

                          gfx_Cls();

                          dimmer_estado();

                          img_Show(hndl,i_dimmer_0) ;

                          img_SetWord(hndl, i_count_1, IMAGE_INDEX, s2) ;
                          img_Show(hndl,i_count_1) ;

                          endfunc
                          func dimmer_input()
                          var _state;
                          var _n;

                          _state := touch_Get(TOUCH_STATUS);
                          x := touch_Get(TOUCH_GETX);
                          y := touch_Get(TOUCH_GETY);

                          if(_state == TOUCH_PRESSED)
                          if(y > 64 && y < 114)
                          if(x > 40 && x < 76) //decreases
                          d_incre_1 := 1;
                          else if(x > 167 && x < 203) //Increases
                          d_incre_1 := 2;
                          endif
                          endif
                          endif

                          if(_state == TOUCH_RELEASED) // this part, it refers precisely to when the user holds the button, it changes (increasing or decreasing)
                          d_incre_1 := 0;
                          endif

                          if(_state == TOUCH_MOVING)
                          endif

                          dimmer_inc_dec_1(0x01);

                          endfunc

                          func dimmer_inc_dec_1(var exp) //Increases and decreases the intensity of the dimmer by the +/- buttons

                          if(d_incre_1 == 1 )
                          if(ypos_1 > 0)
                          ypos_1--;
                          dimmerizacao(exp,420-(ypos_1*20));
                          img_SetWord(hndl, i_count_1, IMAGE_INDEX, ypos_1) ;
                          img_Show(hndl,i_count_1) ;
                          pause(100);
                          endif
                          else if(d_incre_1 == 2 )
                          if(ypos_1 < 20)
                          ypos_1++;
                          dimmerizacao(exp,420-(ypos_1*20));
                          img_SetWord(hndl, i_count_1, IMAGE_INDEX, ypos_1) ;
                          img_Show(hndl,i_count_1) ;
                          pause(100);
                          endif
                          endif

                          endfunc
                          /*
                          * Functions Responsible for sending dimmer commands
                          */
                          func dimmerizacao(var saida, var vol)
                          serout1(0x28);
                          serout1(0x00);
                          serout1(0x08);
                          serout1(0x01);
                          serout1(0x69);
                          serout1(saida); //Output channel
                          serout1((vol>>8)); //pegando 8 bits a esqueda (vol<<8 -> pegando 8 bits a direita. ex: vol = 0x0190 - vol>>8 = 0x01 ou vol<<8 = 0x9000
                          serout1(vol&0x00FF);
                          endfunc
                          /*
                          * Responsible functions to receive the status of the central
                          * When the function send commands (protocol) for the center, the same returns, stating which are
                          * connected and which are intensity
                          */
                          func dimmer_estado()

                          updateLoad(0);

                          serout1(0x28);
                          serout1(0x00);
                          serout1(0x05);
                          serout1(0x01); //expansão dimmer
                          serout1(0x41);

                          s1:=0;
                          s2:=0;
                          s3:=0;

                          ti := sys_T();
                          tf := ti;
                          var tg:=0;
                          tg:=tf;

                          repeat

                          c2 := serin1();
                          tf := sys_T();
                          if((tf-tg)>100)
                          tg:=tf;
                          nextLoad() ;
                          endif

                          until(c2 ==0x28 || (tf-ti)>10000);
                          if((tf - ti) < 10000 )
                          serout(c2);

                          repeat //byte 1
                          c2 := serin1();
                          until(c2 >= 0 ) ;
                          serout(c2);

                          repeat //byte 2
                          c2 := serin1();
                          until(c2 >= 0) ;
                          serout(c2);

                          repeat //byte 3
                          c2 := serin1();
                          until(c2 >= 0) ;
                          serout(c2);

                          repeat //byte 4
                          c2 := serin1();
                          until(c2 >= 0) ;
                          serout(c2);

                          repeat //byte 5
                          c2 := serin1();
                          until(c2 >= 0) ;
                          serout(c2);

                          repeat //byte 6
                          c2 := serin1();
                          until(c2 >= 0) ;
                          s1:=c2<<8;
                          serout(c2);

                          repeat //byte 7
                          c2 := serin1();
                          until(c2 >= 0) ;
                          s1:=s1+c2;
                          serout(c2);

                          repeat //byte 8
                          c2 := serin1();
                          until(c2 >= 0) ;
                          s2:=c2<<8;
                          serout(c2);

                          repeat //byte 9
                          c2 := serin1();
                          until(c2 >= 0) ;
                          s2:=s2+c2;
                          serout(c2);

                          repeat //byte 10
                          c2 := serin1();
                          until(c2 >= 0) ;
                          s3:=c2<<8;
                          serout(c2);

                          repeat //byte 11
                          c2 := serin1();
                          until(c2 >= 0) ;
                          s3:=s3+c2;
                          serout(c2);

                          repeat //byte 12
                          c2 := serin1();
                          until(c2 >= 0) ;

                          serout(c2);

                          repeat //byte 13
                          c2 := serin1();
                          until(c2 >= 0) ;

                          serout(c2);

                          s1:=(400-s1);
                          s2:=(400-s2);
                          s3:=(400-s3);

                          mx:=0;
                          repeat
                          mx:=mx+1;
                          aux_1:=mx*19;
                          until(s1<aux_1) ;
                          s1:=mx-1;

                          mx:=0;
                          repeat
                          mx:=mx+1;
                          aux_1:=mx*19;
                          until(s2<aux_1) ;
                          s2:=mx-1;

                          mx:=0;
                          repeat
                          mx:=mx+1;
                          aux_1:=mx*19;
                          until(s3<aux_1) ;
                          s3:=mx-1;

                          endif
                          endfunc
                          /*
                          * This function refers to a 'wait' screen, while the central does not return with the status, a 'wait' screen will be called
                          */
                          func updateLoad(var img)

                          if(img>11)
                          img:=0;
                          endif

                          loadingIndex:=img;

                          img_SetWord(hndl, iimgLoad, IMAGE_INDEX, img) ; //The picture changes, according to the dimmer status return
                          img_Show(hndl,iimgLoad) ;

                          endfunc

                          func nextLoad()

                          loadingIndex:=loadingIndex+1;
                          updateLoad(loadingIndex);

                          endfunc

                          Click image for larger version

Name:	Desenho2.jpg
Views:	1
Size:	57.4 KB
ID:	56082
                          Attached Files

                          Comment


                          • #14
                            Dear Nunes,

                            Please try this code. It no longer enters an infinite loop if there is no data from the serial port. It also uses a buffer to hold the serial data.


                            var loadingIndex := 0;
                            var s1:=0;
                            var s2:=0;
                            var s3:=0;
                            var mx:=0;
                            var ti := 0;
                            var tf := 0;
                            var c2:=-1;
                            var buffer[13]; // allocate buffer for serial port 1
                            var n; //serial data counter


                            func main()

                            putstr("Mounting...\n");
                            if (!(file_Mount()))
                            while(!(file_Mount()))
                            putstr("Drive not mounted...");
                            pause(200);
                            gfx_Cls();
                            pause(200);
                            wend
                            endif

                            touch_Set(TOUCH_ENABLE);
                            setbaud(BAUD_4800);
                            com_SetBaud(COM1, 480);
                            com1_Init(buffer,13, 0); // initialize serial port 1 buffer

                            hndl := file_LoadImageControl("inovar_2.dat", "inovar_2.gci", 1);

                            dimmer();

                            repeat
                            dimmer_input();
                            forever
                            endfunc

                            func dimmer()

                            gfx_Cls();

                            dimmer_estado();

                            img_Show(hndl,i_dimmer_0) ;

                            img_SetWord(hndl, i_count_1, IMAGE_INDEX, s2) ;
                            img_Show(hndl,i_count_1) ;

                            endfunc
                            func dimmer_input()
                            var _state;
                            var _n;

                            _state := touch_Get(TOUCH_STATUS);
                            x := touch_Get(TOUCH_GETX);
                            y := touch_Get(TOUCH_GETY);

                            if(_state == TOUCH_PRESSED)
                            if(y > 64 && y < 114)
                            if(x > 40 && x < 76) //decreases
                            d_incre_1 := 1;
                            else if(x > 167 && x < 203) //Increases
                            d_incre_1 := 2;
                            endif
                            endif
                            endif

                            if(_state == TOUCH_RELEASED) // this part, it refers precisely to when the user holds the button, it changes (increasing or decreasing)
                            d_incre_1 := 0;
                            endif

                            if(_state == TOUCH_MOVING)
                            endif

                            dimmer_inc_dec_1(0x01);

                            endfunc

                            func dimmer_inc_dec_1(var exp) //Increases and decreases the intensity of the dimmer by the +/- buttons

                            if(d_incre_1 == 1 )
                            if(ypos_1 > 0)
                            ypos_1--;
                            dimmerizacao(exp,420-(ypos_1*20));
                            img_SetWord(hndl, i_count_1, IMAGE_INDEX, ypos_1) ;
                            img_Show(hndl,i_count_1) ;
                            pause(100);
                            endif
                            else if(d_incre_1 == 2 )
                            if(ypos_1 < 20)
                            ypos_1++;
                            dimmerizacao(exp,420-(ypos_1*20));
                            img_SetWord(hndl, i_count_1, IMAGE_INDEX, ypos_1) ;
                            img_Show(hndl,i_count_1) ;
                            pause(100);
                            endif
                            endif

                            endfunc
                            /*
                            * Functions Responsible for sending dimmer commands
                            */
                            func dimmerizacao(var saida, var vol)
                            serout1(0x28);
                            pause(2); //takes 2 milliseconds to transmit a byte at 4800 baud
                            serout1(0x00);
                            pause(2);
                            serout1(0x08);
                            pause(2);
                            serout1(0x01);
                            pause(2);
                            serout1(0x69);
                            pause(2);
                            serout1(saida); //Output channel
                            pause(2);
                            serout1((vol>>8)); //pegando 8 bits a esqueda (vol<<8 -> pegando 8 bits a direita. ex: vol = 0x0190 - vol>>8 = 0x01 ou vol<<8 = 0x9000
                            pause(2);
                            serout1(vol&0x00FF);
                            pause(2);
                            endfunc
                            /*
                            * Responsible functions to receive the status of the central
                            * When the function send commands (protocol) for the center, the same returns, stating which are
                            * connected and which are intensity
                            */
                            func dimmer_estado()

                            updateLoad(0);

                            serout1(0x28);
                            pause(2); //takes 2 milliseconds to transmit a byte at 4800 baud
                            serout1(0x00);
                            pause(2);
                            serout1(0x05);
                            pause(2);
                            serout1(0x01); //expansão dimmer
                            pause(2);
                            serout1(0x41);
                            pause(2);

                            s1:=0;
                            s2:=0;
                            s3:=0;

                            ti := sys_T();
                            tf := ti;
                            var tg:=0;
                            tg:=tf;

                            repeat

                            c2 := serin1();
                            tf := sys_T();
                            if((tf-tg)>100)
                            tg:=tf;
                            nextLoad() ;
                            endif

                            until(c2 ==0x28 || (tf-ti)>10000);
                            if((tf - ti) < 10000 )
                            serout(c2);

                            n:=com1_Count()

                            if(n>=12) // Check if enough bytes are in the serial buffer
                            // If the bytes are in the buffer, read it

                            //byte 1
                            c2 := serin1();
                            serout(c2);
                            pause(2); //it takes 2 milliseconds to transmit a byte at 4800 baud

                            //byte 2
                            c2 := serin1();
                            serout(c2);
                            pause(2);

                            //byte 3
                            c2 := serin1();
                            serout(c2);
                            pause(2);

                            //byte 4
                            c2 := serin1();
                            serout(c2);
                            pause(2);

                            //byte 5
                            c2 := serin1();
                            serout(c2);
                            pause(2);

                            //byte 6
                            c2 := serin1();
                            serout(c2);
                            pause(2);

                            //byte 7
                            c2 := serin1();
                            s1:=s1+c2;
                            serout(c2);
                            pause(2);


                            //byte 8
                            c2 := serin1();
                            s2:=c2<<8;
                            serout(c2);
                            pause(2);


                            //byte 9
                            c2 := serin1();
                            s2:=s2+c2;
                            serout(c2);
                            pause(2);


                            //byte 10
                            c2 := serin1();
                            s3:=c2<<8;
                            serout(c2);
                            pause(2);


                            //byte 11
                            c2 := serin1();
                            s3:=s3+c2;
                            serout(c2);
                            pause(2);


                            //byte 12
                            c2 := serin1();
                            serout(c2);
                            pause(2);


                            //byte 13
                            c2 := serin1();
                            serout(c2);
                            pause(2);


                            s1:=(400-s1);
                            s2:=(400-s2);
                            s3:=(400-s3);

                            mx:=0;
                            repeat
                            mx:=mx+1;
                            aux_1:=mx*19;
                            until(s1<aux_1) ;
                            s1:=mx-1;

                            mx:=0;
                            repeat
                            mx:=mx+1;
                            aux_1:=mx*19;
                            until(s2<aux_1) ;
                            s2:=mx-1;

                            mx:=0;
                            repeat
                            mx:=mx+1;
                            aux_1:=mx*19;
                            until(s3<aux_1) ;
                            s3:=mx-1;

                            endif
                            endif
                            endfunc
                            /*
                            * This function refers to a 'wait' screen, while the central does not return with the status, a 'wait' screen will be called
                            */
                            func updateLoad(var img)

                            if(img>11)
                            img:=0;
                            endif

                            loadingIndex:=img;

                            img_SetWord(hndl, iimgLoad, IMAGE_INDEX, img) ; //The picture changes, according to the dimmer status return
                            img_Show(hndl,iimgLoad) ;

                            endfunc

                            func nextLoad()

                            loadingIndex:=loadingIndex+1;
                            updateLoad(loadingIndex);


                            Best regards,
                            Last edited by Noel; 17th February 2017, 05:12 PM.

                            Comment

                            Working...
                            X