Announcement

Collapse
No announcement yet.

Testing for ACK and NAK

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

  • Testing for ACK and NAK

    All,



    I have been using a PIC24F32KA301 microcontroller to control a microOLED-128-G1. Overall, I have been getting slightly flaky and very slow performance,.... but overall decent results.



    I have been trying to create a compass needle that essentially always points North even as the user rotates the compass in different directions. I want the needle to move smoothly.



    Since the beginning of this project, I was sharing a UART with a GPS receiver, so I could never test for ACK/NAK from the microOLED-128-G1. So in order to make the OLED function properly, I had to place a bunch of delays on the order of 10ms to 50ms througout my code.



    In my post last night, the moderator said that removing the delays and testing testing for ACK/NAK would speed up the graphics. So I removed the GPS receiver and connected the Tx line of the OLED back to my microcontroller's Rx pin (on the UART of the microcontroller). I also placed my logic analyzer on the same pin and I discovered that I have been receiving only a couple of ACK's (06hex) and MANY NAK's (15hex).



    WHY???



    See the attached snapshot of the OLED. Line start randomly appearing all over the display. What could be causing this.



    TIA.


    Attached files
    TIA,

    Neal

  • #2


    Generally that would happen if you are sending some invalid commands.



    The display is simply receiving a continuous never ending string. Once it has something that it understands it processes it and sends an ACK (assuming it was a valid command and the response was ACK), if it gets something it doesn't understand it sends a NAK.



    To illustrate consider a hypothtical controller that accepts three commands A B and C, A takes 1 parameter, B takes 2 and C takes 3. Say this was sent.



    A1B12C123



    The controller would send back three ACKS, now say this was sent



    A12B12C123



    What would the controller send back?



    ACK, NAK, ACK, ACK



    and this?



    B1A1C123



    ACK, NAK, ACK



    Check that what you are sending is correct and the correct length.



    Usually the easiest way to work out what is wrong is check that you get a response to every command and what that response is.



    If the first 'error' is a missing response then you are probably a parameter short, if the first 'error' is a double (or more) response then you may have either sent too much as part of the current command, or as part of the previous command.
    Mark

    Comment


    • #3


      Dear Moderator,



      Please see some sample code in the attachment. All of this code has worked with the delays placed throughout my code.



      As soon as I started testing for ACK/NAK, and connecting my logic analyzer to the transmit pin of the OLED, I started seeing the NAK's.



      And yes. I started using individual commands in main() and testing them one by one. Once again flaky behavior.



      And my background changes color from white to blue...and then a bunch of lines and then half the display will turn green and the other half purple. Weird stuff.



      My microcontroller is functioning with an oscillator frequency of 32MHz and baud rate on the UART is 4800.



      Please let me know your thoughts.



      TIA.


      Attached files lcd_ack_nak.txt (3.4 KB)
      TIA,

      Neal

      Comment


      • #4


        That looks OK as far as I can see, but I can't see introScreen() or ack()
        Mark

        Comment


        • #5


          Dear Moderator,



          See attached.


          Attached files intro_bounce_ack.txt (1.2 KB)
          TIA,

          Neal

          Comment


          • #6


            That looks OK to, but it's really hard to find the error from where I sit, just looking at bits of code written by someone else.



            Could it be that there's rubbish in the UART Q at the start that is being read as ACKs and NAKs. Can you flush it before you start the autobaud?



            As I said you need to check what you are sending when you get the first NAK, or what you sent immediately prior.



            If you have a scope and can align TX and RX together that will probaly help even more.



            You background changes are tending to indicate your are not waiting for the ACK properly, but really it's probably just another effect of whatever is 'wrong'
            Mark

            Comment


            • #7


              Dear Moderator,



              Yes I have a scope and a logic analyzer. I will play with this some more over the coming days. I think that my brain needs a break from this.



              I will have to figure out how to flush the UART queue. Probably check to see if there is any data waiting in the transmit shift register. If there is, then maybe pop the data off of the transmit register FIFO.



              Thank you for your help.
              TIA,

              Neal

              Comment

              Working...
              X