Announcement

Collapse
No announcement yet.

Changing baud rate using an Arduino Mega 2560 connected to a gen4-uLCD-32DT

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

  • Changing baud rate using an Arduino Mega 2560 connected to a gen4-uLCD-32DT

    Hello ,

    I am working on a project which was originally only an internship project, and which has become very important for a critical application.
    It includes a 4D Systems screen reference "gen4-uLCD-32DT", controlled by an Arduino Mega 2560, which communicate in UART at 9600 Bauds on the Serial 3 port of the Arduino.
    I’m using Diablo_Serial_4Dlib.

    This weak Baudrate causes delays that I am really forced to reduce. A baudrate at 115,200 Bauds would be great.
    But I have never managed to increase this, despite forum research and testing.

    I am enclosing the program below only intended to test an increase in baudrate.

    Result:
    I have the display "9600 Bauds OK"
    Monitor displays : Serial 4D Library reports error NAK returned data = 249
    The LED flashes to indicate the error.
    I don't know what the 249 answer is (= 0xF9).

    Any help would be welcome.

    Olivier





    //*********************************************************************
    // Test increase baudrate (doesn't work)
    // Arduino MEGA 2560 + 4D Systems gen4-uLCD-32DT (UART on Serial3)
    //*********************************************************************

    // Monitor : Serial 4D Library reports error NAK returned data = 249 (= 0xF9)


    #define DisplaySerial Serial3
    #define ResetLCD A3
    #define led 13

    #include <Diablo_Const4D.h>
    #include <Diablo_Serial_4DLib.h>
    Diablo_Serial_4DLib Display(&DisplaySerial) ;

    void setup( ) {

    pinMode( ResetLCD , OUTPUT ) ;
    pinMode( led , OUTPUT ) ;

    Serial.begin ( 115200 ) ; // Monitor
    DisplaySerial.begin ( 9600 ) ; // LCD default baudrate
    Display.Callback4D = mycallback ;
    Display.TimeLimit4D = 5000 ;

    // Reset LCD
    digitalWrite ( ResetLCD , 0 ) ;
    delay( 100 ) ;
    digitalWrite ( ResetLCD , 1 ) ;
    delay ( 5000 ) ;

    Display.gfx_ScreenMode ( LANDSCAPE ) ;
    Display.gfx_BGcolour ( BLUE ) ;
    Display.gfx_Cls() ;
    Display.txt_BGcolour ( RED ) ;
    Display.txt_FGcolour ( BLACK ) ;
    Display.txt_Height ( 2 ) ;
    Display.txt_Width ( 2 ) ;

    // Display 9600 baud OK
    Display.gfx_MoveTo ( 10 , 100 ) ;
    Display.print ( " 9600 Bauds OK" ) ;
    delay ( 5000 ) ;

    // Increase baudrate (doesn't work)
    Display.setbaudWait( BAUD_19200 ) ;
    DisplaySerial.begin( 19200 ) ;
    delay( 3000 ) ;

    // Display 19200 baud OK (doesn't work)
    Display.gfx_MoveTo ( 100 , 10 ) ;
    Display.print ( "19200 Bauds OK" ) ;
    }


    void loop ( ) {
    }

    void mycallback( int ErrCode, unsigned char Errorbyte ) {
    const char *Error4DText[] = { "OK\0", "Timeout\0", "NAK\0", "Length\0", "Invalid\0" } ;
    Serial.print( F ( "Serial 4D Library reports error " ) ) ;
    Serial.print( Error4DText[ ErrCode ] ) ;
    if ( ErrCode == Err4D_NAK ) {
    Serial.print( F ( " returned data = " ) ) ;
    Serial.println( Errorbyte ) ;
    }
    // Led blinking
    while ( 1 ) {
    digitalWrite( led, HIGH) ;
    delay( 200 ) ;
    digitalWrite( led, LOW) ;
    delay( 200 ) ;
    }
    }

  • #2
    Hello,

    Welcome to the forum. Apologies for the delayed reply.

    Kindly check this appnote for your reference:
    AN-00092 Serial Connection to an Arduino Host
    https://4dsystems.com.au/blog/4d-an-00092/

    You can change the baud rate in WS4 IDE, File > Options > Serial. You will have to create a new Serial Environment project, then reload the SPE Application:

    Click image for larger version  Name:	SPE load.JPG Views:	0 Size:	22.7 KB ID:	72117

    BR,
    Sherwin
    Last edited by sherwin4D; 25 May 2020, 11:56 AM.

    Comment


    • #3
      Hello, Thank you for your answer, but the application is already developed using the "Diablo_Serial_4DLib" library, with the help of the "BigDemo" examples. It is quite substantial, I had only posted a piece of code targeted at changing the baud rate, in order to facilitate the resolution of the problem.

      To describe you quickly, this project is a redundant control drawer, which has two Arduino boards which communicate with each other.
      In my work team, we tried to test the redundancy with every conceivable failure case.
      It is currently the subject of a dependability study conducted by an authority X, and for the aeronautical use of a large group Y.
      (If this project would have to be redone, it goes without saying that the Arduino is not ideal for this.) X sift through the code and Y make additional tests on their side. It turns out that a delay is too long in one case, due to the baud rate of 9600 Bds on the screen which delays one of the two cards.
      At this stage of testing, it is very annoying to have to modify the code, it is not possible to redevelop everything under another IDE such as Workshop 4.
      I continued my attempts to change the baud rate, with the SetbaudWait function which exists in "Diablo_Serial_4DLib", and in the document DIABLO16_serialcmdmanual_R_2_0.

      I am enclosing a Big Demo modeled test program, I renamed "SetBaudWait" and "SetThisBaudRate" by "MySetBaudWait" and "MySetThisBaudRate" so as not to interfere with the library.
      According to this test program: the display seems working until 31250 Bds (i = 9). A problem occurs at the moment of setting baud rate to 38400 Bds (i = 10)? By changing the program code a little, 38400 Bds can work.
      I did other test programs, I happened to reach 256000 Bauds, with sometimes no error reported, and on another program untimely errors.
      It’s very strange, as if the screen was on the verge of functioning. I cannot define the limit for the proper functioning of the screen, it is so changeable.

      I could see in another discussion that changing the baud rate works perfectly on a Picasso screen model with the Picasso library. Are there any known baud rate change issues with diablo16?
      Could it be due to clock inaccuracy?
      I'm going to have a meeting with X and Y soon, I don’t how to say that, in French we says : I’m in beautiful sheet.
      help would be welcome.


      (I don't know if my way of posting the code here is correct.)



      //*********************************************************************
      // Test increase baudrate (doesn't work)
      // Arduino MEGA 2560 + 4D Systems gen4-uLCD-32DT (UART on Serial3)
      //*********************************************************************

      /*
      RESULT ON MONITOR :

      Serial 4D Library reports error Timeout
      i = 10 num = 0
      Serial 4D Library reports error Timeout
      i = 10 num = 1
      Serial 4D Library reports error Timeout
      i = 10 num = 2
      Serial 4D Library reports error Timeout
      i = 10 num = 3
      ...
      ...
      ...
      According to this test program : the display seems working until 31250 Bds ( i = 9 ).
      A problem occurs at the moment of setting baud rate to 38400 Bds( i = 10 ) ?
      */

      #define DisplaySerial Serial3
      #define ResetLCD A3
      #define led 13

      #include <Diablo_Const4D.h>
      #include <Diablo_Serial_4DLib.h>
      Diablo_Serial_4DLib Display(&DisplaySerial) ;


      int num, i ;

      void setup( ) {
      Display.Callback4D = mycallback ;
      Display.TimeLimit4D = 5000 ;
      pinMode( ResetLCD , OUTPUT ) ;
      pinMode( led , OUTPUT ) ;
      Serial.begin ( 115200 ) ; // Monitor
      DisplaySerial.begin ( 9600 ) ; // LCD default baud rate

      // Reset LCD
      digitalWrite ( ResetLCD , 0 ) ;
      delay( 100 ) ;
      digitalWrite ( ResetLCD , 1 ) ;
      delay ( 5000 ) ;


      // Test loop 9600 Bds until 600000 Bds
      for ( i = 6 ; i < 20 ; i++ ) {
      num = 0 ; // Benchmark to target the error
      MySetBaudWait( i ) ;
      num = 1 ; // Benchmark to target the error
      LotOfTest ( ) ;
      Display.print ( "Bauds rate n " ) ;
      Display.println ( i ) ;
      delay( 2000 ) ;
      }
      /*
      i = 6 <-> 9600 Bds
      i = 7 <-> 14400 Bds
      i = 8 <-> 19200 Bds
      i = 9 <-> 31250 Bds
      i = 10 <-> 38400 Bds
      i = 11 <-> 56000 Bds
      i = 12 <-> 57600 Bds
      i = 13 <-> 115200 Bds
      i = 14 <-> 128000 Bds
      i = 15 <-> 256000 Bds
      i = 16 <-> 300000 Bds
      i = 17 <-> 375000 Bds
      i = 18 <-> 500000 Bds
      i = 19 <-> 600000 Bds
      */
      }

      void loop ( ) {
      }

      void MySetBaudWait( word Newrate )
      {
      DisplaySerial.print( ( char ) ( F_setbaudWait >> 8 ) ) ;
      DisplaySerial.print( ( char ) ( F_setbaudWait ) ) ;
      DisplaySerial.print( ( char ) ( Newrate >> 8 ) ) ;
      DisplaySerial.print( ( char ) ( Newrate ) ) ;
      MySetThisBaudRate( Newrate ) ; // change this systems baud rate to match new display rate, ACK is 100ms away
      Display.GetAck( ) ;
      }

      void MySetThisBaudRate( int Newrate )
      {
      int br ;
      DisplaySerial.flush( ) ;
      DisplaySerial.end( ) ;
      switch ( Newrate )
      {
      case BAUD_9600 : br = 9600 ; // 6
      break ;
      case BAUD_14400 : br = 14400 ; // 7
      break ;
      case BAUD_19200 : br = 19200 ; // 8
      break ;
      case BAUD_31250 : br = 31250 ; // 9
      break ;
      case BAUD_38400 : br = 38400 ; // 10
      break ;
      case BAUD_56000 : br = 56000 ; // 11
      break ;
      case BAUD_57600 : br = 57600 ; // 12
      break ;
      case BAUD_115200 : br = 115200 ; // 13
      break ;
      case BAUD_128000 : br = 133928 ; // actual rate is not 128000
      break ;
      case BAUD_256000 : br = 281250 ; // actual rate is not 256000
      break ;
      case BAUD_300000 : br = 312500 ; // actual rate is not 300000
      break ;
      case BAUD_375000 : br = 401785 ; // actual rate is not 375000
      break ;
      case BAUD_500000 : br = 562500 ; // actual rate is not 500000
      break ;
      case BAUD_600000 : br = 703125 ; // actual rate is not 600000
      break ;
      }
      DisplaySerial.begin( br ) ;
      delay( 50 ) ; // Display sleeps for 100 ms
      DisplaySerial.flush( ) ;
      }


      void LotOfTest ( void ) {
      Display.gfx_ScreenMode ( LANDSCAPE ) ; num = 2 ;
      Display.gfx_BGcolour ( BLUE ) ; num = 3 ;
      Display.gfx_Cls( ) ; num = 4 ;
      Display.txt_BGcolour ( GREEN ) ; num = 5 ;
      Display.txt_FGcolour ( BLACK ) ; num = 6 ;
      Display.txt_Height ( 2 ) ; num = 7 ;
      Display.txt_Width ( 2 ) ; num = 8 ;
      Display.gfx_MoveTo ( 10 , 20 ) ; num = 9 ;
      Display.gfx_RectangleFilled ( 16, 60, 152, 105, GRAY ) ; num = 10 ;
      Display.gfx_Rectangle ( 16, 60, 152, 105, BLACK ) ; num = 11 ;
      Display.gfx_RectangleFilled ( 168, 60, 304, 105, GRAY ) ; num = 12 ;
      Display.gfx_Rectangle ( 168, 60, 304, 105, BLACK ) ; num = 13 ;
      Display.gfx_RectangleFilled ( 16, 120, 152, 165, GRAY ) ; num = 14 ;
      Display.gfx_Rectangle ( 16, 120, 152, 165, BLACK ) ; num = 15 ;
      Display.gfx_RectangleFilled ( 168, 120, 304, 165, GRAY ) ; num = 16 ;
      Display.gfx_Rectangle ( 168, 120, 304, 165, BLACK ) ; num = 17 ;
      Display.gfx_RectangleFilled ( 16, 180, 152, 225, GRAY ) ; num = 18 ;
      Display.gfx_Rectangle ( 16, 180, 152, 225, BLACK ) ; num = 19 ;
      Display.gfx_RectangleFilled ( 168, 180, 304, 225, GRAY ) ; num = 20 ;
      Display.gfx_Rectangle ( 168, 180, 304, 225, BLACK ) ; num = 21 ;
      Display.touch_Set ( TOUCH_ENABLE ) ; num = 22 ;
      }


      void mycallback( int ErrCode, unsigned char Errorbyte ) {

      const char *Error4DText[] = { "OK\0", "Timeout\0", "NAK\0", "Length\0", "Invalid\0" } ;
      Serial.print( F ( "Serial 4D Library reports error " ) ) ;
      Serial.print( Error4DText[ ErrCode ] ) ;
      if ( ErrCode == Err4D_NAK ) {
      Serial.print( F ( " returned data = " ) ) ;
      Serial.println( Errorbyte ) ;
      }
      Serial.println ( F ( "" ) ) ;
      Serial.print ( "i = " ) ;
      Serial.print ( i ) ;
      Serial.print ( F ( " num = " ) ) ;
      Serial.println ( num ) ;
      }


      Click image for larger version

Name:	20200529_125710.jpg
Views:	63
Size:	1.58 MB
ID:	72156

      Thanks for reading

      Comment


      • #4
        Hello,
        I found what is wrong with the code, an error from BigDemo supplied with Diablo_Serial_4DLib.

        This is a problem with the size of the number "br", here is the extract from BigDemo from line 848:

        int br ;
        DisplaySerial.flush() ;
        DisplaySerial.end() ;
        switch(Newrate)
        {
        case BAUD_110 : br = 110 ;
        break ;
        case BAUD_300 : br = 300 ;
        break ;
        case BAUD_600 : br = 600 ;
        break ;
        case BAUD_1200 : br = 1200 ;
        break ;
        case BAUD_2400 : br = 2400 ;
        break ;
        case BAUD_4800 : br = 4800 ;
        break ;
        case BAUD_9600 : br = 9600 ;
        break ;
        case BAUD_14400 : br = 14400 ;
        break ;
        case BAUD_19200 : br = 19200 ;
        break ;
        case BAUD_31250 : br = 31250 ;
        break ;
        case BAUD_38400 : br = 38400 ;
        break ;
        case BAUD_56000 : br = 56000 ;
        break ;
        case BAUD_57600 : br = 57600 ;
        break ;
        case BAUD_115200 : br = 115200 ;
        break ;
        case BAUD_128000 : br = 133928 ; // actual rate is not 128000 ;
        break ;
        case BAUD_256000 : br = 281250 ; // actual rate is not 256000 ;
        break ;
        case BAUD_300000 : br = 312500 ; // actual rate is not 300000 ;
        break ;
        case BAUD_375000 : br = 401785 ; // actual rate is not 375000 ;
        break ;
        case BAUD_500000 : br = 562500 ; // actual rate is not 500000 ;
        break ;
        case BAUD_600000 : br = 703125 ; // actual rate is not 600000 ;
        break ;
        }

        "Br" cannot exceed +32767, that's why my test program which starts 9600 Bauds, still works at 31250, but cannot reach 38400 Bds.
        Just replace “int” with “long”

        I tried to run at 256000 Bauds, but the value 281250 causes reported errors.
        I did multiple tests to identify the right value:
        Low operating limit between 235,000 and 235,500.
        High operating limit between 266,500 and 267,000.
        The median value would be 251000, it works but with a lot of time out errors reported by the screen.

        Results :

        Daiblo 4D / Arduino
        115200 / 115200 Bauds : good fonctioning
        128000 / 133928 Bauds : good fonctioning <--------- Best choice
        128000 / 128000 Bauds : Bad fonctioning
        256000 / 281250 Bauds : Bad fonctioning
        256000 / 251000 Bauds : works but has time out errors
        256000 / 256000 Bauds : works but has time out errors

        I have a good functioning at 128000 Bauds which should be enough to solve my problem .

        Here is my end of simplified program to adjust this baud rate:

        // Baud rate increase to 128000 Bauds
        DisplaySerial.print( ( char ) ( F_setbaudWait >> 8 ) ) ;
        DisplaySerial.print( ( char ) ( F_setbaudWait ) ) ;
        DisplaySerial.print( ( char ) ( 0 ) ) ;
        DisplaySerial.print( ( char ) ( BAUD_128000 ) ) ;
        DisplaySerial.flush( ) ;
        DisplaySerial.end( ) ;
        DisplaySerial.begin( 133928 ) ;
        delay( 50 ) ; // Display sleeps for 100 ms
        DisplaySerial.flush( ) ;
        Display.GetAck( ) ;


        If it can help others ...

        Comment

        Working...
        X