Shop OBEX P1 Docs P2 Docs Learn Events
Working with serial devices... — Parallax Forums

Working with serial devices...

ZachariahZachariah Posts: 6
edited 2011-12-20 14:55 in BASIC Stamp
Well hello forums people. Not to sounds as if I am sucking up but I would like to thank all the people that post on these forums. I have been using them to answer my question on many of my projects.
Okay down to business. I just got a SOMO-14D chip.

http://microcontrollershop.com/product_info.php?products_id=4360

there is already a post about this chip on these forums.

http://forums.parallax.com/showthread.php?122204-Help-with-a-sound-effect-device&highlight=SOMO-14D


This has really got me working in the right direction on getting my Basic Stamp Board to interact and operate the SOMO-14D chip.


However, I seem to be only able to get the first audio file to play over and over. Despite what code I put it.
'{$STAMP BS2} 'Stamp directive
 '{$PBASIC 2.5} 'PBASIC directive
 '----------{SOHO 14D Audio Module Commands}-----------------
 'Play/Pause FFFEh
 'Stop FFFFh
 'Volume FFF0h-FF7h (In terms of volume)
 'Songs 0000h,0001h,0002h,0003h,0004h
 'PIN 1 NEXT
 'PIN 2 NC
 'PIN 3 CLK
 'PIN 4 DATA
 'PIN 5 BUSY
 'PIN 6 PLAY/STOP
 'PIN 7 PREVIOUS
 'PIN 8 VCC
 'PIN 9 GND
 'PIN 10 RESET
 'PIN 11 SPK+
 'PIN 12 SPK-
 'PIN 13 NC
 'PIN 14 AUDIO
 DEBUG CR, "Program Running"
 '----------{I/O}--------------------------------------------
 Data1 PIN 1
 Clock PIN 2
 '----------{Initialization}---------------------------------
 Main:
 DEBUG CR, "Initialization"
 HIGH Clock
 LOW Data1
 SHIFTOUT Data1, Clock, MSBFIRST , [16\$FFF2] 'Set Volume to 3 of 7
 GOSUB StartMusic
 PAUSE 5000

 StartMusic:
 DEBUG CR, "Playing First Song"
 SHIFTOUT Data1, Clock, MSBFIRST , [16\$FFFE] 'Play
 PAUSE 1000
 DEBUG CR, "Playing Second Song"
 SHIFTOUT Data1, Clock, MSBFIRST , [16\$0001] 'Play Second Song
 PAUSE 1000
 RETURN



I am trying to dumb down the code so that I can just get it to do what I want.

What I am having problems with is when I send the command for "Play/Pause" (HEX FFFE) the first file plays. However, when I send any hex code from 0012 - FFFE the first song will play. Then if I send hex code 0000 - 0010 nothing will happen and if I send hex code 0011 the second song plays.

Thank you for your time!

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2011-12-17 15:07
    Hi and welcome to the forums, one of the first things I see is that the data and number of bits are transposed in the shiftout instruction

    should be

    [$FFFE\16]

    not

    [16\$FFFE]

    Jeff T.
  • ZachariahZachariah Posts: 6
    edited 2011-12-17 21:29
    O I should have mentioned that in the first post. In the help menu it shows that the SHIFTOUT show be like this

    Syntax: SHIFTOUT Dpin, Cpin, Mode, [OutputData {\Bits} {,OutputData {\Bits}...}]

    So like you have said. However, in my trouble shooting I figured out that if I put it how the help said to if would not play anything. Then when I wrote it with the bits declared first it would play... sometimes.
    So, yes, I agree with you.

    Thank you for your help!
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2011-12-18 07:44
    Hi, I don't have any experience with your sound device so I'm groping in the dark a little here. My thought was that the song should be selected before you send the command to play not after. So here is your BS2 file modified to select and play file #2, check it out and see if it works.

    Jeff T.
  • PublisonPublison Posts: 12,366
    edited 2011-12-18 09:20
    Why the Poll?
  • ZachariahZachariah Posts: 6
    edited 2011-12-18 10:25
    Unsoundcode,
    I tried your corrections and sorry to say there is no change. In the datasheet is says that if you the Play/Pause signal is sent to the chip it will automatically start playing the first audio file or continue playing the file that was paused.

    Publison,
    This is my first time posting on this website and I did not know what the polling was for. I first though people could rate how well I am answering peoples questions that are trying to help me. I see now that I may have been mistaken.
  • PublisonPublison Posts: 12,366
    edited 2011-12-18 10:34
    Not a problem :smile:

    And welcome to the forums!
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2011-12-18 13:47
    Hi, you say no change, can you give us a little more information, did anything play?

    Jeff T.
  • ZachariahZachariah Posts: 6
    edited 2011-12-18 14:00
    No there is no change. As in it will not play any audio file when I have the code as Unsoundcode recommended. What he recommended is correct. In that is to change the OutputData {\Bits} to how the help menu shows.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-12-18 14:22
    Is the use of SHIFTOUT appropriate for this device?

    From the SOMO manual:
    When communication is required, the CLK is
    brought LOW for a period of 2ms (START bit wait
    time).
    Each individual data bit (starting with the
    MSB bit15) is then clocked in sequentially. The
    data is latched on every rising edge of the clock.
    When the last data bit (bit0) is clocked in the CLK
    signal must be held high for a period of 2ms (STOP
    bit wait time) before the next command data is
    sent. The clock HIGH and LOW periods are 100us
    minimum.

    Refer to “Section 7. Timing Diagrams“ for more
    detailed timing and waveform information.

    That's some slow data!
    The CLOCK timing from SHIFTOUT (BS2) is 14us HI and 46us LO (60us total).

    I think this will have to be bit-banged, PULSOUT will be a good option.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2011-12-18 14:27
    I would be inclined to configure the sound device for key mode just to verify the hardware, remove the wires from pins 3,4 and 10 and by momentarily grounding pin 6 the first audio file should play. If it does then momentarily ground pin 1 and the next file should play.

    If this does not happen there is a hardware,wiring or SD problem.

    Jeff T.
  • ZachariahZachariah Posts: 6
    edited 2011-12-18 16:25
    Unsoundcode,
    I did that when I first got the chip to test that it worked and test that the Vcc off of the Basic Stamp board 5v down to 3.5v. I removed everything and tested it again and it works just fine. When I momentarily ground the pin 6 (play/pause) the first audio file plays. The first audio file plays every time I momentarily ground pin 6. Then when I momentarily ground pin 1 (Next) the next file plays. I have three audio files and if I continue momentarily ground pin 1 it will just keep cycling threw them. Then if I remove power and reapply power, then momentarily ground pin 1 it starts from the second audio file.

    So the chip works and I checked power again also and everything is good with that... I think.

    Next I am going to look into using the PULSOUT. I will start reading up but the first question that I will have, before I have start reading up on PULSOUT. If I control the Clock with PULSOUT will I have to use that for the Data also? I mean control every bit that is sent, so as to slow everything down?

    Next I am going to look into using the PULSOUT. I will start reading up but the first question that I will have, before I have start reading up on PULSOUT. If I control the Clock with PULSOUT will I have to use that for the Data also? I mean control every bit that is sent, so as to slow everything down?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-12-18 16:48
    Next I am going to look into using the PULSOUT. I will start reading up but the first question that I will have, before I have start reading up on PULSOUT. If I control the Clock with PULSOUT will I have to use that for the Data also? I mean control every bit that is sent, so as to slow everything down?

    Yes, totally.

    Those are some slow-*** times (and they're MIN). The 2ms LO isn't part of the SHIFTOUT regime, neither those 100us_HI,/100us_LO clocks. SHIFTOUT speed is >> that. The data rate approximates 4800bps, but that clock held LO part... Carumba!
    You present the data bit, and there's a minimum hold-up time for that, then you bring your clock HI, hold it, then send it back LO, and mind your end of data 2msec, too.

    ** Post Edit **
    Been thinking about this.
    I think it'll work out better using LOW pin, DELAY val and HIGH pin, DELAY val instead of PULSOUT.
  • ZachariahZachariah Posts: 6
    edited 2011-12-20 05:32
    Great news everyone! PJ Allen proved to be smarter than I. Not that it was ever in question. I have the chip working now. So if anyone else gets this chip I will post my code as of right now so people can look through it. Then when I am done with my more detailed code I will post again so others may use it or learn from this post as well. Thanks for all the help!
    Also as a side not, for some reason I am getting this slight "feed back" or clicking sounds when the microcontroller is sending data to the audio chip. I did not mention it before because I did not want to cruder my programming question with the electrical issues. I assume it is just one of the inputs on the audio chip getting bleed off from the data lines since I am using a resistor to ground to lower the voltage of the output. After I figure that out also I will post a schismatic and photos for all to enjoy.

    HAPPY HOLIDAYS!
    DEBUG CR, "Program Running"
             '----------{I/O}--------------------------------------------
              Busy              PIN         4
              Data1             PIN         3
              Clock             PIN         2
              Reset             PIN         0
             '----------{Variables}--------------------------------------
             Volume            VAR          Word
             '----------{Initialization}---------------------------------
             Main:
             DEBUG CR, "Initialization"
              Volume = $FFF0
              PULSOUT Reset,2500                                  'Reset Pulse Width
               DO
    
                 GOSUB SendData
                 SHIFTOUT  Data1, Clock, MSBFIRST , [Volume\16]   'Set volume
                 HIGH Clock                                       'Data Send Completed
                 PAUSE 1000
                 GOSUB SendData
                 SHIFTOUT  Data1, Clock, MSBFIRST , [$0000\16]    'Play first audio file
                 HIGH Clock                                       'Data Send Completed
                 Volume = Volume + 1
                 DEBUG CR, HEX Volume
                 PAUSE 2000
               LOOP WHILE Volume < $FFF8
             END
    
             SendData:
              HIGH Clock             'Reset idle to start bit
              PAUSE 300
              LOW Clock              'Start bit low level pulse width
              PAUSE 1
              HIGH data1             'On Mid Clock low pulse, Data1 High for start of Write data setup
              PAUSE 1
             RETURN
    
    [ATTACH]87789[/ATTACH]
    
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-12-20 14:55
    Well, it basically looks like all you had to do was take care of that long "start bit" time.
    SHIFTOUT worked for the rest.
    (Funny.)
    So, you're happening; good deal.
Sign In or Register to comment.