Exemple #1
0
void SD_Read_Block(PTR_LBA_APP_STRUCT lba_data_ptr)
{
    uint_8 u8Temp=0;
    uint_32 u32Counter;

    /*Body*/
    gu8SD_Argument.lword = lba_data_ptr->offset; 

    if(SD_SendCommand(SD_CMD17|0x40,SD_OK))
    {       
        return;     /* Command IDLE fail */
    }/*EndIf*/
    
    while(u8Temp!=0xFE)  
    {      
        u8Temp = SPI_Receive_byte(); 
    }/*EndWhile*/
    
    for(u32Counter=0;u32Counter<lba_data_ptr->size;u32Counter++)  
    {
        *(lba_data_ptr->buff_ptr + u32Counter) = SPI_Receive_byte(); 
    }/*EndFor*/
    
    
  /* Dummy SPI cycle */
    (void)SPI_Receive_byte();
    (void)SPI_Receive_byte();
    (void)SPI_Receive_byte();
    
    
    return;
}/*EndBody*/
Exemple #2
0
void SD_Write_Block(PTR_LBA_APP_STRUCT lba_data_ptr)
{
    uint_32 u32Counter;

    /*Body*/
    gu8SD_Argument.lword = lba_data_ptr->offset; 
    if(SD_SendCommand(SD_CMD24|0x40,SD_OK))
    {
        return;   /* Command IDLE fail */
    }/*EndIf*/
    
    SPI_Send_byte(0xFE);
    
    for(u32Counter=0;u32Counter<lba_data_ptr->size;u32Counter++)  
    {
        SPI_Send_byte(*(lba_data_ptr->buff_ptr + u32Counter));
    }/*EndFor*/

    SPI_Send_byte(0xFF);    /* checksum Bytes not needed */
    SPI_Send_byte(0xFF);

    
    if((SPI_Receive_byte() & 0x0F) != 0x05)
    {       
        return;     /* Command fail */
    }/*EndIf*/

    while(SPI_Receive_byte()==0x00)
    {
        Watchdog_Reset();   /* Dummy SPI cycle */
    }/*EndWhile*/

    return;
}/*EndBody*/
Exemple #3
0
void SD_Read_Block(PTR_LBA_APP_STRUCT lba_data_ptr)
{
    uint_8 u8Temp=0;
    uint_32 u32Counter;

    gu8SD_Argument.lword = lba_data_ptr->offset; 

    if(SD_SendCommand(SD_CMD17|0x40,SD_OK))
    {       
        return; // Command IDLE fail
    }
    
    while(u8Temp!=0xFE)  
    {      
        u8Temp = SPI_Receive_byte(); 
    }
    
    for(u32Counter=0;u32Counter<lba_data_ptr->size;u32Counter++)  
    {
        *(lba_data_ptr->buff_ptr + u32Counter) = SPI_Receive_byte(); 
    }
        
    (void)SPI_Receive_byte();  // Dummy SPI cycle
    (void)SPI_Receive_byte();  // Dummy SPI cycle

    (void)SPI_Receive_byte();  // Dummy SPI cycle
    
    return;
}
Exemple #4
0
UINT8 SD_Init(void) 
{
    _SD_PRESENT=_IN;
    
    /* Check for SD */
    if(SD_PRESENT)
        return(NO_SD_CARD);
    
    /* Initialize SPI Module */
    SPI_Init();

    
    /* Start SD card Init */
    SPI_SS=ENABLE;
    SD_CLKDelay(10);            // Send 80 clocks 
    SPI_SS=DISABLE;
  
    gu8SD_Argument.lword=0;
    SD_CLKDelay(8);  
    
    /* IDLE Command */
    
    SPI_SS=ENABLE;
    if(SD_SendCommand(SD_CMD0|0x40,SD_IDLE))
    {
        SPI_SS=DISABLE;
        return(INIT_FAILS);      
    }
    SPI_SS=DISABLE;
    
    (void)SPI_Receive_byte();  // Dummy SPI cycle
    
    /*  Initialize SD Command */
    SPI_SS=ENABLE;
    while(SD_SendCommand(SD_CMD1|0x40,SD_OK));
    SPI_SS=DISABLE;
    
    (void)SPI_Receive_byte();  // Dummy SPI cycle

    /*  Block Length */
    SPI_SS=ENABLE;
      
    gu8SD_Argument.lword=SD_BLOCK_SIZE;
    if(SD_SendCommand(SD_CMD16|0x40,SD_OK))
    {
        SPI_SS=DISABLE;
        return(INIT_FAILS);      
    }
    
    SPI_SS=DISABLE;
    
    SPI_High_rate();

    SPI_Send_byte(0x00);
    SPI_Send_byte(0x00);
    return(OK);
}
uint_8 SD_ReadCSD(void)
{
#ifdef MCU_MKL25Z4
    uint_8 i;
    
    SPI_set_SS();

    if(SD_SendCommand(SD_CMD9|0x40,SD_OK))
    {
        SPI_clr_SS() ;
        return(4);      
    }
    
    while(i!=0xFE)
        i=SPI_Receive_byte();
    
    for(i=0;i<16;i++)
        vSD_CSD[i]=SPI_Receive_byte();

    (void)SPI_Receive_byte();  /* Dummy SPI cycle */
    (void)SPI_Receive_byte();  /* Dummy SPI cycle */

    SPI_clr_SS() ;
    
    (void)SPI_Receive_byte();  /* Dummy SPI cycle */
    
    return(0);
#else
   uint_8 i = 0;
   /*Body*/
   if(SD_SendCommand(SD_CMD9|0x40,SD_OK))
   {
      return(4);
   }/*EndIf*/

   while(i!=0xFE)
   i=SPI_Receive_byte();

   for(i=0;i<16;i++)
   vSD_CSD[i]=SPI_Receive_byte();

   (void)SPI_Receive_byte();
   (void)SPI_Receive_byte();

   (void)SPI_Receive_byte();

   return(0);
#endif
}/*EndBody*/
Exemple #6
0
UINT8 SD_SendCommand(UINT8 u8SDCommand,UINT8 u8SDResponse) 
{
    UINT8 u8Counter;
    volatile UINT8 u8Temp=0;

    /* Send Start byte */
    SPI_Send_byte(u8SDCommand);

    /* Send Argument */
    for(u8Counter=0;u8Counter<4;u8Counter++) 
        SPI_Send_byte(gu8SD_Argument.bytes[u8Counter]);
  
    /* Send CRC */
    SPI_Send_byte(0x95);
  
    /* Response RHandler */
    u8Counter=SD_WAIT_CYCLES;
    do
    {
        u8Temp=SPI_Receive_byte();
        u8Counter--;
    }while((u8Temp != u8SDResponse) && u8Counter > 0);
    
    if(u8Counter)   return(OK);
    else            return(COMMAND_FAILS);
}
void BUFRead(unsigned char *data, unsigned int addr, unsigned int length, unsigned char buf)
{
unsigned char i;
AT45DBXX_Enable; //CS LOW
if (buf==BUFFER1)
{
SPI_Send_byte( BUF1_READ); //opcode for read status
}
if (buf==BUFFER2)
{
SPI_Send_byte(BUF2_READ);
}
SPI_Send_byte(0x00); //don't care

SPI_Send_byte((char)(addr>>8)); //don't care and 1st 2 addr bits

SPI_Send_byte((char)(addr)); //address

SPI_Send_byte(0x00); //don't care

for(i=0;i<length;i++)
{
*data = SPI_Receive_byte();
data++;
}
AT45DBXX_Disable; //end
}
uint_8 SD_SendCommand(uint_8 u8SDCommand,uint_8 u8SDResponse)
{
   /*Body*/
   uint_8 u8Counter;
   volatile uint_8 u8Temp=0;

   /* Send Start byte */
   SPI_Send_byte(u8SDCommand);

   /* Send Argument */
   for(u8Counter=0;u8Counter<4;u8Counter++)
   SPI_Send_byte(gu8SD_Argument.bytes[u8Counter]);

   /* Send CRC */
   SPI_Send_byte(0x95);

   /* Response RHandler */
   u8Counter=SD_WAIT_CYCLES;
   do
   {
      u8Temp=SPI_Receive_byte();
      u8Counter--;
   }while((u8Temp != u8SDResponse) && u8Counter > 0);
   if(u8Counter)   return(0);
   else            return(1);
}/*EndBody*/
Exemple #9
0
/***************************************************************************************
 *
 *     *** SD_CBufferDataSectorWrite ***
 *
 *     Description: Write a 512 bytes from the circular buffer as a data sector.
 *                  Assume:
 *                         - SD Card has been previously erased.
 *                         - Write a full sector at a time.
 *
 *     Entry: void. 
 *
 ****************************************************************************************/
void SD_CBufferDataSectorWrite(void) {
	UINT16 u16Counter;

	SPI_SS = ENABLE;

	gu8SD_Argument.lword = u32DataSector++; // Set WRITE_BLOCK command argument
											//     to the current data segment
	gu8SD_Argument.lword = gu8SD_Argument.lword << SD_BLOCK_SHIFT; // Convert sector number to
																   // byte address

	if (SD_SendCommand(SD_CMD24 | 0x40, SD_OK)) // WRITE_BLOCK command
			{
		SPI_SS = DISABLE;
		return;
	}

	WriteSPIByte(0xFE); // Start Block Token

	for (u16Counter = 0; u16Counter < BLOCK_SIZE; u16Counter++) // Write the block
		WriteSPIByte(FromCBuffer());

	WriteSPIByte(0xFF); // checksum Bytes not needed
	WriteSPIByte(0xFF);

//    for(u16Counter=0;u16Counter<BLOCK_SIZE;u16Counter++);

//    if((ReadSPIByte() & 0x0F) != 0x05)                // Read the status token.
	// Correct response is 0x05
	// Foust p5.
	while ((SPI_Receive_byte() & 0x0F) != 0x05)
		;
//    {
//        SPI_SS=DISABLE;
//        return;      
//    }

	while (SPI_Receive_byte() == 0x00)
		; // Wait while the card is busy

	SPI_SS = DISABLE;

	SD_CLKDelay(1); // 8 dummy clocks

	return;

}
Exemple #10
0
//FLASH INTERACTION FUNCTIONS
char FLASHStatus(void) {
	int i;
//AT45DBXX_BUSY();
	AT45DBXX_Enable; //CS LOW
	SPI_Send_byte(STATUS_READ);  //opcode for read status
   i=SPI_Receive_byte();
AT45DBXX_Disable; //end
return i;
}
Exemple #11
0
/*****************************************************************************
 *
 ************* SD_Erase_Blocks ***********
 *
 *      Description: Erase multiple sectors (blocks) no the SD card.
 *
 *      Inputs:      u32SD_Start_Block - the sector (block) number of the first
 *                                 block to be erased.
 *                   u32SD_End_Block - the sector (block) number of the last
 *                                    block to be erased.
 *
 *****************************************************************************/
UINT8 SD_Erase_Blocks(UINT32 u32SD_Start_Block, UINT32 u32SD_End_Block) {
	UINT8 res;
	UINT16 u16Counter;

	SPI_SS = ENABLE;

	/* Set the address of the first write block to be erased */
	gu8SD_Argument.lword = u32SD_Start_Block; // Set ERASE_WR_BLK_START_ADDR 
											  //   command argument
	gu8SD_Argument.lword = gu8SD_Argument.lword << SD_BLOCK_SHIFT; // Convert sector number to
																   // byte address

	if (SD_SendCommand(SD_CMD32 | 0x40, SD_OK)) // ERASE_WR_BLK_START_ADDR command
			{
		SPI_SS = DISABLE;
		return (WRITE_COMMAND_FAILS);
	}

	SD_CLKDelay(1); // 8 dummy clocks

	/* Set the address of the last write block to be erased */
	gu8SD_Argument.lword = u32SD_End_Block; // Set ERASE_WR_BLK_END_ADDR 
											//   command argument
	gu8SD_Argument.lword = gu8SD_Argument.lword << SD_BLOCK_SHIFT; // Convert sector number to
																   // byte address

	if (SD_SendCommand(SD_CMD33 | 0x40, SD_OK)) // ERASE_WR_BLK_END_ADDR command
			{
		SPI_SS = DISABLE;
		return (WRITE_COMMAND_FAILS);
	}

	SD_CLKDelay(1); // 8 dummy clocks

	/* Send the erase command */
	gu8SD_Argument.lword = 0x00000000; // stuff bits 

	if (SD_SendCommand(SD_CMD38 | 0x40, SD_OK)) // ERASE command
			{
		SPI_SS = DISABLE;
		return (WRITE_COMMAND_FAILS);
	}

	/* Wait while card is busy. Indicated by reading 0x00 from SD Card */
	u16Counter = 0; // Counter to see if it is doing something
	do {
		res = SPI_Receive_byte();
		u16Counter++;
	} while (res == 0x00); // Wait while the card is busy

	SPI_SS = DISABLE;

	SD_CLKDelay(1); // 8 dummy clocks

	return (OK);
}
Exemple #12
0
 void AT45DBXX_Read_sec_lock(unsigned char *sec)
{ u8 i;
  AT45DBXX_Enable;
	SPI_Send_byte(0x35);
SPI_Send_byte(0x00); 
SPI_Send_byte(0x00); 
SPI_Send_byte(0x00); 	
	for(i=0;i<8;i++)
	sec[i]=SPI_Receive_byte();
AT45DBXX_Disable;	
}
Exemple #13
0
unsigned char Status_read(void)
{ u8 i;
	  AT45DBXX_Enable;
   SPI_Send_byte( STATUS_READ); 

		do
	{i = SPI_Receive_byte();}
	while(!(i & 0x80));
AT45DBXX_Disable;
	return i;

}
Exemple #14
0
uint_8 SD_Init(void) 
{

    SPI_Init();             	// SPI Initialization

    SD_CLKDelay(10);            // Send 80 clocks 

    gu8SD_Argument.lword = 0;
    SD_CLKDelay(8);  
    
    /* IDLE Command */
    if(SD_SendCommand(SD_CMD0|0x40,SD_IDLE))
    {
        return(1);      		// Command IDLE fail
    }
    
    (void)SPI_Receive_byte();  	// Dummy SPI cycle
    
    /*  Initialize SD Command */
     while(SD_SendCommand(SD_CMD1|0x40,SD_OK))
    {
        Watchdog_Reset();
    }
    
    (void)SPI_Receive_byte();  // Dummy SPI cycle

    /*  Block Length */
    gu8SD_Argument.lword = SD_BLOCK_SIZE;
    if(SD_SendCommand(SD_CMD16|0x40,SD_OK))
    {       
        return(1);      // Command IDLE fail
    }
    
    SPI_High_rate();
    
    SPI_Send_byte(0x00);
    SPI_Send_byte(0x00);
    //(void)SPI_Receive_byte();  // Dummy SPI cycle
    return(0);
}
Exemple #15
0
uint_8 SD_Init(void) 
{
    /* Body */
    SPI_Init();                 /* SPI Initialization */
    SPI_set_SS();
    SD_CLKDelay(10);            /* Send 80 clocks  */
    SPI_clr_SS() ;
    gu8SD_Argument.lword = 0;
    SD_CLKDelay(8);  
    /* IDLE Command */
    SPI_set_SS();
    if(SD_SendCommand(SD_CMD0|0x40,SD_IDLE))
    {
        SPI_clr_SS() ;
        return(1);          /* Command IDLE fail */
    } /* EndIf */
    SPI_clr_SS() ;
    (void)SPI_Receive_byte();   /* Dummy SPI cycle */
    /*  Initialize SD Command */
    SPI_set_SS();
    while(SD_SendCommand(SD_CMD1|0x40,SD_OK))
    {
        __RESET_WATCHDOG();
    } /* EndWhile */
    SPI_clr_SS() ;
    (void)SPI_Receive_byte();  /* Dummy SPI cycle */
    /*  Block Length */
    SPI_set_SS();
    gu8SD_Argument.lword = SD_BLOCK_SIZE;
    if(SD_SendCommand(SD_CMD16|0x40,SD_OK))
    {
        SPI_clr_SS() ;
        return(1);      /* Command IDLE fail */
    } /* EndIf */
    SPI_clr_SS() ;
    SPI_High_rate();
    SPI_Send_byte(0x00);
    SPI_Send_byte(0x00);
    return(0);
} /* EndBody */
Exemple #16
0
uint_8 SD_ReadCSD(void)
{
    uint_8 i;
    
    /*Body*/
    if(SD_SendCommand(SD_CMD9|0x40,SD_OK))
    {
        return(4);
    }
    
    while(i!=0xFE)
        i=SPI_Receive_byte();
    
    for(i=0;i<16;i++)
        vSD_CSD[i]=SPI_Receive_byte();

    (void)SPI_Receive_byte();
    (void)SPI_Receive_byte();
    (void)SPI_Receive_byte();
    
    return(0);
}/*EndBody*/
Exemple #17
0
UINT8 SD_Write_Block(UINT32 u16SD_Block,UINT8 *pu8DataPointer) 
{
    UINT16 u16Counter;
    UINT8 SD_response;

    SPI_SS=ENABLE;

    gu8SD_Argument.lword=u16SD_Block;
    gu8SD_Argument.lword=gu8SD_Argument.lword<< SD_BLOCK_SHIFT;

    if(SD_SendCommand(SD_CMD24|0x40,SD_OK))
    {
        SPI_SS=DISABLE;
        return(WRITE_COMMAND_FAILS);      
    }
    
    WriteSPIByte(0xFE);
    
    for(u16Counter=0;u16Counter<BLOCK_SIZE;u16Counter++)
        WriteSPIByte(*pu8DataPointer++);

    WriteSPIByte(0xFF);    // checksum Bytes not needed
    WriteSPIByte(0xFF);

    
    /* Buggy, replaced with //--
    for(u16Counter=0;u16Counter<BLOCK_SIZE;u16Counter++) ;
    
    if((ReadSPIByte() & 0x0F) != 0x05)
    {
        SPI_SS=DISABLE;
        return(WRITE_DATA_FAILS);      
    }
    */

    //-- 
    SD_response=0xFF; // #001 created this variable
    while (SD_response==0xFF) SD_response=ReadSPIByte(); // #001 wait for SD response <> 0xFF
    if((SD_response & 0x0F) != 0x05)  // #001 checks if response = 0101 = data accepted
    {
        SPI_SS=DISABLE;
        return(WRITE_DATA_FAILS);    
    }
    //-- Thx to Celso Monteiro

    while(SPI_Receive_byte()==0x00) ;  // Dummy SPI cycle

    SPI_SS=DISABLE;
    return(OK);
}
Exemple #18
0
UINT8 SD_Write_Block(UINT32 u16SD_Block,UINT8 *pu8DataPointer) 
{
    UINT16 u16Counter;

    SPI_SS=ENABLE;

    gu8SD_Argument.lword=u16SD_Block;
    gu8SD_Argument.lword=gu8SD_Argument.lword<< SD_BLOCK_SHIFT;

    if(SD_SendCommand(SD_CMD24|0x40,SD_OK))
    {
        SPI_SS=DISABLE;
        return(WRITE_COMMAND_FAILS);      
    }
    
    SPI_Send_byte(0xFE);
    
    for(u16Counter=0;u16Counter<BLOCK_SIZE;u16Counter++)
        SPI_Send_byte(*pu8DataPointer++);

    SPI_Send_byte(0xFF);    // checksum Bytes not needed
    SPI_Send_byte(0xFF);

    for(u16Counter=0;u16Counter<BLOCK_SIZE;u16Counter++);
    
    if((SPI_Receive_byte() & 0x0F) != 0x05)
    {
        SPI_SS=DISABLE;
        return(WRITE_DATA_FAILS);      
    }

    while(SPI_Receive_byte()==0x00);  // Dummy SPI cycle

    SPI_SS=DISABLE;
    return(OK);
}
Exemple #19
0
/*********************************************************
* Name: SD_ReadCSD
* Desc: Read CSD vaule of SD card
* Parameter: None
* Return: Status of read -- Fail:04  Success:00
**********************************************************/
uint_8 SD_ReadCSD(void)
{
    /* Body */
    uint_8 i;
    SPI_set_SS();
    if(SD_SendCommand(SD_CMD9|0x40,SD_OK))
    {
        SPI_clr_SS() ;
        return(4);      
    } /* EndIf */
    while(i!=0xFE)
    {
        i=SPI_Receive_byte();
    } /* EndWhile */
    for(i=0;i<16;i++)
    {
        vSD_CSD[i]=SPI_Receive_byte();
    } /* EndFor */
    (void)SPI_Receive_byte();  /* Dummy SPI cycle */
    (void)SPI_Receive_byte();  /* Dummy SPI cycle */
    SPI_clr_SS() ;
    (void)SPI_Receive_byte();  /* Dummy SPI cycle */
    return(0);
} /* EndBody */
Exemple #20
0
/*****************************************************************************
 *
 **************SD_Write_Block************
 *
 *      Description: Write a 512 byte sector (block) to the SD card.
 *
 *      Inputs:      u16SD_Block - the sector (block) number where the block is
 *                                 to be written.
 *                   pu8DataPointer - the 512 byte buffer that is to be written
 *                                    to the SD card.
 *
 *****************************************************************************/
UINT8 SD_Write_Block(UINT32 u16SD_Block, UINT8 *pu8DataPointer) {
	UINT16 u16Counter;

	SPI_SS = ENABLE;

	gu8SD_Argument.lword = u16SD_Block; // Set WRITE_BLOCK command argument
	gu8SD_Argument.lword = gu8SD_Argument.lword << SD_BLOCK_SHIFT; // Convert sector number to
																   // byte address

	if (SD_SendCommand(SD_CMD24 | 0x40, SD_OK)) // WRITE_BLOCK command
			{
		SPI_SS = DISABLE;
		return (WRITE_COMMAND_FAILS);
	}

	WriteSPIByte(0xFE); // Start Block Token

	for (u16Counter = 0; u16Counter < BLOCK_SIZE; u16Counter++) // Write the block
		WriteSPIByte(*pu8DataPointer++);

	WriteSPIByte(0xFF); // checksum Bytes not needed
	WriteSPIByte(0xFF);

	for (u16Counter = 0; u16Counter < BLOCK_SIZE; u16Counter++)
		;

	if ((ReadSPIByte() & 0x0F) != 0x05) // Read the status token.
										// Correct response is 0x05
										// Foust p5.
			{
		SPI_SS = DISABLE;
		return (WRITE_DATA_FAILS);
	}

	while (SPI_Receive_byte() == 0x00)
		; // Wait while the card is busy

	SPI_SS = DISABLE;

	SD_CLKDelay(1); // 8 dummy clocks

	return (OK);
}
Exemple #21
0
void PageRead (unsigned char *data, unsigned int page_addr, unsigned int byte_addr, unsigned int length)
{
unsigned int i;
AT45DBXX_Enable; //end

SPI_Send_byte( PAGE_READ);
SPI_Send_byte((char)(page_addr>>7));

SPI_Send_byte((char)(page_addr<<1)|(0x01 & (byte_addr>>8)));

SPI_Send_byte((char)(byte_addr));

//32 don't care bits
for (i=0;i<4;i++)
{SPI_Send_byte( 0x00);

}
for (i=0;i<length;i++)
{
*data =SPI_Receive_byte();
data++;
}
AT45DBXX_Disable;
}
Exemple #22
0
void SD_Write_Block(PTR_LBA_APP_STRUCT lba_data_ptr)
{
#ifdef MCU_MKL25Z4
    uint_32 u32Counter;

    SPI_set_SS();

    gu8SD_Argument.lword = BYTESWAP32(lba_data_ptr->offset);

    if(SD_SendCommand(SD_CMD24|0x40,SD_OK))
    {
        SPI_clr_SS() ;
        return;   /* Command IDLE fail */
    }
    
    SPI_Send_byte(0xFE);
    
    for(u32Counter=0;u32Counter<lba_data_ptr->size;u32Counter++)  
    {
        SPI_Send_byte(*(lba_data_ptr->buff_ptr + u32Counter));
    }

    SPI_Send_byte(0xFF);    /* checksum Bytes not needed */
    SPI_Send_byte(0xFF);

    if((SPI_Receive_byte() & 0x0F) != 0x05)
    {
        SPI_clr_SS() ;
        return;     /* Command fail */
    }

    while(SPI_Receive_byte()==0x00)
    {
    	Watchdog_Reset();   /* Dummy SPI cycle */
    }      

    SPI_clr_SS() ;
    return;
#else
   /* Body */
   uint_32 u32Counter, time_out;

   gu8SD_Argument.lword = BYTESWAP32(lba_data_ptr->offset);

   if(SD_SendCommand(SD_CMD24|0x40,SD_OK))
   {
      return;   /* Command IDLE fail */
   } /* EndIf */

   SPI_Send_byte(0xFE);

   for(u32Counter=0;u32Counter<lba_data_ptr->size;u32Counter++)
   {
      SPI_Send_byte(*(lba_data_ptr->buff_ptr + u32Counter));
   } /* EndFor */

   SPI_Send_byte(0xFF);    /* checksum Bytes not needed */
   SPI_Send_byte(0xFF);


   for (time_out=0;time_out<1000;time_out++)
   {
      if((SPI_Receive_byte() & 0x1F) < 16)
      {
         break;
      } /* EndIf */
   }/* EndFor */

   if (time_out>=1000)
   return;

   while(SPI_Receive_byte()==0x00)
   {
      Watchdog_Reset();
   } /* EndWhile */
   return;
#endif
}
Exemple #23
0
void SD_Read_Block(PTR_LBA_APP_STRUCT lba_data_ptr)
{
#ifdef MCU_MKL25Z4
    uint_8 u8Temp=0;
    uint_32 u32Counter;

    SPI_set_SS();

    gu8SD_Argument.lword = BYTESWAP32(lba_data_ptr->offset);

    if(SD_SendCommand(SD_CMD17|0x40,SD_OK))
    {
        SPI_clr_SS() ;
        return;     /* Command IDLE fail */
    }
    
    while(u8Temp!=0xFE)  
    {      
        u8Temp = SPI_Receive_byte(); 
    }
    
    for(u32Counter=0;u32Counter<lba_data_ptr->size;u32Counter++)  
    {
        *(lba_data_ptr->buff_ptr + u32Counter) = SPI_Receive_byte(); 
    }
        
    (void)SPI_Receive_byte();  /* Dummy SPI cycle */
    (void)SPI_Receive_byte();  /* Dummy SPI cycle */

    SPI_clr_SS() ;

    (void)SPI_Receive_byte();  /* Dummy SPI cycle */
    
    return;
#else
   uint_8 u8Temp=0;
   uint_32 u32Counter;

   gu8SD_Argument.lword = BYTESWAP32(lba_data_ptr->offset);

   if(SD_SendCommand(SD_CMD17|0x40,SD_OK))
   {
      return; /* Command IDLE fail*/
   }

   while(u8Temp!=0xFE)
   {
      u8Temp = SPI_Receive_byte();
   }/*EndWhile*/

   for(u32Counter=0;u32Counter<lba_data_ptr->size;u32Counter++)
   {
      *(lba_data_ptr->buff_ptr + u32Counter) = SPI_Receive_byte();
   }

   (void)SPI_Receive_byte();  /*   Dummy SPI cycle */
   (void)SPI_Receive_byte();  /*   Dummy SPI cycle */

   (void)SPI_Receive_byte();  /*   Dummy SPI cycle */
   return;
#endif
}/*EndBody*/
Exemple #24
0
uint_8 SD_Init(void)
{
#ifdef MCU_MKL25Z4
    SPI_Init();                 /* SPI Initialization */

    SD_CLKDelay(10);            /* Send 80 clocks  */
    SPI_clr_SS() ;

    gu8SD_Argument.lword = 0;
    SPI_set_SS();
    SD_CLKDelay(8);  
    
    /* IDLE Command */
    
    SPI_set_SS();
    if(SD_SendCommand(SD_CMD0|0x40,SD_IDLE))
    {
        SPI_clr_SS();
        return(FALSE);          /* Command IDLE fail */
    }
    SPI_clr_SS();
    
    (void)SPI_Receive_byte();   /* Dummy SPI cycle */
    
    /*  Initialize SD Command */
    SPI_set_SS();
    while(SD_SendCommand(SD_CMD1|0x40,SD_OK))
    {
    	Watchdog_Reset();
    }
    SPI_clr_SS() ;
    
    (void)SPI_Receive_byte();  /* Dummy SPI cycle */

    /*  Block Length */
    gu8SD_Argument.lword = BYTESWAP32(SD_BLOCK_SIZE);
    SPI_set_SS();
    if(SD_SendCommand(SD_CMD16|0x40,SD_OK))
    {
        SPI_clr_SS() ;
        return(FALSE);      /* Command IDLE fail */
    }
    SPI_clr_SS() ;
    SPI_High_rate();
    SPI_Send_byte(0x00);
    SPI_Send_byte(0x00);
    
    return(TRUE);
#else
   /*Body*/
   SPI_Init();                 /* SPI Initialization*/

   SD_CLKDelay(10);            /* Send 80 clocks*/

   gu8SD_Argument.lword = 0;
   SD_CLKDelay(8);
   
   /* IDLE Command */
   if(SD_SendCommand(SD_CMD0|0x40,SD_IDLE))
   {
      return(FALSE);              /* Command IDLE fail*/
   }/*Endif*/

   (void)SPI_Receive_byte();   /* Dummy SPI cycle*/

   /*  Initialize SD Command */
   while(SD_SendCommand(SD_CMD1|0x40,SD_OK))
   {
      Watchdog_Reset();
   }/*EndWhile*/

   (void)SPI_Receive_byte();   /*Dummy SPI cycle */

   /*  Block Length */
   gu8SD_Argument.lword = BYTESWAP32(SD_BLOCK_SIZE);

   if(SD_SendCommand(SD_CMD16|0x40,SD_OK))
   {
      return(FALSE);              /* Command IDLE fail */
   }/*Endif*/

   SPI_High_rate();

   SPI_Send_byte(0x00);
   SPI_Send_byte(0x00);
   return(TRUE);
#endif
}/*End Body*/