Menu

Software uart end

Help
Marcoos
2014-03-24
2014-03-25
  • Marcoos

    Marcoos - 2014-03-24

    Sorry, but it fate of
    I entered the serial software and everything seemed to work fine.
    But I realized today that if I do not send first one to use the routine in the program the first byte data is corrupted.
    The defect was masked by the panel on the pc that automatically discarded the data, but using the serial terminal with the defect is highlighted.
    The serial works in slave mode.

    #chip tiny44,1
    #config osc = int
    
    'Impostazioni RS232
    '------------------------------------------------------------------------------
    
    #define SendAHigh Set PORTA.5 Off
    #define SendALow Set PORTA.5 On
    #define RecAHigh PORTA.6 Off
    #define RecALow PORTA.6 On
    
    Dir PORTA.5 Out     'TX232
    Dir PORTA.6 In      'RX232
    
    InitSer 1, r300, 1+WaitForStart, 8, 1, none, invert
    StartLine = "z"  ' per inizio linea
    '------------------------------------------------------------------------------
    'mem
    
    Dim StartLine, test1,test2, T1, as byte
    
    'Create buffer variables to store 232 received messages
    Dim Buffer As String
    BufferSize = 5
    
    SerSend 1, "b"  'pulizia trasm?????????? if not, don't run!!!!
    ' Loop principale
    do
            call SerGest
            wait 500 us
    Loop
    
    end
    
    Sub SerGest
        TempSer=0
        SerReceive 1, TempSer
        if TempSer= StartLine then
            T1=1
            for T1=1 to 4
            SerReceive 1, Buffer(T1)
    '        SerSend 1, Buffer(T1)   echo for test
            Next
            wait 5 ms
            SerSend 1, StartLine
            T1=1
            for T1=1 to 4
            SerSend 1, Buffer(T1)
            Next
        End if
    End sub
    
     

    Last edit: Marcoos 2014-03-24
  • Marcoos

    Marcoos - 2014-03-24

    software uart send.....!!!
    Bye

     
  • Anobium

    Anobium - 2014-03-24

    This may be hard to diagnose.

    From my knowledge and experience.

    • 'Invert' baud rate idles low, with data pulse going high.

    • 'True' baud rate idles high, with data pulses going low. When using a True baud rate
      the very first byte may become corrupt if the output pin was low before the SerSend
      command (the pin will be automatically left high after the SerSend command). To
      avoid this issue place the line high (via a High command’) a few milliseconds
      before the very first SerSend command.

    So, using the same principle, I think you have the signals the wrong way around. I would try as below

    #define SendAHigh Set PORTA.5 On
    #define SendALow Set PORTA.5 Off
    

    I stand to be corrected but remote serial diagnosis is tough.

     
  • Anobium

    Anobium - 2014-03-24

    Or, leave the SerSend 1, "b" 'pulizia trasm because it seems to work. :-)

    :-)

     
  • Marcoos

    Marcoos - 2014-03-24

    Sorry but maybe I have not explained clearly, is quite complicated.
    The polarity of the pin is correct, in fact once the match, the serial is working properly, I have zero errors after hours, the problem is only the first send of the sersend, and is also easily be masked, however, remains.
    I have an idea, reading your response, but when They come declared the bits for the serial, what state they were before?
    who initializes the pins to the correct level?
    Tomorrow if I can do the tests.
    good night, Marco

     
  • Marcoos

    Marcoos - 2014-03-24

    Hi
    I havn't see your last post, yes it work, but tomorrow I want do the test :-)

     
  • Marcoos

    Marcoos - 2014-03-25

    Hello
    I Can now confirm the problem is on the output level initialization, this run ok!!!

    'Impostazioni RS232
    '------------------------------------------------------------------------------
    
    #define SendAHigh Set PORTA.5 Off
    #define SendALow Set PORTA.5 On
    #define RecAHigh PORTA.6 Off
    #define RecALow PORTA.6 On
    Set PORTA.5 On  ' set iniziale tx for the right level
    Dir PORTA.5 Out     'TX232
    Dir PORTA.6 In      'RX232
    
    InitSer 1, r300, 1+WaitForStart, 8, 1, none, invert
    

    if the output level is not initialized correctly, in line with the choices of initialization 232, the first character in the output will be wrong.
    Sorry, but I do not have the capacity to do so, but I think based on the When initialization file 232 software should set the appropriate level for its operation, is not it? tell me, thanks, Marco

     
  • Anobium

    Anobium - 2014-03-25

    Very good news.

    I like the idea of initialisation setting the appropriate output level. I have an idea that could work. Let me add it to the list of new functionality.

     
  • Marcoos

    Marcoos - 2014-03-25

    I'm just glad to add a grain .........
    Marco

     
  • Chuck Hellebuyck

    I added a soft serial routine to my sample projects page.
    I used the UART tool inside the PICkit 2 software as the terminal.
    I just send the data through the programming pins RB6 and RB7 so I don't have to disconnect the PICkit 2 or attached a RS232 to USB convertor.
    I just have the code posted, no schematic.
    http://www.greatcowbasic.com/sample-projects.html

     

Log in to post a comment.