static BYTE send_cmd ( BYTE cmd, /* Command byte */ DWORD arg /* Argument */ ) { BYTE n, res; if (cmd & 0x80) { /* ACMD<n> is the command sequense of CMD55-CMD<n> */ cmd &= 0x7F; res = send_cmd(CMD55, 0); if (res > 1) return res; } #if AXI_SPI XStatus Status = XSpi_SetSlaveSelect(&Spi, 0); if(Status != XST_SUCCESS) { xil_printf("Failure Slave Select 0\r\n"); xil_printf("Status = %d\r\n", Status); } rcvr_mmc(); Status = XSpi_SetSlaveSelect(&Spi, 1); if(Status != XST_SUCCESS) { xil_printf("Failure Slave Select 1\r\n"); } rcvr_mmc(); #else /* Select the card */ CS_H(); rcvr_mmc(); CS_L(); rcvr_mmc(); #endif /* Send a command packet */ xmit_mmc(cmd); /* Start + Command index */ xmit_mmc((BYTE)(arg >> 24)); /* Argument[31..24] */ xmit_mmc((BYTE)(arg >> 16)); /* Argument[23..16] */ xmit_mmc((BYTE)(arg >> 8)); /* Argument[15..8] */ xmit_mmc((BYTE)arg); /* Argument[7..0] */ n = 0x01; /* Dummy CRC + Stop */ if (cmd == CMD0) n = 0x95; /* Valid CRC for CMD0(0) */ if (cmd == CMD8) n = 0x87; /* Valid CRC for CMD8(0x1AA) */ xmit_mmc(n); /* Receive a command response */ n = 10; /* Wait for a valid response in timeout of 10 attempts */ do { res = rcvr_mmc(); } while ((res & 0x80) && --n); return res; /* Return with the response value */ }
void LD_reset(void) //芯片复位 { RST_H(); delay_ms(2); RST_L(); delay_ms(2); RST_H(); delay_ms(2); CS_L(); delay_ms(2); CS_H(); delay_ms(2); }
void ld3320_write_reg(uint8 data1,uint8 data2) { CS_L(); SPIS_L(); spi_send_byte(0x04); spi_send_byte(data1); spi_send_byte(data2); CS_H(); }
uint8 ld3320_read_reg(uint8 reg_add) { uint8 i; CS_L(); SPIS_L(); spi_send_byte(0x05); spi_send_byte(reg_add); i=spi_send_byte(0); CS_H(); return(i); }
static BYTE send_cmd ( BYTE cmd, /* Command byte */ DWORD arg /* Argument */ ) { BYTE n, res; if (cmd & 0x80) { /* ACMD<n> is the command sequense of CMD55-CMD<n> */ cmd &= 0x7F; res = send_cmd(CMD55, 0); if (res > 1) return res; } /* Select the card */ CS_H(); rcvr_mmc(); CS_L(); rcvr_mmc(); /* Send a command packet */ XMIT_MMC(cmd); /* Start + Command index */ XMIT_MMC((BYTE)(arg >> 24)); /* Argument[31..24] */ XMIT_MMC((BYTE)(arg >> 16)); /* Argument[23..16] */ XMIT_MMC((BYTE)(arg >> 8)); /* Argument[15..8] */ XMIT_MMC((BYTE)arg); /* Argument[7..0] */ n = 0x01; /* Dummy CRC + Stop */ if (cmd == CMD0) n = 0x95; /* Valid CRC for CMD0(0) */ if (cmd == CMD8) n = 0x87; /* Valid CRC for CMD8(0x1AA) */ XMIT_MMC(n); /* Receive a command response */ n = 10; /* Wait for a valid response in timeout of 10 attempts */ do { res = rcvr_mmc(); } while ((res & 0x80) && --n); return res; /* Return with the response value */ }