--- a/vs1053.c
+++ b/vs1053.c
@@ -30,8 +30,12 @@
 
 const char patch_magicstring[4] = {'V','l','S','i'};
 
-
-
+#ifdef PATCH_DREQ_DEBUG
+unsigned short patchpos=0;
+#endif
+
+unsigned char dreq_timeout=0;
+        
 struct VS1063_OPTIONS vs1063_options;
 
 const unsigned short vs1063_samplerate[9] = {
@@ -70,21 +74,40 @@
   29135, //5dB
 };
 
+void VS1053WaitDreqTimeout()
+{
+    unsigned char delay;
+    
+    delay = freetimer;
+    while(!VS1053_CHECK_DREQ && ((unsigned char)(freetimer-delay) <= 5));
+    
+    if ( !((unsigned char)(freetimer-delay) <= 5))
+      dreq_timeout++;
+}
+
+
 
 
 int LoadVS1063Patch(void) {
   int i = 0;
-  unsigned short *patch_data;
-  
-  patch_data = &__patch;
-  
-  if(strncmp(patch_magicstring, __patch_magic, 4))
+  
+  char *patch_magic; //@ 0xa000
+  unsigned short *patch_len; //@ 0xa004
+  unsigned short *patch_data; //@ 0xa006
+
+  //Patch is placed at offset 0xa0000
+  patch_magic = (char *)0xa000;
+  patch_len = (unsigned short*)0xa004;
+  patch_data = (unsigned short*)0xa006;
+  
+  
+  if(strncmp(patch_magicstring, patch_magic, 4))
   {
     //Magic String not found
     return 0;
   }
-
-  while (i<__patch_len) {
+  
+  while (i<*patch_len) {
     unsigned short addr, n, val;
     addr = patch_data[i++];
     n = patch_data[i++];
@@ -92,47 +115,62 @@
       n &= 0x7FFF;
       val = patch_data[i++];
       while (n--) {
+#ifdef PATCH_DREQ_DEBUG
+        patchpos=i;
+#endif
         VS1053WriteRegister(addr, val);
+        if(dreq_timeout) return -1;
       }
     } else {           /* Copy run, copy n samples */
       while (n--) {
         val = patch_data[i++];
+#ifdef PATCH_DREQ_DEBUG
+        patchpos=i;
+#endif
         VS1053WriteRegister(addr, val);
+        if(dreq_timeout) return -1;
       }
     }
   }
   
-  while(!VS1053_CHECK_DREQ);   
+  VS1053WaitDreqTimeout();
+//  while(!VS1053_CHECK_DREQ);   
   return 1;
 }
 
 
 void InitVS1053(void)
 {
-        unsigned char delay;
   
         VS1053_GPIO_CTRL->DDR |= VS1053_PIN_RESET;
         VS1053_GPIO_CTRL->CR1 |= VS1053_PIN_RESET;
         VS1053_GPIO_SPI->DDR |= VS1053_PIN_CS;
         VS1053_GPIO_SPI->CR1 |= VS1053_PIN_CS;
         
-	InitSPI(SPI_BAUDRATEPRESCALER_256);		//Slow SPI for Initialization
-
-	VS1053Reset();
-	
-	VS1053WriteRegister(VS1053_REG_MODE, VS1053_SM_SDINEW | VS1053_SM_SDISHARE);
-	
-	//Set GPIOs as Output
-	VS1053WriteWram(VS1053_ADDR_DDR,0xff);
-	VS1053WriteRegister(VS1053_REG_CLOCKF,VS1053_CLOCK_5); // set to  61,44 Mhz Operation	
-        VS1053WriteRegister( VS1053_REG_STATUS, VS1053ReadRegister(VS1053_REG_STATUS) | VS1063_SS_REFERENCE_SEL );  //1,65 Volt Reference
-	InitSPI(SPI_BAUDRATEPRESCALER_4);		//fast SPI approx 3,68 M/bits (Datasheet allows max. 3,5M/Bits)
-
-        //wait a little 1/450 - 2/450 s
-        delay = freetimer;
-        while((freetimer-delay) >= 2);
-        
-        LoadVS1063Patch();
+        do {
+          
+          dreq_timeout = 0;
+          
+          InitSPI(SPI_BAUDRATEPRESCALER_256);		//Slow SPI for Initialization
+  
+          VS1053Reset();
+          
+          VS1053WriteRegister(VS1053_REG_MODE, VS1053_SM_SDINEW | VS1053_SM_SDISHARE);
+          
+           
+          //Set GPIOs as Output
+          VS1053WriteWram(VS1053_ADDR_DDR,0xff);
+          VS1053WriteRegister(VS1053_REG_CLOCKF,VS1053_CLOCK_5); // set to  61,44 Mhz Operation	
+          InitSPI(SPI_BAUDRATEPRESCALER_4);		//fast SPI approx 3,68 M/bits (Datasheet allows max. 3,5M/Bits)
+          VS1053WriteRegister( VS1053_REG_STATUS, VS1053ReadRegister(VS1053_REG_STATUS) | VS1063_SS_REFERENCE_SEL );  //1,65 Volt Reference
+  
+          
+          VS1053WaitDreqTimeout();      
+          //while(!VS1053_CHECK_DREQ);   
+    
+          LoadVS1063Patch();
+ 
+        } while( dreq_timeout );
         
 }
 
@@ -145,8 +183,14 @@
 
 void VS1053Reset(void)
 {
+        unsigned char delay;
+          
 	VS1053_GPIO_CTRL->ODR &= ~VS1053_PIN_RESET;
-	VS1053_GPIO_CTRL->ODR |= VS1053_PIN_RESET;
+        //wait a little 1/450 - 2/450 s
+        delay = freetimer;
+        while((unsigned char)(freetimer-delay) <= 2);
+ 
+        VS1053_GPIO_CTRL->ODR |= VS1053_PIN_RESET;
 }
 
 void VS1053WriteWram(unsigned short addr, unsigned short val)
@@ -190,10 +234,14 @@
 	return (unsigned char)VS1053ReadWram(VS1053_ADDR_IDATA);
 }
 
+
+
 void VS1053WriteRegister(unsigned char reg, unsigned short val) 
 {
-	
-	while(!VS1053_CHECK_DREQ);
+	unsigned char delay;
+                
+        VS1053WaitDreqTimeout();
+	//while(!VS1053_CHECK_DREQ);
 	
         disableInterrupts();
 //	SPI->CR1 |= 0x40; //Enable SPI;
@@ -215,6 +263,15 @@
 	VS1053_SPI_CS_OFF;
         
         enableInterrupts();
+        
+        if(reg == VS1053_REG_WRAMADDR)
+        {
+          //wait a little 1/450 - 2/450 s
+          delay = freetimer;
+          while((unsigned char)(freetimer-delay) <= 2);
+        } 
+      
+        return;
 }
 
 
@@ -222,8 +279,9 @@
 	unsigned char c,d;
 	unsigned short val;
 	
-	while(!VS1053_CHECK_DREQ);
-	
+	//while(!VS1053_CHECK_DREQ);
+	VS1053WaitDreqTimeout();
+        
         disableInterrupts();
 		
 	VS1053_SPI_CS_ON;