​ ​ ​ ​ Missing Serial Signal
Results 1 to 5 of 5

Thread: Missing Serial Signal

  1. #1
    New Member
    Join Date
    Feb 2018
    Location
    Rotterdam
    Posts
    2

    Lightbulb Missing Serial Signal

    I use the 20x2 with a MP3 Trigger. If I play a song, and the song ends, the MP3 trigger sends a serial signal, lets say "X", to the 20x2. But when I use the picaxe for a project where the picaxe is busy with a lot of other data he is missing the X. and I can't use interrupt because the program needs to go on. Is there a memory buffer where the X is saved and I can read the data? or is there another way?


    I hope you can help me !

  2. #2
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    24,346

    Default

    Welcome to the PICAXE forum

    You can use HSERSETUP and the background serial receive capability of the PICAXE devices to read serial data while busy doing something else. For the 20X2 there is a buffer which can retain the last 128 bytes sent so you could look for your "X" being sent while the PICAXE is busy using something like ...

    Code:
    HSerSetup B9600_8,%001
    Gosub SendCommand
    Gosub DoSomethingElse
    Do
      Do : Loop While ptr = hSerPtr
    Loop Until @ptrInc = "X"
    Gosub GotTheX

  3. #3
    New Member
    Join Date
    Feb 2018
    Location
    Rotterdam
    Posts
    2

    Default

    thank you for your answer!
    But I have asked the question wrong ...
    I have a main loop, in this loop I have 4 things to do, one of those things is listen when the MP3 is done with the song he played.
    When the MP3 is done, he sends "X" but if the picaxe is busy with things 2 or 3, he miss the signal from the MP3. but he needs to go on with the main loop.
    I guess I need something like a double check. but I don't know how I can make that without making a : loop until

  4. #4
    Senior Member
    Join Date
    Jan 1970
    Location
    Nova Scotia, Canada
    Posts
    2,815

    Default

    hippy's reply gives you what you need; you use HSERSETUP to make serial input on the hserin pin (B.6 on the 20X2) directed behind the scenes to the scratchpad. In your main loop which does 4 things, one of the things is to check the scratchpad to see if an "X" has been received.

    And welcome to the forum.

  5. #5
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    24,346

    Default

    Quote Originally Posted by quinlanvh View Post
    When the MP3 is done, he sends "X" but if the picaxe is busy with things 2 or 3, he miss the signal from the MP3. but he needs to go on with the main loop.
    I guess I need something like a double check. but I don't know how I can make that without making a : loop until
    You can make the code a subroutine which checks whether there has been an "X" received or not. In this case variable b0 will be set to 1 when an "X" has been received and 0 when not -

    Code:
    CheckForX:
      b0 = 0
      Do While ptr <> hSerPtr
         If @ptrInc = "X" Then
           b0 = 1
        End If
      Loop
      Return
    Then, while doing other things you can call that code, look at the result and then act on whether b0 is 1 or 0 ...

    Code:
    MyLoop:
      Gosub DoSomeThings
      Gosub CheckForX
      If b0 = 1 Then GotAnX
      Goto MyLoop
    You could also interrupt when any character is received, set a flag when it has been and it's an "X", so you don't have to explicitly call the 'CheckForX' routine.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •