2017-12-02 35 views
0

SPI1을 사용하는 STM32F407에서 내 플래시 메모리로 정수 데이터를 저장하고 복원하려고합니다. 나는이 코드처럼 FLASH에 지시를 내렸다. rxData[0]에서 HAL 드라이버가있는 STM32F4에서 W25Q16 플래시 메모리를 사용하는 방법은 무엇입니까?

uint8_t txData[10] = {0xAB, 0x04, 0x06, 0xC7, 0x04, 0x90, 0x00, 0x00, 0x00, 0x00}; 
uint8_t rxData[10] = {0}; 

HAL_SPI_Init(&hspi1); 
HAL_SPI_Transmit(&hspi1, txData+5, 1, 10000); 
HAL_SPI_Transmit(&hspi1, txData+6, 1, 10000); 
HAL_SPI_Transmit(&hspi1, txData+7, 1, 10000); 
HAL_SPI_Transmit(&hspi1, txData+8, 1, 10000); 
HAL_SPI_TransmitReceive(&hspi1, txData+9, rxData, 1, 10000); 

하지만, 그것은 단지 FFHAL_SPI_TransmitReceive() 있습니다. 제조사 ID를보고 싶습니다.

도움을 주셔서 감사합니다.

답변

0

W25Q 플래시 모듈에 데이터를 쓰려면 다음 단계를 따라야합니다.

  1. 당신은 다음과 같은 기능을 사용할 수 있습니다

를 해결하기 위해 다시

  • 쓰기 datas 수 있도록 쓰기 쓰고 싶은
  • 지우기 칩 또는 주소를 가능하게 작성합니다.

    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 
    }