SPE035 "DF Player" Reading track data from SD Card or USB

1968neil

Senior Member
Hi Folks,
It's been a while since i last posted,
Can anyone help with the following ?

I have a working set up with an LCD all working fine etc etc
What i need to do is display the number of tracks at initialisation of the SPE035 Module and inset them into a variable.
Possibly the device it reads from would also be handy (SD or USB stick as both are available on my set up).

This is so when the unit boots it looks at the module checks how many tracks are on it and displays it on the LCD.
I can find no reference to this on the datasheet i have ?
Any help would be appreciated

Regards
Neil
 

tmfkam

Senior Member
Depending on the storage system you used on the disk, you might find the value(s) returned includes a count of the folders and or other files found on the disk. From memory, if two disks are present at the same time, values for one, other or both could be inaccurate.

I also found that if a uSD card was fitted, the player defaulted to it, automatically switching to USB if one was present and no uSD card was found. Manually trying to select USB with a uSD card installed was very unreliable for me.
 

1968neil

Senior Member
Many thanks Guy's.
I missed the extra datasheet !
A great little module, i have used it in many projects for speech and find it very reliable.
Will be nice to get some info back from the module and be able to display it whilst figuring out the next steps of my project.
If i ever get enough spare time to proceed any further.

Thanks again
Regards
Neil
 

tmfkam

Senior Member
These are the routines I am using to fetch the track count in my 'Mini Jukebox'. This has over 7,500 MP3 files on it, stored in a folder called 'MP3', with the tracks named 0001.mp3, 0002.mp3 ... 9999.mp3.

These were pulled from another dialect of BASIC, so some syntactical changes will need to be made in order to PicAxe-ify them, but will hopefully give some idea of how to use the commands.

C:
Sub Fetch_Tracks

    SerSend 1, 0x7e
    SerSend 1, 0xff
    SerSend 1, 0x06
    SerSend 1, 0x48 'Command for track query uSD disk
    SerSend 1, 0x00 'Return value request
    SerSend 1, 0x00
    SerSend 1, 0x00
    SerSend 1, 0xef
    Serial_Fetch

    'If there are no tracks (folders) found on uSD, try USB
    If ReturnTracks < 1 Then
        Wait 100 mS
        SerSend 1, 0x7e
        SerSend 1, 0xff
        SerSend 1, 0x06
        SerSend 1, 0x47 'Command for track query USB
        SerSend 1, 0x00 'Return value request
        SerSend 1, 0x00
        SerSend 1, 0x00
        SerSend 1, 0xef
        Serial_Fetch
    End If

    'If there are no tracks (folders) found on USB, try Flash disk
    If ReturnTracks < 1 Then
        Wait 100 mS
        SerSend 1, 0x7e
        SerSend 1, 0xff
        SerSend 1, 0x06
        SerSend 1, 0x49 'Command for track query Flash disk
        SerSend 1, 0x00 'Return value request
        SerSend 1, 0x00
        SerSend 1, 0x00
        SerSend 1, 0xef
        Serial_Fetch
    End If

    Wait 100 mS
End Sub

Sub Serial_Fetch

    Let ReturnTracks = 0

    SerReceive 1, SerData(1) '0x7e
    SerReceive 1, SerData(2) '0xff
    SerReceive 1, SerData(3) '0x06
    SerReceive 1, SerData(4)
    SerReceive 1, SerData(5)
    SerReceive 1, SerData(6) 'High Byte of track count
    SerReceive 1, SerData(7) 'Low  Byte of track count
    SerReceive 1, SerData(8) '0xef

'    Locate 1, 0
'    Print SerData(4)'Indicates disk? 72=microSD 71=USB?
'    Print ":"
'    Print SerData(6)
'    Print ":"
'    Print SerData(7)
'    Print "                "
'    Wait 1000 mS

    If SerData(6) > 0 Then
          Let ReturnTracks = SerData(6)
          Let ReturnTracks = ReturnTracks * 256 'High Byte
    End If

    If SerData(7) > 0 Then
          Let ReturnTracks = ReturnTracks + SerData(7) 'Low Byte
    End If

End Sub
It looks as though SerData is an eight byte array. There is no flash disk on the SPE035 so I'm not sure what value is returned by it.

I use this to set the maximum playable track number which allows me to limit the range of random numbers when playing the tracks in random sequence. Where no track numbers are returned, I set this to 9999 and should a track not be found, reduce the maximum down. This worked well, but when playing a disk with a relatively low number of tracks (250 or so for example) the gap between played tracks could be rather long before a valid track was randomly selected. Querying the actual number of tracks works much better.

If you can't figure out the code, let me know and I'll try and decipher it for you.
 

hippy

Senior Member
These were pulled from another dialect of BASIC, so some syntactical changes will need to be made in order to PicAxe-ify them, but will hopefully give some idea of how to use the commands.
Thanks for that. In our SPE035 samples for PE6, for sending we use ...
Code:
Send:
  SetFreq BAUD_FREQ
  Pause 10
  SerOut TX, BAUD, ( $7E, $FF, $06, cmd, $00, arg.msb, arg.lsb, $EF )
  SetFreq MDEFAULT
  arg = 0
  Return
And I think that can be modified to receive a reply with something like, no error checking done ...
Code:
cmd = $47
Gosub SendAndReceiveReply
SerTxd( "Tracks=", #arg, CR, LF )
End

SendAndReceiveReply:
  SetFreq BAUD_FREQ
  Pause 10
  SerOut TX, BAUD, ( $7E, $FF, $06, cmd, $00, arg.msb, arg.lsb, $EF )
  SerIn  RX, BAUD,   arg, arg, arg, arg, arg, arg.msb, arg.lsb
  SetFreq MDEFAULT
  Return
 

1968neil

Senior Member
Thanks guys,
Will report back when I get a spare hour or two to try out the suggestions.
Regards
Neil
 
Top