Вы должны выполнить следующие действия для записи данных во флеш-модули W25Q.
- Запись разрешена
- Стереть чип или адрес, который хотите написать
- Запись разрешена снова
- Напишите данные по адресу
Вы можете использовать следующие функции.
void Flash_Erase_Chip(void)
{
uint8_t Write_Enable = 0x06;
uint8_t Erase_Chip = 0xC7;
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_8,RESET); // CS to low
HAL_SPI_Transmit(&hspi6,&Write_Enable,1,1000); // Write Enable Command
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_8,SET); // CS to high
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_8,RESET); // CS to low
HAL_SPI_Transmit(&hspi6,&Erase_Chip,1,1000); // Erase Chip Command
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_8,SET); // CS to high
}
void Flash_Write_Data()
{
uint8_t Write_Enable = 0x06;
uint8_t Page_Program = 0x02;
uint32_t Address = 0x00000000;
uint8_t txData[10] = {0xAB, 0x04, 0x06, 0xC7, 0x04, 0x90, 0x00, 0x00, 0x00, 0x00};
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_8,RESET); // CS to low
HAL_SPI_Transmit(&hspi6,&Write_Enable,1,1000); // Write Enable Command
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_8,SET); // CS to high
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_8,RESET); // CS to low
HAL_SPI_Transmit(&hspi6,&Page_Program,1,1000);// Page Program Command
HAL_SPI_Transmit(&hspi6,&Address,4,1000); // Write Address ( The first address of flash module is 0x00000000 )
HAL_SPI_Transmit(&hspi6,txData,10,1000); // Write 10 bytes
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_8,SET); // CS to high
}
void Flash_Read_Data
{
uint8_t Read_Data = 0x03;
uint32_t Address = 0x00000000;
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_8,RESET); // CS low
HAL_SPI_Transmit(&hspi6,&Read_Data,1,1000); // Read Command
HAL_SPI_Transmit(&hspi6,&Address,4,1000); // Write Address
HAL_SPI_Receive(&hspi6,rxData,10,1000); // Read 10 bytes
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_8,RESET); // CS high
}
person
Gürtaç Kadem
schedule
10.12.2017