2017-12-02 22 views
0

SPI1を使用しているSTM32F407のFLASHメモリで整数データを保存して復元したいとします。私はFLASHにこのコードのような指示を与えました。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); 

しかし、rxData[0]で、それだけでFFHAL_SPI_TransmitReceive()後にしています。メーカーIDを確認したい

おかげさまで、

答えて

0

W25Qフラッシュモジュールにデータを書き込むには、以下の手順に従ってください。

  1. を書きたい
  2. 消去チップまたはアドレスを有効に書くには、あなたは以下の機能を使用することができます

に対処するために、再度

  • 書き込み件のデータを有効に書きます。

    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 
    } 
    
  • 関連する問題