1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Software Usart

Discussion in 'Oshonsoft' started by mastero, May 23, 2016.

  1. mastero

    mastero Member

    Joined:
    Nov 27, 2011
    Messages:
    69
    Likes:
    1
    Hello Ian,

    I am using internal 4mhz clock .

    Found with simple led method the interrupt is not getting triggered when data received at RX pin.

    any idea ?

    latest progress ..... tried with 4mhz resonator with HS config bit ......still no luck
     
    Last edited: Jun 8, 2016
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,304
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    When debugging serial, you really need to clear the input buffer before receiving a new packet or the '#' will always be there even if there were errors.

    A simple while loop to clear the input buffer at the end of a successful transmission is needed..
     
  3. mastero

    mastero Member

    Joined:
    Nov 27, 2011
    Messages:
    69
    Likes:
    1
    ok i am a little confused here

    my code for receving and storing

    Code (BASIC):


    On Interrupt
    Save System
        If RCSTA.OERR = True Then  'any error reboot serial module..
            RCSTA.CREN = 0
            RCSTA.CREN = 1
            Goto fin
        Endif
        serdata = RCREG  '; get character(reading clears the RCIF)
       
        If serdata > 0 Then
         
                    data(j) = serdata  'store data in buffer
                        j = j + 1
                    If j = 12 Then
                        j = 0
                        outptr = True
                    Endif
        Endif

    fin:
        Resume
     
    You want me to clear serdata or data ? cause data is getting cleared after the array buffer has been processed using

    For k = 0 To 12 Step 1 'clear buffer
    data(k) = 0x00
    Next k

    now i tried the same software on another MCU 16f690 had brand new ones around.

    one 690 works and the other 690 does not.

    After power up. The first time data is sent to the rx pin the MCU halts for say a good 3secs i know this cause there is a status led blinking every 0.5sec
    which does not blink.

    Then after that 3sec of halt the Status led starts to blink again and any data sent after this is accepted by the Chip.

    Same issue was there with the working 16f628A also, the second 690 when the data is sent first time same halt but does not resume after 3 sec same as other 628a's

    very confusing this is ..... :( please help or advice.

    thanx in advance.

    mastero
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. mastero

    mastero Member

    Joined:
    Nov 27, 2011
    Messages:
    69
    Likes:
    1

    ok update :

    The system hangs after reading the first byte.

    i taught

    serdata = RCREG

    will clear the RCIF buffer and it is a read only as per DS 12.2.2

    am i missing something here ??

    cheers
    mastero
     
    Last edited: Jun 8, 2016
  6. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,304
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    Reading the RCREG clears the flag...

    Sorry about the confusion about clearing the data buffer.... But as it wasn't included, I did't know it was there...

    When I get some time tonight, I'll get one up and running as see what gives..
     
  7. mastero

    mastero Member

    Joined:
    Nov 27, 2011
    Messages:
    69
    Likes:
    1
    Ok thanx will to see what you come up with.

    In osho simulator it works perfectly.

    Very confusing.

    Cheers
    Mastero
     
  8. mastero

    mastero Member

    Joined:
    Nov 27, 2011
    Messages:
    69
    Likes:
    1
    solved ...

    the issue was there was too many waitms in the code.....;)

    make a sub for each and call it .....solves the problem for any one who walks my path...;)

    thank you a million for all who helped.... specially ian :)

    cheers
    mastero
     
  9. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,304
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    Just for future reference.. Post the entire code... Makes it easier for us to help you!!
     
    • Agree Agree x 1

Share This Page