SCK and SPI question ?

Go To Last Post
30 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Guys,

 

Is the right SCK clock on my SPI bus ?

I tried to see in Logic analyzer, some of them can't be read properly....

Am I sending the right SCK clock or wrong one ? Why isn't SCK constantly sent per byte ?? I can see only 4 edges per byte ?

 

How to fix it ?

Please have a look on the picture :

 

 

The code :

void VS1003B_SPI_Low(void)
{

	SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<SPR0);
	SPSR = (0<<SPI2X);
}

//ÒÔFCK/4ËÙ¶ÈÔËÐÐ	//full speed
void VS1003B_SPI_High(void)
{

	SPCR = (1<<SPE)|(1<<MSTR)|(0<<SPR1)|(0<<SPR0);
    SPSR = (1<<SPI2X); //fosc/2
	}

unsigned char VS1003B_WriteByte(unsigned char CH)
{
	SPDR = CH;
	while(!(SPSR & _BV(SPIF)));
	return SPDR;
}

//´ÓVS1003¶ÁÒ»×Ö½Ú		//read one byte from vs1003
unsigned char VS1003B_ReadByte()
{
    SPDR = 0xff;
	while(!(SPSR & _BV(SPIF)));
 	return SPDR;
}

I need something like this :

 

Any clues ?

 

Thanks

 

Last Edited: Fri. Jan 1, 2016 - 11:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How fast is sck and how fast are you sampling it? If the answer is 8MHz and 12MHz, then that is the answer - the logic analyser is not showing what is really happening. Up the sample rate and/or decrease the sck rate.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

so my sampling speed must be 8Mhz ? since my sck speed is 8 Mhz ? thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bianchi77 wrote:

so my sampling speed must be 8Mhz ? since my sck speed is 8 Mhz ? thanks

Your sampling rate will have to be at least 2 times, probably more like 4 times, the SCK frequency.

SpiderKenny
@spiderelectron
www.spider-e.com

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

if I use 16MHz sampling, it stops in the middle and asks me for reducing the sampling frequency...why is that ??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So for sending 8 bits data, I need 8 edges SCK, am I right ?

I put SPI analyzer on, but I can't see byte value, why is that ?

Please have a look :

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why is that? I'd guess at the settings for the spi analyser.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Which setting should I change ? thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have selected xcs as the enable. It seems to stay high in your picture, thus the software is not expecting any data. Maybe you want xdcs?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Saleae Logic Analysers work very well. They do rely on sending lots of traffic on USB. If your PC is slow or just busy with other tasks, you need to reduce the sampling frequency. Or make sure that your PC is not doing other things.

In practice, it is easier to debug SPI at 4MHz. Once you are happy with 4MHz, go with 8MHz and 24MHz sample frequency.

Not much of a problem with AVR. ARM or Xmega can go faster than the Saleae can manage.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You're right, suppose to be XDCS, how can I see the array is sent properly on SPI....because so many bytes on SPI now...

 

I want to check :

const unsigned char HelloMP3[] __attribute__ ((progmem))= {
	0xFF,0xF2,0x40,0xC0,0x19,0xB7,0x00,0x14,0x02,0xE6,0x5C, /* ..@.......\ */
	0x01,0x92,0x68,0x01,0xF1,0x5E,0x03,0x08,0xF0,0x24,0x80, /* ..h..^...$. */
	0x05,0x9E,0x20,0xC6,0xFC,0x12,0x32,0x5C,0xBF,0xF9,0xB9, /* .. ...2\... */

..............

thanks
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The salae logic can grab as much data that can fit on your hard disk. So you can check each byte if you want to. Personally, i'd be checking only a few and verifying your code sends at the right time.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The trick with Saleae is to use a spare GPIO pin and wiggle it just before the sequence you want to observe.
Either use the wiggle to Start or simply click either side of the wiggle channel to find the next wiggle.
Or learn to recognise the patterns at low resolution. Then zoom in to find your sequence of interest.

The software will decode the SPI for you. You should see the FF, F2, 40, ... clearly displayed.

David.

Last Edited: Sat. Jan 2, 2016 - 09:13 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried to do sine test....it's sending byte properly but I can not hear 1kHz beep on and off....anything missing here ?

 

 

The delay between ON and OFF, I saw it, 10 uS

 

Code :

 /** VS10xx Sine Test Function - Good getting started example */
    void VsSineTest(){
        unsigned int i;
	    /* Reset MP3 chip */
	   /* Pull xRESET low -> hardware reset */
	    VS1003B_XRESET_L(); 
		_delay_ms(100);            /* 100 ms delay */

	    /* Send dummy SPI byte to initialize SPI bus of Atmel microcontroller */
	    VS1003B_WriteByte(0xFF);
		
	    /* Un-reset MP3 chip */
	    VS1003B_XCS_H();
		/* Pull xCS high    */
	    /* Pull xDCS high   */
	    VS1003B_XDCS_H();
		 /* Pull xRESET high */
	    VS1003B_XRESET_H();
		_delay_ms(100);            /* 100 ms delay     */
        PORTD = 0xFF;
		
	    /* VS10xx Application Notes, chapter 4.8 ---------------------------------*/
	    /* As an example, let's write value 0x0820 to register 00 byte by byte    */
	    //VS1003B_XCS_L();
		 /* Pull XCS low, now SPI writes go to SCI port     */
	    //VS1003B_WriteCMD(SCI_MODE,0x0820);
		//VS1003B_WriteCMD(SCI_VOL,0x0000); //max volume
          	
		 /* Send SPI Byte, then wait for byte to be sent.   */
	     /* 0x02 was WRITE command, 0x00 is register number */
	     /* This byte goes to MSB                           */
	     /* ..and this is LSB. (0x20=Allow Test Mode)       */
	    VS1003B_Delay();
		 /* Wait until Atmel MCU signals SPI write complete */
	    VS1003B_XCS_H();
		
		/* Pull XCS high, now SPI writes don't go to SCI port. */
       	while ((bit_is_clear(VS1003B_PIN,VS1003B_DREQ))) {
	       	// Do nothing while waiting for DREQ
			   _delay_ms(100);
       	}
        
		
		 
	    /* pull XDCS low, now SPI writes go to SDI port    */
         
		VS1003B_XDCS_L();
		/* Send a Sine Test Header to Data port*/
		
		
		
		        
		VS1003B_WriteByte(0x53);
		VS1003B_WriteByte(0xef);
		VS1003B_WriteByte(0x6e);
		VS1003B_WriteByte(0x44);
		VS1003B_WriteByte(0x00);
		VS1003B_WriteByte(0x00);
		VS1003B_WriteByte(0x00);
		VS1003B_WriteByte(0x00);
	   
		      /* - This is a special VLSI Solution test header - */
	          /* - that starts a sine sound. It's good for     - */
	          /* - testing your code and the chip. */
	    
		VS1003B_Delay(10);
	    // _delay_ms(150);           /* 1500 ms delay */
	    VS1003B_XDCS_H();
	    //_delay_ms(500);           /* 500 ms delay */
       VS1003B_Delay(10);
	   PORTD = 0x00;
	    /* Stop the sine test sound */
		 VS1003B_XDCS_L();
	    		
		VS1003B_WriteByte(0x45);
		VS1003B_WriteByte(0x78);
		VS1003B_WriteByte(0x69);
		VS1003B_WriteByte(0x74);
		VS1003B_WriteByte(0x00);
		VS1003B_WriteByte(0x00);
		VS1003B_WriteByte(0x00);
		VS1003B_WriteByte(0x00);
        
		
	    
		VS1003B_Delay(100);

	   
        VS1003B_XDCS_H(); 
	    _delay_ms(500);            /* 500 ms delay */
		
		
		
		
		
    }

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your delay is suspect. Do you really to expect to hear something 10us wide?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's what I've been wondering....

How much delay do I need ? Where should I put it ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry, you've already used up your three questions on very obvious things. Time for you to do some work methinks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've put 500 ms delay on between...but still I can't hear beep, I can see the delay on logic analyzer but...not in my earphone...??

May be my earphone is not sensitive enough ?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What?????

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 4

The problem might be something that lies between the earphones.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is it possible that my earphone doesn't response properly ? I'll see the output at scope then....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

david.prentice wrote:
The problem might be something that lies between the earphones.

 

Sounds familiar: http://8052.com/forumchat/read/1...

 

wink

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I can hear "teng" ....."teng"....."teng" with this code :

while (p <= &HelloMP3[sizeof(HelloMP3)-1])
		
		{
			
			//loop_until_bit_is_set(VS1003B_PIN,VS1003B_DREQ);
			
			if(bit_is_set(VS1003B_PIN,VS1003B_DREQ))  //send data  honoring DREQ
			 {
				//waitspi();
			
				
				for (i=0; i<32; i++)
				{
				
					VS1003B_WriteByte(pgm_read_byte(p++));
				    _delay_us(1);
				}//end for
		      }//end if
			
			
		}//end while

Is it possible if my SPI transfer is too fast ? I'm using f osc /2 = 8MHz....?

 

Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

again, you ask questions you can easily answer yourself.

is the spi transfer too fast?  refer to the vs1003 data sheet. or simply try it slower.

 

did you get the sine wave test working? if not, it's worthless going any further.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It could be related with clock related multiplier, I changed the multiplier and it produces a different tone...

 

....

The external clock multiplier SCI register SCI_CLOCKF, which has changed slightly since
VS1003 and VS1033, is presented in the table below.

...........

I don't understand which multiplier is suit with my application, my external crystal is 12.228 MHz

I set the value :

#define CLOCK_REG       0x0800

Any ideas ?

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

At a guess, I'd say 0x6800. You might want to see what the Arduino (or other example code) does.  The test frequency is supposed to be 1kHz, so that can be used to verify. The spi speed has to be slow until you set the clock multiplier.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes I used fosc / 128 for setting up CLOCKF....

I changed to 0x6800....still the same ...produced "ting" "ting" "tuck" "tuck"....when I see at logic analyzer...it's sending the correct byte....it means it decodes wrongly because of the wrong speed, I reckon....

 

How do you reckon ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

it works now with VS1003, but strangely, it doesn't work with VS1053....anything I miss here ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

.anything I miss here ?

That is surely a question to pose in a VLSI support forum. I think you'd be lucky to find anyone here who has experience of both 1003 and 1053.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bianchi77 wrote:

it works now with VS1003, but strangely, it doesn't work with VS1053....anything I miss here ?

Yes. Why you didn't say which chips you were using in your original post and you finally get around to it after 14 posts. You can type "VS1053 tutorial" into google and find plenty of help there.