uMP3_SYNC

This routine will synchronize the Basic Stamp to the uMP3. The routine sends an ASCII ESC (27 decimal, 0x1b hex) to the uMP3, which will clear its buffer and return the command prompt.

uMP3_SYNC:
  loopvar1 = 0
uMP3_SYNC_AGAIN:
  SEROUT UMP3R, uMP3Baud, [27]  ' Send an ESC to clear the buffer
  SERIN UMP3T, uMP3Baud, uMP3StartUpTimeOut, uMP3_SYNC_Error, [STR buffer\1]
  IF buffer(0) = ">" THEN GOTO uMP3_SYNC_Complete
uMP3_SYNC_Error:
  loopvar1 = loopvar1 + 1
  DEBUG "uMP3 Sync Error: Bad/No response - check ST R (minimum 5)", CR
  IF loopvar1 > 3 THEN GOTO uMP3_SYNC_Error_2
  GOTO uMP3_SYNC_AGAIN
uMP3_SYNC_Error_2:
  DEBUG "uMP3 Sync Error: Too many retries - check ST R, or ST D (Baud)", CR
  GOTO uMP3_SYNC_End
uMP3_SYNC_Complete:
  DEBUG "uMP3 Synchronized", CR
uMP3_SYNC_End:
  RETURN

uMP3StartUpTimeOut is the amount of time (in milliseconds) that the Basic Stamp should wait before assuming there is no response. You should ensure that this time takes into consideration the amount of start up time that the uMP3 may require depending on the card you use, the file system format, and the amount of files you have on the card. The amount of time can vary widely. Just watch to see how long the Activity LED on the uMP3 stays on when you apply power to the uMP3.