Menu

Ser1Print and Ser1Send command

Help
JB
2024-04-24
2025-05-15
1 2 > >> (Page 1 of 2)
  • JB

    JB - 2024-04-24

    Hello,

    looking for help about serial communication commands.

    for the Ser1Print command the first 3 bytes are not similar to what has been sent

    the Ser1Send command all the bytes are received ok.

    #option explicit
    #chip tiny10, 8
    
     ; ----- Include library
        #include <SoftSerial.h>
    
        ; ----- Config Serial UART for sending:
        #define SER1_BAUD 4800     ; baudrate must be defined
        #define SER1_TXPORT PORTB  ; I/O port (without .bit) must be defined
        #define SER1_TXPIN 0       ; portbit  must be defined
        #define SER1_INVERT On
    
     DO
    PAUSE 50
    ; first data segment
     Ser1Print "ABCDEFabcdef"
    pause 50
    ; second data segment
        Ser1Send 65  ;A
        Ser1Send 66  ;B
        Ser1Send 67  ;C
        Ser1Send 68  ;D
        Ser1Send 69  ;E
        Ser1Send 70  ;F
        Ser1Send 97  ;a
        Ser1Send 98  ;b
        Ser1Send 99  ;c
        Ser1Send 100 ;d
        Ser1Send 101 ;e
        Ser1Send 102 ;f
     LOOP
    
     
  • Anobium

    Anobium - 2024-04-25

    These chips are very limited in terms of RAM. I am surprised you can even create a string of "ABCDEFabcdef". Try preallocating the string RAM handler. These chips have some limitations. :-)

    #DEFINE SYSDEFAULTCONCATSTRING 14

     
  • JB

    JB - 2024-04-25

    Hello ,

    I was able to send separate string of 18 char. max with the Ser1Print,
    but I had to use this instead "#DEFINE SYSDEFAULTCONCATSTRING 0" to work

    the Ser1Send work only with byte var, and it's ok for commend control for the LCD (FRM010)
    on the other hand the Ser1Print "xxxxxx" string is sent ok, but I think it need a delay between
    each byte sent like the Ser1Send so the LCD can catch all the characters.

    (I tried to get the same result as PBP3 Serout Pc: Pace var needed to work)

    SerOut GPIO.1,N4800,**Pc**,[254,128,"1234567890ABCDEFGHIJ"] ; Line 1
    DelayMS D1
    
    Here's the PulseView chart I was able to get from Ser1Print
    
     
  • JB

    JB - 2024-04-25

    Here's a timing for "Ser1Print" at 300uS avr/ between stop-start bit
    and "Ser1Send" at 1.4mS avr.
    The "Ser1Send" is working fine with all 80 characters at the display
    but the "Ser1Print" the first character of "ABCD" A is ok all sub-sequent are not
    Listed below both listing code.
    Thanks again Evan.

    ; **Ser1Send**
    ; gosub / return  ok  Evan.
    #option explicit
    #chip tiny10, 1
    
     ; ----- Include library
        #include <SoftSerial.h>
    
        ; ----- Config Serial UART for sending:
        #define SER1_BAUD 4800     ; baudrate must be defined
        #define SER1_TXPORT PORTB  ; I/O port (without .bit) must be defined
        #define SER1_TXPIN 0       ; portbit  must be defined
        #define SER1_INVERT On
    
    Dim Count as byte
    Dim Count1 as byte
    
    pause 1000
    ;BackLight On/Off
      ser1send 255  ;BackLight On
      pause 1
      ser1send 8    ;8=On, 0=Off
      pause 1
    
    DO
    ; Count Char
    for count = 128 to 167
        Count1 = count - 80
        gosub main
    next
    
    for count = 192 to 231
        Count1 = count - 104
        gosub main
    next
    
    pause 1000
    ; Clear LCD
      ser1send 254
      pause 1
      ser1send 1
      pause 1
      pause 1000
    loop
    
    Main:
        ser1send 254
        pause 1
        Ser1Send count
        pause 1
        Ser1Send Count1
        pause 1
    return
    
    ; **Ser1Print**
    #option explicit
    #chip tiny10, 1
    
     ; ----- Include library
        #include <SoftSerial.h>
    
        ; ----- Config Serial UART for sending:
        #define SER1_BAUD 4800     ; baudrate must be defined
        #define SER1_TXPORT PORTB  ; I/O port (without .bit) must be defined
        #define SER1_TXPIN 0       ; portbit  must be defined
        #define SER1_INVERT On
    
    Dim Count as byte
    Dim Count1 as byte
    
    pause 1000
    ;BackLight On/Off
      ser1send 255  ;BackLight On
      pause 1
      ser1send 8    ;8=On, 0=Off
      pause 1
    
    ; Clear LCD
      ser1send 254
      pause 1
      ser1send 1
      pause 1
      pause 500
    
    DO
    ; Clear LCD
      ser1send 254
      pause 5
      ser1send 1
      pause 5
      pause 500
    
        ser1send 254
        pause 5
        Ser1Send 128
        pause 5
        Ser1Print "ABCD"
    ;    PAUSE 1
    ;    Ser1Print "B"
    ;    PAUSE 1
    ;    Ser1Print "C"
    ;    PAUSE 1
    ;    Ser1Print "D"
        pause 500
    
    loop
    
     
  • Anobium

    Anobium - 2024-04-26

    A bit confused - does "#DEFINE SYSDEFAULTCONCATSTRING 0" resolve?

     
  • JB

    JB - 2024-04-26

    as for the "#DEFINE SYSDEFAULTCONCATSTRING 0" ,
    the max. string it can send is 18 characters but still the display is receiving random characters.

    for the
    Ser1Send: sending one byte at the time
    is working well but need a pause of at least 1ms between each send.

    ser1send 254
      pause 1
      ser1send 1
      pause 1
    

    for the
    Ser1Print: sending a string ,bytes etc..
    will need some kind of delay between each byte it send
    ( #define SER1_Delay )

    Thanks Evan

     
  • Anobium

    Anobium - 2024-04-26

    I am not the expert on the Software Serial - but, try adding this to your program. This is change the Ser1Print to this new code.

    I have added a constant called Ser1PrintInterCharDelay this can be any value. I have set to 50. Type different values. Does this work ?

    #DEFINE Ser1PrintInterCharDelay 50
    
    Sub Ser1Print (In PrintData As String)
    
    Dim PrintLen, SysPrintTemp as Byte
       'PrintLen = LEN(PrintData$)
       PrintLen = PrintData(0)
    
       if PrintLen = 0 then Goto Ser1PrintStrEnd
    
       'Write Data
       for SysPrintTemp = 1 to PrintLen
          Ser1Send PrintData(SysPrintTemp)
       next
    
     'CR
     Ser1PrintStrEnd:
      #IFDEF SerPrintCR
        Ser1Send 13
      #ENDIF
      #IFDEF SerPrintLF
        Ser1Send 10
      #ENDIF
      #IFDEF Ser1PrintInterCharDelay
        wait Ser1PrintInterCharDelay ms
      #ENDIF
    
    End Sub
    
     
  • JB

    JB - 2024-04-26

    I tried 5,50,500,5000.
    the delay work between each Ser1Print command ,
    but not between each byte it's send.

     
  • Anobium

    Anobium - 2024-04-26

    You could move the test I added re the new contants to Ser1Send. look in the Ser1.h file. You will have to check that filename.

     
  • JB

    JB - 2024-04-26

    like this the delay between bytes is working, but some characters are not sent properly.

    'Write Data
    for SysPrintTemp = 1 to PrintLen
    Ser1Send PrintData(SysPrintTemp)
    wait Ser1PrintInterCharDelay ms
    next

    ;Line sent
    Ser1Print "ABCDEFGHIJKLMNOPQRST"
    Ser1Print "12345678901234567890"
    Ser1Print "abcdefghijklmnopqrst"
    Ser1Print "stuvwxyz[]\<>?,./+[]"
    see pic for display result.

    `
    ; Ser1Print "ABCDEFabcdef" TEST
    ;
    ;

    option explicit

    chip tiny10, 1

    ;#DEFINE SYSDEFAULTCONCATSTRING 14
    ; ----- Include library
    #include <softserial.h></softserial.h>

    ; ----- Config Serial UART for sending:
    #define SER1_BAUD 4800     ; baudrate must be defined
    #define SER1_TXPORT PORTB  ; I/O port (without .bit) must be defined
    #define SER1_TXPIN 0       ; portbit  must be defined
    #define SER1_INVERT On
    

    Dim PC as byte
    PC =3

    pause 500
    ser1send 254 ; must clear LCD first
    pause pc
    ser1send 1
    pause pc
    pause 500
    ser1send 255
    pause pc
    ser1send 8 ;LCD BackLight On
    pause pc

    ser1send 254
    pause pc
    ser1send 128 ;Line 1
    pause pc
    Ser1Print "ABCDEFGHIJKLMNOPQRST"
    pause pc

    ser1send 254
    pause pc
    ser1send 192 ;Line 2
    pause pc
    Ser1Print "12345678901234567890"
    pause pc

    ser1send 254
    pause pc
    ser1send 148 ;Line 3
    pause pc
    Ser1Print "abcdefghijklmnopqrst"
    pause pc

    ser1send 254
    pause pc
    ser1send 212 ;Line 4
    pause pc
    Ser1Print "stuvwxyz[]\<>?,./+[]"
    pause pc

    #DEFINE Ser1PrintInterCharDelay 50
    

    Sub Ser1Print (In PrintData As String)

    Dim PrintLen, SysPrintTemp as Byte
    'PrintLen = LEN(PrintData$)
    PrintLen = PrintData(0)

    if PrintLen = 0 then Goto Ser1PrintStrEnd

    'Write Data
    for SysPrintTemp = 1 to PrintLen
    Ser1Send PrintData(SysPrintTemp)
    wait Ser1PrintInterCharDelay ms
    next

    'CR
    Ser1PrintStrEnd:
    #IFDEF SerPrintCR
    Ser1Send 13
    #ENDIF
    #IFDEF SerPrintLF
    Ser1Send 10
    #ENDIF
    #IFDEF Ser1PrintInterCharDelay
    wait Ser1PrintInterCharDelay ms
    #ENDIF

    End Sub

    `

     
  • Anobium

    Anobium - 2024-04-26

    Replace the LCD with a serial terminal - still got the same issue ? If the same issue then it points to timing in the Tiny10 program. I think you need to do this test to eradicate the LCD being at fault.

     
  • JB

    JB - 2024-04-26

    Good News Evan.

    with this on my code it's working.

    since I don't use CR,LF I did put ";" on the 'CR sub

    and I can adjust the Pc = 1ms , and the Ser1PrintInterCharDelay to 1.

    Thank you Evan excellent work.
    My regards.

    DEFINE SYSDEFAULTCONCATSTRING 0

    ; Ser1Print "ABCDEFabcdef" TEST
    ;
    ;
    #option explicit
    #chip tiny10, 1
    #DEFINE SYSDEFAULTCONCATSTRING 0
     ; ----- Include library
        #include <SoftSerial.h>
    
        ; ----- Config Serial UART for sending:
        #define SER1_BAUD 4800     ; baudrate must be defined
        #define SER1_TXPORT PORTB  ; I/O port (without .bit) must be defined
        #define SER1_TXPIN 0       ; portbit  must be defined
        #define SER1_INVERT On
    
    
    
    Dim PC as byte
    PC =1
    
    pause 500
    ser1send 254 ; must clear LCD first
    pause pc
    ser1send 1
    pause pc
    pause 500
    ser1send 255
    pause pc
    ser1send 8   ;LCD BackLight On
    pause pc
    
    ser1send 254
    pause pc
    ser1send 128  ;Line 1
    pause pc
    Ser1Print "ABCDEFGHIJKLMNOPQRST"
    pause pc
    
    ser1send 254
    pause pc
    ser1send 192  ;Line 2
    pause pc
    Ser1Print "12345678901234567890"
    pause pc
    
    ser1send 254
    pause pc
    ser1send 148  ;Line 3
    pause pc
    Ser1Print "abcdefghijklmnopqrst"
    pause pc
    
    ser1send 254
    pause pc
    ser1send 212  ;Line 4
    pause pc
    Ser1Print "stuvwxyz[]\<>?,./+[]"
    pause pc
    
    
    
    #DEFINE Ser1PrintInterCharDelay 1
    
    Sub Ser1Print (In PrintData As String)
    
    Dim PrintLen, SysPrintTemp as Byte
       'PrintLen = LEN(PrintData$)
       PrintLen = PrintData(0)
    
       if PrintLen = 0 then Goto Ser1PrintStrEnd
    
       'Write Data
       for SysPrintTemp = 1 to PrintLen
    
             Ser1Send PrintData(SysPrintTemp)
    wait Ser1PrintInterCharDelay ms
       next
    
     'CR
     Ser1PrintStrEnd:
      ;#IFDEF SerPrintCR
       ; Ser1Send 13
      ;#ENDIF
      ;#IFDEF SerPrintLF
        ;Ser1Send 10
      ;#ENDIF
      ;#IFDEF Ser1PrintInterCharDelay
       ; wait Ser1PrintInterCharDelay ms
      ;#ENDIF
    
    End Sub
    
     
  • Anobium

    Anobium - 2024-04-26

    We should get Frank to add the optional delay to add the Ser1 commands. Then, you would remove all the delays in your source. Is the best approach?

     
  • JB

    JB - 2024-04-26

    Something as ( #define SER1_Delay ? )
    easier to read

     
  • Anobium

    Anobium - 2024-04-26

    These are the Ser1 related Constants.

                  FINAL/CONSTANT :SER1_BAUD                                             4800
                  FINAL/CONSTANT :SER1_DATABITS                                         8
                  FINAL/CONSTANT :SER1_INVERT                                           1
                  FINAL/CONSTANT :SER1_RXNOWAIT                                         0
                  FINAL/CONSTANT :SER1_RXPORT                                           SER1_RXPORT_NOT_SET
                  FINAL/CONSTANT :SER1_STOPBITS                                         1
                  FINAL/CONSTANT :SER1_TXPIN                                            0
                  FINAL/CONSTANT :SER1_TXPORT                                           PORTB
                  FINAL/CONSTANT :STX1_DELAY                                            66
                  FINAL/CONSTANT :STX1_DELAYH                                           0
    

    So, as this is specific to Ser1 then maybe SER1_TXDELAY would be best.

    Do you want to make these changes?

     
  • JB

    JB - 2024-04-26

    go for it, it's make sense
    this will be in the new gbasic.exe ?

     

    Last edit: JB 2024-04-26
    • Anobium

      Anobium - 2024-04-26

      Do you want to edit this in softserialch1.h ?

       
  • JB

    JB - 2024-04-26

    I'll need some guidance for this if you don't mind
    and how to implement in my code (syntax)

     
  • Anobium

    Anobium - 2024-04-26

    Of course,

    If you edit softserialch1.h in the appropriate place(s).

    Add

      #IFDEF Ser1_TXDELAY
           wait Ser1_TXDELAY ms
      #ENDIF
    

    This will only add the wait if Ser1_TXDELAY exists. This is called conditional compilation.

    You could put at the end of Sub Ser1Send (In STxDataByte) just before the END SUB


    Test, removing the waits in your program and add the constant Ser1_TXDELAY.

     
  • JB

    JB - 2024-04-26

    Let me look at it first .. and I'll comeback

     
  • JB

    JB - 2024-04-26

    I had to get Notepad++, and edit the softserialch1.h
    test after edit :
    with #DEFINE Ser1_TXDELAY ms = 1
    text get on display very slow, and some characters at the end are random.

    without
    ; #DEFINE Ser1_TXDELAY ms = 1
    display is very fast annd accurate

    ;
    #option explicit
    #chip tiny10, 1
    #DEFINE SYSDEFAULTCONCATSTRING 0
     ; ----- Include library
        #include <SoftSerial.h>
    
        ; ----- Config Serial UART for sending:
        #define SER1_BAUD 4800     ; baudrate must be defined
        #define SER1_TXPORT PORTB  ; I/O port (without .bit) must be defined
        #define SER1_TXPIN 0       ; portbit  must be defined
        #define SER1_INVERT On
        ;#DEFINE Ser1_TXDELAY ms = 1
    
    
    Dim PC as byte
    PC =1
    do
    pause 500
    ser1send 254 ; must clear LCD first
    pause pc
    ser1send 1
    pause pc
    pause 50
    ser1send 255
    pause pc
    ser1send 8   ;LCD BackLight On
    pause pc
    
    ser1send 254
    pause pc
    ser1send 128  ;Line 1
    pause pc
    Ser1Print "ABCDEFGHIJKLMNOPQRST"
    
    
    ser1send 254
    pause pc
    ser1send 192  ;Line 2
    pause pc
    Ser1Print "12345678901234567890"
    
    
    ser1send 254
    pause pc
    ser1send 148  ;Line 3
    pause pc
    Ser1Print "abcdefghijklmnopqrst"
    
    
    ser1send 254
    pause pc
    ser1send 212  ;Line 4
    pause pc
    Ser1Print "stuvwxyz[]\<>?,./+[]"
    
    loop
    
    
    #DEFINE Ser1PrintInterCharDelay 1
    
    Sub Ser1Print (In PrintData As String)
    
    Dim PrintLen, SysPrintTemp as Byte
       'PrintLen = LEN(PrintData$)
       PrintLen = PrintData(0)
    
       if PrintLen = 0 then Goto Ser1PrintStrEnd
    
       'Write Data
       for SysPrintTemp = 1 to PrintLen
    
             Ser1Send PrintData(SysPrintTemp)
    wait Ser1PrintInterCharDelay ms
       next
    
    ; 'CR
     Ser1PrintStrEnd:
    ;  ;#IFDEF SerPrintCR
    ;   ; Ser1Send 13
    ;  ;#ENDIF
    ;  ;#IFDEF SerPrintLF
    ;    ;Ser1Send 10
    ;  ;#ENDIF
    ;  ;#IFDEF Ser1PrintInterCharDelay
    ;   ; wait Ser1PrintInterCharDelay ms
    ;  ;#ENDIF
    
    End Sub
    
     
  • JB

    JB - 2024-04-26

    and the edit with notepad++

     
  • Anobium

    Anobium - 2024-04-26

    Did you remove all the pause and waits from your program? You may have to leave the pause 500. Othewise you are getting lots of waits.

    And, you should remove the modified Ser1Print from you program. Again, this is no longer needed.

     
  • JB

    JB - 2024-04-26

    with : #DEFINE Ser1_TXDELAY ms = 2
    it's very slow and last 3 characters of line are not right
    with all wait remove except first pause 500 for the display refresh, and clear.

    with : #DEFINE Ser1PrintInterCharDelay 8
    the Ser1Print (String) work fine
    but still I need the wait for each Ser1Send (Line/Col)

    from the softserial1 file, the "String" portion is ok,
    but can't find the byte Ser1Send section to add (#DEFINE Ser1PrintInterCharDelay 8)

     
  • JB

    JB - 2024-04-26

    when using
    Ser1Print 254 ,
    Ser1Print 128 ; Line 1

    it's sent as text not byte.
    otherwise I'll use this to remove the wait.
    let me know if I'm on the right track.
    Thank you

     
1 2 > >> (Page 1 of 2)

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.