int fm25cx_writestatus(u8 status) { //LCD_CS_HIGH();
FM25CX_WP_HIGH();
FM25CX_CS_LOW(); SPI_I2S_SendData(SPI2, 0x06); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); FM25CX_CS_HIGH();
FM25CX_CS_LOW(); SPI_I2S_SendData(SPI2, 0x01); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); SPI_I2S_SendData(SPI2, status); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); FM25CX_CS_HIGH();
FM25CX_WP_LOW();
return 1; }
int fm25cx_readbyte(u16 addr, u16 *value) { //LCD_CS_HIGH();
FM25CX_CS_LOW();
SPI_I2S_SendData(SPI2, 0x03); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); SPI_I2S_SendData(SPI2, addr >> 8); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); SPI_I2S_SendData(SPI2, addr & 0xff); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET); *value = SPI_I2S_ReceiveData(SPI2);
FM25CX_CS_HIGH();
return 1; }
int fm25cx_writebyte(u16 addr, u8 value) { //LCD_CS_HIGH();
fm25cx_writestatus(0x00);
FM25CX_WP_HIGH();
FM25CX_CS_LOW(); SPI_I2S_SendData(SPI2, 0x06); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); FM25CX_CS_HIGH();
FM25CX_CS_LOW(); SPI_I2S_SendData(SPI2, 0x02); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); SPI_I2S_SendData(SPI2, addr >> 8); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); SPI_I2S_SendData(SPI2, addr & 0xff); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); SPI_I2S_SendData(SPI2, value); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); FM25CX_CS_HIGH();
FM25CX_WP_LOW();
fm25cx_writestatus(0x8c);
return 1; } |