Menu

Resolved: Issues with Software RS232 routines

2020-06-25
2021-11-15
  • Bertrand BAROTH

    Bertrand BAROTH - 2020-06-25

    Resolved

    The attached program produces garbage, Tampon_leds is corrupted if I activate the serial routines ; if I cancel them with a "comment" in the "envoi ... " and "attente ..." sub's, everything works OK (excepted for the fact that I can't hear nothing ...). Very strange ...

     

    Last edit: Anobium 2021-11-15
  • Anobium

    Anobium - 2020-06-25

    I am not the expert on Soft Serial.. but, try this to isolate the issue.

    ' ----- Configuration
     #chip Mega8515, 4
    
     #Option Explicit
    
    ' Constantes et variables
    
     #Include <SoftSerial.h>
     #Define SER1_TXPORT PortC
     #Define SER1_TXPIN 1
     #Define SER1_RXPORT PortC
     #Define SER1_RXPIN 0
     #Define SER1_BAUD 9600
     #Define SER1_DATABITS 8
     #Define SER1_STOPBITS 1
     #Define SER1_INVERT Off
    
     Do
    
        Ser1Print "Hello"
        Ser1Send 13
        Ser1Send 10
        Wait 500 ms
     Loop
    

    Do you get Hello on the terminal?

     
  • Bertrand BAROTH

    Bertrand BAROTH - 2020-06-25

    The problem is not if the data are transmitted : in fact, they are, Emic speaks ... But there are "side effects", as I wrote some other variables are modified ! On the STK200, Port B is for PushButtons and Port D for control Leds. It looks as if inside softserial, memory allocation of variables would generate conflicts with other variables of user's prog. I tested with GCB 04, 05 and Minimal 06, same error.
    In fact, the error is (at least) inside SerXPrint (I used the prog without Attente_Emic, replacing it with a delay) and the wrong value tranferred to Tampon_leds is related with the variable Gare or gare_locale. Hope this helps for debugging ...
    I downloaded SoftSerial_20190205 and installed the four files, still the same ...
    Meanwhile I tested with hardware RS232, removing the jumpers for Pushbuttons at PD0 and PD1 ; the result was worse : not only Tampon_leds but Tampon_emic too were corrupted, resulting in unintelligible noise.

     

    Last edit: Bertrand BAROTH 2020-06-26
  • Bertrand BAROTH

    Bertrand BAROTH - 2020-06-27

    Since it is probable that there are some bugs (allocation of RAM) in the AVR part of softserial (and hardware RS232) routines (I could not find any in my prog, I made the test I described above, the errors appeared only when the serial routines were activated), are You planning to make an update in a near future ? I saw there was such a modification last year, I think for the PIC part, as most users of GCBasic seem to program this processor family ...
    Thanks in advance for any answer ...

     
    • Anobium

      Anobium - 2020-06-27

      We are updating very soon but we have not seen these errors before. We are currenlty adding more AVRs and we have tested and tested AVRs.

      I need a program with the minimum amount of code to reproduce the issue.

      Write a program - minimal code and let us have a look.

      :-)

       
  • Bertrand BAROTH

    Bertrand BAROTH - 2020-06-27

    A prog was attached to the first post. You can test it without Emic hardware by removing the call to Attente_emic (which waits for Emic finishing) inside of Annoncer_train, so no timeout will occur.

     
  • Anobium

    Anobium - 2020-06-27

    Sorry, may be I am not being clear.

    I need the minimum program. The smallest program to create the issue. Then, I can debug. Please try the attachment - this has the init. the serial in/out. Does this create the issue?

     
  • Bertrand BAROTH

    Bertrand BAROTH - 2020-06-27

    Your attachment does not create the issue, the leds 0 and 3 are immediately lit ; normal, if the "envoi ..." at line 55 corrupts the Tampon_leds, this cannot be seen because it is assigned a value later (line 59) and is written to Port at line 64. So I modified Your prog to the new attachment. And now the Tampon_leds was never corrupted. But I modified line 62 to send 64 times "A" ; and not only was the sentence repeated several times ( ? ) but tampon_leds was corrupted too at line 65 (lower nibble 0x1, Leds 1, 2 and 3 on). It seems that there is a kind of "buffer overflow" if one sends via RS232 a string longer than a "particular" value (32 ? ) ... Look for the same issue in the hardware routines.
    The problem does not come from the Emic, it has a buffer of 1024 bytes. But if You make the test without connecting it take care, don't forget to cancel the lines which activate a waiting for answer via RS232, otherwise there will be an endless loop in "Attente ... " and the prog can never reach line 63 !
    If this is the real cause, maybe a possibility would be a "#define Serial_buffer_size", to avoid the need of a minimum amount of RAM to use the RS232 routines ?

     

    Last edit: Bertrand BAROTH 2020-06-27
  • Frank Steinberg

    Frank Steinberg - 2020-06-28

    I can reproduce the issue on an Arduino Uno:

     #chip Mega328p, 16  'Arduino Uno
    
     #define USART_BAUD_RATE 9600
     #define USART_TX_BLOCKING
    
     Dim TestString As String * 50
     TestByte = 1
    
     HSerPrint TestByte
     HSerSend  13
    
     TestString = "--------10--------20--------30--------40--------50"
     HSerPrint TestString
     HSerSend  13
     HSerPrint TestByte
     HSerSend  13
    
     TestString = "--------10--------20--------30------38"
     HSerPrint TestString + "x"
     HSerSend  13
     HSerPrint TestByte
     HSerSend  13
    
     'This changes the value of TestByte:
     TestString = "--------10--------20--------30--------40"
     HSerPrint TestString + "x"
     HSerSend  13
     HSerPrint TestByte
     HSerSend  13
    

    Using a longer string (> 38 chars here) and merge the string while using HSerPrint (SerNPrint the same) the value of the byte variable is changed while never touched by code.

    Workaround: Merge String before sending via Print.

    Frank

     
  • Bertrand BAROTH

    Bertrand BAROTH - 2020-06-28

    Thanks ... In fact the idea is working because the Emic concatenates the incoming strings in its input buffer and begins with speaking only when the complete string is terminated by a CR. I attach the final prog (I must admit, it looks a little bit "strange", but it works) ... As You understood the routines will be used in my model railroad layout control program, and a side effect could cause a "splendid" accident or short-circuit on a turnout. I attach the final test program. But You could add the information of maximal length in a future version of help file.
    And, since I am sure that there will be no side effects if I use only strings "not too long", maybe I will replace the "synthetic" , but a little "robotic" voice of the Emic : some modellers compared the samples that I published on a model forum with the voice of a Cylon warrior in "Battlestar Galactica", end of the 70's ... With the Adafruit sample player the commands are only 13 characters in length : "P" (for "Play") + 8 for file name + 3 for extension + LF ...

     

    Last edit: Bertrand BAROTH 2020-06-28
  • Anobium

    Anobium - 2020-06-29

    Guys - well done. I did not recognise the bug. This bug is planned to be fixed in the next release. Just awaiting Hugh to complete a few last items.

    See https://sourceforge.net/p/gcbasic/discussion/579125/thread/8aafd62637/#da98 item #5 "String concat errors"

    This issue has been reported mulitple times. Below is the bug reference note I have:

    User cannot concat with AVR.  Tested ok on PIC.
    
    Simplified the code.
    
    #CHIP mega328p, 16
    
    'USART settings
    #define USART_BAUD_RATE 9600
    #define USART_TX_BLOCKING
    #define USART_DELAY OFF
    
    Do Forever
        wait 1 s
    
        HSerPrint "a"+"123"
        HSerPrintCRLF
    
    Loop
    
    Yields
    
    a13
    a13
    a13
    a13
    a13
    a13
    a13
    a13
    

    I will add Frank's new example to the reference notes for this bug.

     
    • Anobium

      Anobium - 2021-10-09

      This now yields A123 - as expected.

      #CHIP mega328p, 16
      
      'USART settings
      #define USART_BAUD_RATE 9600
      #define USART_TX_BLOCKING
      #define USART_DELAY OFF
      
      Do Forever
          wait 1 s
      
          HSerPrint "a"+"123"
          HSerPrintCRLF
      
      Loop
      

      Now yeilds

      a123
      a123
      a123
      a123
      a123
      a123
      a123
      a123
      a123
      a123
      a123
      
       
  • Bertrand BAROTH

    Bertrand BAROTH - 2020-07-07

    Finally I found that the best solution was to send the string one character at once in a loop :

    Sub Envoi_tampon_emic ()

    ' Envoie le contenu du Tampon_emic

    Dim compteur_local As Byte
    Dim char_local As String * 1

    Tampon_emic = Tampon_emic + chr (13)
    For compteur_local = 1 to Len (Tampon_emic)
    char_local = Mid (tampon_emic, compteur_local, 1)
    Ser1Print (char_local)
    Next

    End Sub

     

    Last edit: Bertrand BAROTH 2020-07-07

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.