使用GD32F303RET6,接SPI flash GPA4和GPC4作为两个SPI FLASH的片选脚,PA5,PA6,PA7为SPI pin,发现除了CS有变化,SPI的MOSI MISO SCLK都没有波形,代码如下,请高手点拨一下。
rcu_periph_clock_enable(RCU_GPIOA);
rcu_periph_clock_enable(RCU_GPIOB);
rcu_periph_clock_enable(RCU_GPIOC);
rcu_periph_clock_enable(RCU_GPIOD);
rcu_periph_clock_enable(RCU_AF);
rcu_periph_clock_enable(RCU_USART1);
rcu_periph_clock_enable(RCU_USART0);
gpio_pin_remap_config(GPIO_SWJ_SWDPENABLE_REMAP,ENABLE);
rcu_periph_clock_enable(RCU_SPI0);
/* SPI0_SCK(PA5), SPI0_MISO(PA6) and SPI0_MOSI(PA7) GPIO pin configuration */
gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_5 | GPIO_PIN_7);
gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_6);
/* SPI0_CS(PA4) GPIO pin configuration */
gpio_init(GPIOA, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_4);
//cs2
gpio_init(GPIOC, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_4);
/* 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_8;
spi_init_struct.endian = SPI_ENDIAN_MSB;
spi_init(SPI0, &spi_init_struct);
/* enable SPI0 */
spi_enable(SPI0);
调用的地方是读RDID
/*!
\brief read flash identification
\param[in] none
\param[out] none
\retval flash identification
*/
uint32_t spi_flash_read_id(void)
{
uint32_t temp = 0, temp0 = 0, temp1 = 0, temp2 = 0;
/* select the flash: chip select low */
SPI_FLASH_CS_LOW();
/* send "RDID " instruction */
spi_flash_send_byte(0x9F);
/* read a byte from the flash */
temp0 = spi_flash_send_byte(DUMMY_BYTE);
/* read a byte from the flash */
temp1 = spi_flash_send_byte(DUMMY_BYTE);
/* read a byte from the flash */
temp2 = spi_flash_send_byte(DUMMY_BYTE);
/* deselect the flash: chip select high */
SPI_FLASH_CS_HIGH();
temp = (temp0 << 16) | (temp1 << 8) | temp2;
return temp;
}
读出来的id是0 ,通过示波器看,CLK,也没有MOSI 以及MISO 均没有波形,spi flash init部分是GD32F303的demo code中来的
|