标签归档:w25q128

LPC1768读写W25Q128程序

uint8_t W25QXX_Buf[4096];

GPIO设置

/*SPI pin set*/

PinCfg.Funcnum = PINSEL_FUNC_3;

PinCfg.Portnum = 0;

PinCfg.Pinmode = PINSEL_PINMODE_TRISTATE;

PinCfg.Pinnum = SPI_SCK;

PINSEL_ConfigPin(&PinCfg);

PinCfg.Pinnum = SPI_MOSI;

PINSEL_ConfigPin(&PinCfg);

PinCfg.Pinnum = SPI_MISO;

PINSEL_ConfigPin(&PinCfg);

PinCfg.Funcnum = PINSEL_FUNC_0;

PinCfg.Portnum = 0;

PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL;

PinCfg.Pinnum = SPI_CS;

PINSEL_ConfigPin(&PinCfg);

GPIO_SetDir(0, (1<<SPI_CS), 1);

GPIO_SetValue(0, (1<<SPI_CS));

void Spi_Initial(void)

{

SPI_CFG_Type spi0;

spi0.CPHA = SPI_CPHA_FIRST;

spi0.CPOL = SPI_CPOL_LO;

spi0.ClockRate = 3125000; //spi_clk = 25000000,25000000/8=3125000,能使用的最高频率

spi0.DataOrder = SPI_DATA_MSB_FIRST;

spi0.Databit = SPI_DATABIT_8;

spi0.Mode = SPI_MASTER_MODE;

SPI_Init(LPC_SPI,&spi0);

}

uint8_t SPIF_POLLING(void)

{

uint8_t n = 0xff;

while (n–)

{

if (LPC_SPI->SPSR & 0x80)

return TRUE;

}

return FALSE;

}

继续阅读