我正在使用GD32F450ZIT6 SPI0(PB3,PB4,PB5) 读取SPI FLASH (WINBAND 25Q128JVSQ和GD 25Q127CSIG都试过)
读取得FLASH ID正确,但是读数据都是0xFF.
读写函数是“GD32F450IxH6_Demo板资料包/gd25qxx.c”中的
void spi_flash_buffer_write(uint8_t* pbuffer, uint32_t write_addr, uint16_t num_byte_to_write);
void spi_flash_buffer_read(uint8_t* pbuffer, uint32_t read_addr, uint16_t num_byte_to_read);
其他代码:
void spi_flash_init(void)
{
spi_parameter_struct spi_init_struct;
rcu_periph_clock_enable(RCU_GPIOB);
rcu_periph_clock_enable(RCU_GPIOG);
rcu_periph_clock_enable(RCU_SPI0);
/* SPI0_CLK(PB3), SPI0_MISO(PB4), SPI0_MOSI(PB5) GPIO pin configuration */
gpio_af_set(GPIOB, GPIO_AF_5, GPIO_PIN_3|GPIO_PIN_4| GPIO_PIN_5);
gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_3|GPIO_PIN_4| GPIO_PIN_5);
gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_3|GPIO_PIN_4| GPIO_PIN_5);
/* SPI0_CS(PG13) GPIO pin configuration */
gpio_mode_set(GPIOG, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_13);
gpio_output_options_set(GPIOG, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, GPIO_PIN_13);
/* chip select invalid*/
SPI_FLASH_CS_HIGH();
/* SPI0 parameter config */
spi_init_struct.trans_mode = SPI_TRANSMODE_FULLDUPLEX;
spi_init_struct.device_mode = SPI_MASTER;
spi_init_struct.frame_size = SPI_FRAMESIZE_8BIT;
spi_init_struct.clock_polarity_phase = SPI_CK_PL_LOW_PH_1EDGE;
spi_init_struct.nss = SPI_NSS_SOFT;
spi_init_struct.prescale = SPI_PSC_32;
spi_init_struct.endian = SPI_ENDIAN_MSB;
spi_init(SPI0, &spi_init_struct);
/* set crc polynomial */
spi_crc_polynomial_set(SPI0,7);
/* enable SPI0 */
spi_enable(SPI0);
}
int main(void)
{
spi_flash_init();
uint16_t i;
uint32_t flash_id = 0;
uint8_t tx_buffer[256];
uint8_t rx_buffer[256];
flash_id = spi_flash_read_id();
printf("\r\nThe Flash_ID:0x%X\r\n",flash_id);
printf("spi_flash_buffer_write!\r\n");
for(i = 0; i < 256; i++){
tx_buffer[i] = i;
rx_buffer[i] = 0x55;
printf("0x%02X ", tx_buffer[i]);
}
printf("\r\n");
/* erase the specified flash sector */
spi_flash_sector_erase(0);
delay_ms(100);
/* write tx_buffer data to the flash */
spi_flash_buffer_write(tx_buffer,0,256);
delay_ms(100);
/* read a block of data from the flash to rx_buffer */
spi_flash_buffer_read(rx_buffer,0,256);
printf("Check SPI flash the data!\r\n");
/* printf rx_buffer value */
for(i = 0; i < 256; i ++){
printf("0x%02X ", rx_buffer[i]);
}
printf("\r\n");
}
|