Esempio n. 1
0
void if_spiInit(hwInterface *iface)
{
  euint8 i;

  __disable_interrupt();

  UCB0CTL1 |= UCSWRST;

  UCB0CTL0 = UCMSB + UCMST + UCSYNC; //+ UCCKPL+ UCCKPH;
//  UCB0CTL0 = UCMSB + UCMST + UCSYNC + UCCKPL+ UCCKPH;
  UCB0CTL1 |= 0xC0;

  UCB0BR0 = 2;
  UCB0BR1 = 0;

  P3SEL |= 0x0E; //Primary peripheral

  P3OUT |= (1<<DD_CS);
  P3DIR |= (1<<DD_MOSI) | (1<<DD_SCK) | (1<<DD_CS);


  UCB0CTL1 &= ~UCSWRST;
  __enable_interrupt();
		

	/* Send 10 spi commands with card not selected */
  for(i=0;i<10;i++)
    if_spiSend(iface,0xff);

	/* Select card */
	/* PORTB &= 0xFE; moved to interfaceInit to make clear
	   that card has to be selected before calling sd_init() */
  P3OUT &= ~(1<<DD_CS);
}
Esempio n. 2
0
esint8 sd_Init(hwInterface *iface)
{
	euint32 retry;
	euint8  n, resp, ty, ocr[4], cmd;
	
	ty = 0;
	
	/* Try to send command enter idle (CMD0) up to 100 times */
	retry=100;
	do {
		resp = sd_Command(iface, CMD0, 0, 0);
	} while( resp!=1 && retry-- );
	
	if( resp != 1 ) {
		if( resp == 0xff ){
			return(-1);
		}
		else {
			sd_Resp8bError( iface, resp );
			return(-2);
		}
	}

	DBG((TXT("Card identified as ")));
	if ( sd_Command( iface, CMD8, 0, 0x01AA) == 1 ) {
		/* SDHC */
		for ( n=0; n<4; n++ ) {
			ocr[n] = if_spiSend( iface, 0xff );
		}
		if ( ocr[2] == 0x01 && ocr[3] == 0xAA ) {          /* The card can work at vdd range of 2.7-3.6V */
			retry = LOOP_CNT_1000; /* should retry 1000ms */
			do {
				/* Wait for leaving idle state (ACMD41 with HCS bit) */
				resp = sd_Command( iface, ACMD41, ((1UL << 30)>>16), 0 );
				retry--;
			} while ( retry && (resp != 0) );
			
			if ( retry && sd_Command( iface, CMD58, 0, 0 ) == 0) { /* Check CCS bit in the OCR */
				for ( n = 0; n < 4; n++ ) {
					ocr[n] = if_spiSend( iface, 0xff );
				}
				ty = (ocr[0] & 0x40) ? 12 : 4;
				if ( ty == 12 ) DBG((TXT("SDHC HighCap\n")));
				if ( ty == 4 )  DBG((TXT("SDHC\n")));
			}
		}
	}
Esempio n. 3
0
void
if_spiInit(hwInterface *iface)
{
  unsigned int i;
  GPIOA->BSRR = GPIO_BSRR_BS4;
  for(i=0;i<20;i++) {
    if_spiSend(iface, 0xff);
  }
  GPIOA->BSRR = GPIO_BSRR_BR4;
}
Esempio n. 4
0
void
if_spiInit(hwInterface *iface)
{
  unsigned int i;
  *AT91C_PIOA_SODR = AT91C_PA11_NPCS0;
  *AT91C_PIOA_PER = AT91C_PA11_NPCS0;
  for(i=0;i<20;i++) {
    if_spiSend(iface, 0xff);
  }
  *AT91C_PIOA_PDR = AT91C_PA11_NPCS0;
}
Esempio n. 5
0
void if_spiInit(hwInterface *iface)
{
	euint8 i;
	
	/* Unselect card */
	PORTB |= 0x01;
	
	/* Set as master, clock and chip select output */
	DDR_SPI = (1<<DD_MOSI) | (1<<DD_SCK) | 1;

	/* Enable SPI, master, set clock rate to fck/2 */
	SPCR = (1<<SPE) | (1<<MSTR); /* fsck / 4 */ 
	SPSR = 1; /* fsck / 2 */

	/* Send 10 spi commands with card not selected */
	for(i=0;i<10;i++)
		if_spiSend(iface,0xff);

	/* Select card */
	PORTB &= 0xFE;
}
Esempio n. 6
0
void if_spiUnselectDevice(hwInterface* file)
{
  if_spiSend(file,0xff); /* release DO */
  P3OUT |= (1<<DD_CS);
}