Menu

Serial 16f628A works only in specific baud

Christos
2015-07-12
2015-07-13
  • Christos

    Christos - 2015-07-12

    following code ONLY works at 1200 baud, ANY other rate (tested 300,4800,9600,19200) produce trash

    software serial NEVER did work

    #chip 16f628A, 4
    #config OSC = INTOSC
    #define USART_BAUD_RATE 1200
    #define SerOutPort PORTB.4
    #define SerInPort PORTB.5
    InitSer 1, r1200, 1 + WaitForStart, 8, 1, none, invert
    
    DIR PortB out
    
    SerPrint 1,"soft"
    HSerPrint "hard"
    
     

    Last edit: Christos 2015-07-12
  • Anobium

    Anobium - 2015-07-12

    Are you using the latest Hot Release? If not, please upgrade.

    Please let us know the results.

     
  • Christos

    Christos - 2015-07-12

    version 0.94 yes

    just tried same program in microbasic pro
    and works ok, so all my hardware is good and working

     
  • Anobium

    Anobium - 2015-07-12

    Thanks.

    We have tested and we have demonstration programs for serial, so, I need to ask a few questions.

    Does Software serial or Hardware serial not work? or, both?

    Does one work when only one type is programmed? ie Hardware only or Software only?

    Are you communications direct to your PC terminal or via Max232 type converters?

    I have just tested here on my simulator. Looks good for software and hardware. My test code is shown below.

    Can you have a look the demos please? the config for software is shown in the demos.

    Evan

    ; ----- Configuration
    #chip 16f628A, 4
    #config OSC = INTOSC
    
    ; ----- Define Hardware settings
      Dir PORTB.4 Out  'send on Pin 5
      Dir PORTB.5 In   'receive on Pin 7 (PCD)
    
      'Config Software-UART
      #define SendAHigh Set PORTB.4 ON
      #define SendALow Set PORTB.4 OFF
      #define RecAHigh PORTB.5 ON
      #define RecALow PORTB.5 OFF
      InitSer 1, r2400, 1+WaitForStart, 8, 1, None, nORMAL
    
      'Config hardware UART
      #define USART_BLOCKING
      #define USART_BAUD_RATE 2400
    
    '  'Invert UART data polarity to connect without max232:
    '  Set TXCKP On     'inverted transmit data polarity
    '  Set RXDTP On     'inverted receive data polarity
    '  Wait 100 Ms
    
    ; ----- Variables
      ' No Variables specified in this example. All byte variables are defined upon use.
    
    ; ----- Main body of program commences here.
      'Message after reset
      SerPrint 1, " PIC 16f628A"
      SerSend 1, 13  ' "Carriage Return"
      SerSend 1, 10  ' "Line Feed"
    
    SerPrint 1,"soft"
    HSerPrint "hard"
    
     
  • Christos

    Christos - 2015-07-12

    hi and thanx

    both serial and hardware do NOT work in my program, either alone or together.

    using STK500's converter (max232)

    i copy paste your test and make the following conclusions
    i have fully working software serial :) my mistake was
    #define SerOutPort PORTB.4
    it does not exist as a define i misread manual correct is
    #define SendAHigh Set PORTB.4 ON
    #define SendALow Set PORTB.4 OFF

    HOWEVER i found the real problem in HARDWARE serial
    it does trim final 2 bytes in string in low baud rates (300 -1200)
    does NOT trim them at high boud rates 9600-19200 (maybe more)

     
  • Anobium

    Anobium - 2015-07-12

    Ok. Good in software.

    I personally use hw usart extensively at a range of different speeds - no issues. I do not think we have had any issues reported for a number of years.

    Post your test code as an attachment please. Please also ensure you have the original usart.h file when you are testing.

    Again, please look at the serial demos foe inspiration.

    Evan

     
  • Christos

    Christos - 2015-07-12

    the following one example is helpfull i believe

    #chip 16f628A, 4
    #config OSC = INTOSC
    
      #define USART_BLOCKING
      #define USART_BAUD_RATE 300
    
    HSerPrint "hard-"
    HSerPrint "hardware"
    
    end
    

    above code prints "hard-hardwa"

    #chip 16f628A, 4
    #config OSC = INTOSC
    
      #define USART_BLOCKING
      #define USART_BAUD_RATE 19200
    
    HSerPrint "hard-"
    HSerPrint "hardware"
    
    end
    

    above AND below code prints "hard-hardware"

    #chip 16f628A, 4
    #config OSC = INTOSC
    
      #define USART_BLOCKING
      #define USART_BAUD_RATE 300
    
    HSerPrint "hard-"
    HSerPrint "hardware"
    
    wait 100 ms
    end
    
     

    Last edit: Christos 2015-07-12
  • Anobium

    Anobium - 2015-07-13

    Sorry, I cannot reproduce on the test bed here. I used you code and I got 'hard-hardware' in all cases.

    I have 628a, max232 to PC/Putty terminal. PC serial driver is set to FIFO and small 16 byte buffer.

     
  • Anobium

    Anobium - 2015-07-13

    A thought.

    Have a look at the latest help. http://gcbasic.sourceforge.net/help/ I did update with more information on hardware serial.

    The complete code would be:

    ~~~~~
    ; ----- Configuration

    chip 16f628A, 4

    config OSC = INTOSC

    'Config hardware UART
    #define USART_BLOCKING
    #define USART_TX_BLOCKING
    #define USART_DELAY 5 ms ' default is 1 ms
    #define USART_BAUD_RATE 19200

    HSerPrint "hard-"
    HSerPrint "hardware"
    ~~~~

     
  • Christos

    Christos - 2015-07-13

    whats new is online ? its same as offline (btw it is missing define USART_DELAY what it does tweaking?)

    your code is at 19200 baud and yes it print full text
    altering baud to 300, problem appears

    adding a "wait 100 ms" to the end prints everything

    i also use putty/PC/Win7 64 but don't believe its the issue ! since following microbasic code works

    program test
    
    main:
    
    UART1_Init(300)
    UART1_Write_Text("hard-")
    UART1_Write_Text("hardware")
    
    end.
    

    notice in asm output that the program "ends" with a sleep command
    is it possible that sleeps too fast before last characters send out ?
    alternative compilers end program with only a GOTO to itself
    (thats also saves 1 programword :))

    can somehow f.e. the sleep added ONLY if "end" in basic code added ?

     

    Last edit: Christos 2015-07-13
  • Anobium

    Anobium - 2015-07-13

    Re online and offline. The offline help file is the help released with the Hot Release. We maintain the Help as we add functionality and I update the online as I proceed. You can always check the Changes section - this shows the dates etc.

    I did over a range of baud rates. Puzzled.

    Re your code. Add a do forever-loop to the end of your code. This will prove your theory regarding end of code timing.

     
    • Anobium

      Anobium - 2015-07-13

      I will add to the next release the definition of usart_delay. I had missed that one. Thank you.

       
  • Christos

    Christos - 2015-07-13

    tried a
    do
    loop
    instead of
    wait 100 ms

    and yes i have all bytes at 300 baud as well

     
  • Anobium

    Anobium - 2015-07-13

    Excellent. I will add some words to the Help File explaining the need to enable a wait for the usart buffer to empty before the end of the program.

     

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.