Using Music Shield with Cerbuino Bee

// From:
// This is for FEZ Panda II
// MusicShield musicShield = new MusicShield(SPI.SPI_module.SPI1, FEZ_Pin.Digital.An4, FEZ_Pin.Digital.An5, FEZ_Pin.Digital.Di4);

// This is for FEZ Bee?
   MusicShield musicShield = new MusicShield(SPI.SPI_module.SPI1, (Cpu.Pin)0x21, (Cpu.Pin)0x04, (Cpu.Pin)0x2F);

Debug.Print("Testing Playback...");
FileStream fs = new System.IO.FileStream(@ "\SD\song.wma", System.IO.FileMode.Open);

I am trying to use the MusicShield with the Cerbuino Bee. I have the code successfully working with the Panda II, but with the Cerbunio Bee, the music plays for about 1 second and then stops. While debugging, the code just stops. VS says the project is still running. Nothing in the output states the thread has exited. The main loop is in an infinate loop. It appears the code just freezes. If I step through the code, it just freezes.

Am I using the right pins? Is the Music Module supported? How different is the music module from the music shield?

Also, I am using the Ethernet Module connected to Socket 1. Maybe there is a conflict?

If I disconnect the ethernet cable, playback works as expected. So, it appears there is a conflict. Any ideas how to resolve the conflict?

Can I use the Music Module and Ethernet Module together? Is there an example how to use the Music Module?

Investigating further, both the music module and ethernet use socket S. :frowning:

S Socket just means you need to do a custom job on one of them. The CS pin being shared is your problem, if you can jumper that to pin 3/4/5 on one of the modules you’ll be fine. That may require voiding the warranty on one of the devices so choose wisely :slight_smile:

That maybe a great option. Can you clarify what pin? I don’t see CS listed on the pin chart.

Check out S socket pinout here:

I am using the Cerbuino Bee and the original music shield. The music shield is configured to use A4 and A5.

private static MusicShield musicShield = new MusicShield(SPI.SPI_module.SPI1, (Cpu.Pin)0x21, (Cpu.Pin)0x04, (Cpu.Pin)0x2F);

Which calls

   public MusicShield(SPI.SPI_module spi, Cpu.Pin dataCS, Cpu.Pin cmdCS, Cpu.Pin DREQ) 
        _dataConfig = new SPI.Configuration( (Cpu.Pin)dataCS, false, 0, 0, false, true, 2000, spi, (Cpu.Pin)DREQ, false );
        _cmdConfig = new SPI.Configuration( (Cpu.Pin)cmdCS, false, 0, 0, false, true, 2000, spi, (Cpu.Pin)DREQ, false );
        _dreq = new InputPort( (Cpu.Pin)DREQ, false, Port.ResistorMode.PullUp );
        _spi = new SPI( _dataConfig );

I don't think I am sharing CS, but not sure. 

ENC28 on socket 1 (S)
Socket 1, Pin 6 = PA13 

Music Shield
AN4 = PC1
AN5 = PA4

Reading through the following article,"The SPI object on NETMF is a representation of the "bus" and not the "device", and so you can't construct multiple SPI object, unless it uses a different SPI bus."

So, if the Cerbunio Bee only has one SPI bus, is it possible to share the bus between the ENC28 and the music shield?  Thanks.

The code in that page shows how you need to do this - well at least how it needs to happen in 4.1 as I suspect that code is a bit old. It also is the netmf way, I don’t know if Gadgeteer abstracted that again for you. But ultimately, you just need to “set up” your devices individually, then “set” each one as you need to use it. If the drivers respect that, then there won’t be an issue.

May I ask why you use these:

Aren’t there nicer enumerations that have a descriptive name like ? At a minimum you should try to use the PA3/PB1 notations - I don’t have a cerbuino but I can’t easily tell what 0x2f is!

Brett, thanks for the reply.

With the ENC28, I don’t setup SPI. It appears this is all abstracted from me. Not sure.

I am using the following to setup the network. Once I have the NI, I am creating and binding to a network socket.

  Microsoft.SPOT.Net.NetworkInformation.NetworkInterface NI = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0];

You are correct about using better enumerations. Not the best example.

I am still having issues with this and am having similar issues as described here:

The music shield is using AN4 (dataCS), AN5 (cmdCS) and D4 (DREQ). The ENC28 module is connected to socket 1. The following is the code I am using to define the SPI for the music shield.

            _dataConfig = new SPI.Configuration( (Cpu.Pin)dataCS, false, 0, 0, false, true, 2000, spi, (Cpu.Pin)DREQ, false );
            _cmdConfig = new SPI.Configuration( (Cpu.Pin)cmdCS, false, 0, 0, false, true, 2000, spi, (Cpu.Pin)DREQ, false );
            _dreq = new InputPort( (Cpu.Pin)DREQ, false, Port.ResistorMode.PullUp );

I can setup the MP3 shield and playback will start, but freezes after a couple of seconds. Prior to sending data to the MP3 shield, I set the SPI config.

       _spi.Config = _dataConfig;

If I disconnect the network cable prior to MP3 playback, the code run fine. I am fairly confident the music shield and the ENC28 are using differnt CS pins.

I am using the following code to init the network. Works fine.

I updated to the lasted firmware that was posted Nov 29th.

Any suggestions? I have done everything I can think of at this point.

Do you have an oscilloscope? Perhaps you can see what is going on with that, but I don’t know if it’ll get you very far.

Might be time to open up the cerbuino netmf code and start checking that I think.

I worked on getting a simplified repro and reduced to the following.

The following code works if the network cable is unplugged. It stops after a few secs with the network cable plugged in. It doesn’t matter if the network is initalized or not.

If I comment out the MountSD and file stream lines, the code also works.

So, it appears there is a conflict with the SD card, ENC28 and A4.

I then modified the code to use A3 and it appears to work. Now I just need mod the shield to try and use A3 vs A4.

        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");

         //   Doesn't matter if network is init or not.
         //   InitializeNetwork();


            FileStream fs;
            fs = new System.IO.FileStream(@ "\SD\" + msPlay + "mp3", System.IO.FileMode.Open, FileAccess.Read, FileShare.Read);

            byte[] block = new byte[8];

            _dataConfig = new SPI.Configuration(Pins.A4, false, 0, 0, false, true, 2000, SPI.SPI_module.SPI1, Pins.D4, false);

            _spi = new SPI(_dataConfig);

            for (int x = 0; x < (5000); x++)
                _spi.Config = _dataConfig;
                Debug.Print("MP3 Write: " + x.ToString());

Not sure if this helps but Ethernet is power hungry. Are you using a powered hub or a power pack? USB itself is not enough.

Gus, I added the power supply and retested. Same results. I also tried running the music shield on a different pin and had the same results. I did test same code on a different board, and it worked fine. This leads me to believe the issue is with the firmware.

OK, so how about completely moving the pins the music shield uses? you’ll need to rewire it somehow but that should help you test it.

I tried this too. I used jumper wires and connected all of the pins. Kind of odd because music playback wasn’t as smooth, but I am assuming I am impacting the performance of SPI based on the distance of the wires. I couldn’t figure out a good way to test this without using the jumper wires. I tried different combinations of pins. I had the same issue. After about 2 seconds of playback, the device would hang.

This is still an issue with the board, but similar logic works well on the Netduino. Is there an official way to report this issue with the idea it could be fixed in the future? I am happy to try and reduce the issue further if needed. This board would be able perfect if I could use these two modules together.

What other spi port did you try?