Announcement

Collapse
No announcement yet.

hserout not being cleared/repeats last send

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • hserout not being cleared/repeats last send

    Hello guys;
    I've been having this problem for some time. (I'm also not an expert in basic)
    Basically hserout repeats the last send and I'm not exactly sure if its due to the fact that its not being cleared or if it is actually running slower than the main basic program.
    Any pointers would be greatly appreciated.

    updateLEDs:
    select case gesture
    case 0 ' no gesture
    case 1 ' hold left
    hserout ["hleft", 13]
    gosub LED_holdLeft
    PAUSE 1000
    case 2 ' hold center
    hserout ["hcenter", 13]
    ledCount = ledCount + 1
    if (ledCount = 3) then
    gosub LED_holdCenter
    gesture = 0
    pause rtime
    elseif (ledCount = 6) then
    ledCount = 0
    gosub LED_off
    pause rtime
    endif
    case 3 ' hold right
    hserout ["hright", 13]
    gosub LED_holdRight
    PAUSE 1000
    case 4 ' left
    hserout ["sleft", 13]
    gosub LED_swipeLeft
    pause rtime
    case 5 ' right
    hserout ["sright", 13]
    gosub LED_swipeRight
    pause rtime
    case 6 ' center press
    hserout ["press_center", 13]
    gosub LED_pressCenter
    gosub clearDistance
    pause rtime
    end select
    gesture = 0
    return

    Thanks in advance.

  • #2
    What PIC processor are you using? Please list your SFRs related to UART & OSC as well as your TRISx listings. Sometimes issues are buried deep under something seemingly totally related. Your code doesn't suggest the issue you're experiencing.
    We can crack this cotton PIC'n thang!

    Comment


    • #3
      Originally posted by mpgmike View Post
      What PIC processor are you using? Please list your SFRs related to UART & OSC as well as your TRISx listings. Sometimes issues are buried deep under something seemingly totally related. Your code doesn't suggest the issue you're experiencing.
      Thanks Mike for you quick reply;

      PIC16F15375

      #CONFIG
      __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINTPLL & _CLKOUTEN_OFF & _CSWEN_OFF & _FCMEN_OFF
      __config _CONFIG2, _MCLRE_ON & _PWRTE_ON & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON
      __config _CONFIG3, _WDTCPS_WDTCPS_11 & _WDTE_ON & _WDTCWS_WDTCWS_6 & _WDTCCS_SC
      __config _CONFIG4, _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTSAF_OFF & _LVP_OFF
      __config _CONFIG5, _CP_OFF
      #ENDCONFIG

      DEFINE OSC 32 'Define ocillator speed
      ' Maps Rx2 and Tx2 to B7 and B6
      define HSER2_RXREG PORTB
      define HSER2_RXBIT 7
      define HSER2_TXREG PORTB
      define HSER2_TXBIT 6

      DEFINE HSER_RCSTA 90h ' Enables Receive UART
      DEFINE HSER_TXSTA 20h ' Enables Transmit UART(Default 20h, 24h@4MHz)
      DEFINE HSER_BAUD 9600 ' Sets Baud Rate to 9600BPS
      Define HSER_CLROERR 1 ' Clear the HUART if it buffer fills up

      DEFINE HSER2_RCSTA 90h ' Enables Receive UART
      DEFINE HSER2_TXSTA 20h ' Enables Transmit UART(Default 20h, 24h@4MHz)
      DEFINE HSER2_BAUD 9600 ' Sets Baud Rate to 9600BPS
      Define HSER2_CLROERR 1 ' Clear the HUART if it buffer fills up

      ' Inputs OR outputs
      TRISA = %00111111 ' Inputs = 1, Outputs = 0
      TRISB = %10000000 ' Inputs = 1, Outputs = 0
      TRISC = %10000000 ' Inputs = 1, Outputs = 0
      TRISD = %11111111 ' Inputs = 1, Outputs = 0
      TRISE = %00000000


      readAddr = $53
      writeAddr = $52

      the full code listing is here https://pastebin.com/KSJBDX60

      Thanks again

      Comment


      • #4
        Other useful information:
        https://gputils.sourceforge.io/html-...5375-feat.html
        https://gputils.sourceforge.io/html-...15375-sfr.html

        Comment


        • #5
          For starters, for UART both RX & TX pins should be declared as Inputs in the TRIS registers. You have TX labeled as an Output.

          I started making a rather long list of observations when I realized that much of the code is commented out. It was originally included for some reason, perhaps as an option. Check over what is commented out, and un-comment functions you need for what you're doing (if you haven't already). You may be getting wrong transmissions because the function that was intended to update the values was commented out.
          We can crack this cotton PIC'n thang!

          Comment


          • #6
            Mpgmike, Alevis has the TRISB port definitions set correctly. Why would you set the TX port pin on the micro to an input, when it is used as an output. One thing I notice is that some lines are missing such as the defines for the primary HSER TX and RX port pins.
            Dave Purola,
            N8NTA
            EN82fn

            Comment


            • #7
              if you read the data sheet you will see that clearing the tx tris bit is unnecessary , on some chips clearing it will stop proper eusart operation

              33.1.1.1 Enabling the Transmitter
              The EUSART transmitter is enabled for asynchronous
              operations by configuring the following three control
              bits:
              Last edited by richard; 1 week ago.

              Comment


              • #8
                33.1.1.1 Enabling the Transmitter
                The EUSART transmitter is enabled for asynchronous
                operations by configuring the following three control
                bits:

                Comment


                • #9
                  i give up cannot paste text here any longer

                  Comment


                  • #10
                    Originally posted by richard View Post
                    i give up cannot paste text here any longer
                    Hi Richard,
                    Thanks for the reply did you mean:
                    • TXEN 1
                    • SYNC 0
                    • SPEN 1
                    Last edited by alevis; 1 week ago.

                    Comment


                    • #11
                      i was trying to post the relevant section from the data sheet

                      but it does not display on the forum when pasted tnto message

                      Comment


                      • #12
                        33.1.1.1 Enabling the Transmitter
                        The EUSART transmitter is enabled for asynchronous
                        operations by configuring the following three control
                        bits:
                        • TXEN = 1
                        • SYNC = 0
                        • SPEN = 1
                        All other EUSART control bits are assumed to be in
                        their default state.
                        Setting the TXEN bit of the TXxSTA register enables the
                        transmitter circuitry of the EUSART. Clearing the SYNC
                        bit of the TXxSTA register configures the EUSART for
                        asynchronous operation. Setting the SPEN bit of the
                        RCxSTA register enables the EUSART and
                        automatically configures the TX/CK I/O pin as an output.
                        If the TX/CK pin is shared with an analog peripheral, the
                        analog I/O function must be disabled by clearing the
                        corresponding ANSEL bit.
                        Last edited by richard; 1 week ago. Reason: finally got it

                        Comment


                        • #13
                          Basically hserout repeats the last send
                          Alevis, exactly what do you mean by that? Could you show us an example of what you're seeing?

                          Comment


                          • #14
                            Originally posted by tumbleweed View Post
                            Alevis, exactly what do you mean by that? Could you show us an example of what you're seeing?
                            I'm using a tof sensor to detect hand gestures, then from that send out an ascii string based on the gesture detected.
                            2 ascii strings get printed out instead of 1 for each gesture

                            Comment


                            • #15
                              Which message is being sent out twice? It helps to locate the problem area.
                              Dave Purola,
                              N8NTA
                              EN82fn

                              Comment

                              Working...
                              X