使用hc32f460,SPI1,发送0x55,测试时钟和MOSI引脚电平,变化正常。miso脚一直是高电平,但是SPI读出来数据一直是0x00,按理说应该是0xff。SPI 配置如下
#define SD_SPI_PERIPH_CLK FCG1_PERIPH_SPI1
#define SPI_SD CM_SPI1
#define SD_SPI_CS_PORT GPIO_PORT_A
#define SD_SPI_CS_PIN GPIO_PIN_04
#define SD_SPI_PORT GPIO_PORT_A
#define SD_SPI_SCK_PIN GPIO_PIN_05
#define SD_SPI_MISO_PIN GPIO_PIN_06
#define SD_SPI_MOSI_PIN GPIO_PIN_07
#define SD_SPI_SCK_PIN_FUNC (GPIO_FUNC_43)
#define SD_SPI_MOSI_PIN_FUNC (GPIO_FUNC_40)
#define SD_SPI_MISO_PIN_FUNC (GPIO_FUNC_41)
static void App_SPIxCfg(void)
{
stc_gpio_init_t stcGpioInit;
stc_spi_init_t stcSpiInit;
stc_spi_delay_t stcSpiDelayCfg;
(void)GPIO_StructInit(&stcGpioInit);
stcGpioInit.u16PinDrv = PIN_HIGH_DRV;
(void)GPIO_Init(SD_SPI_CS_PORT, SD_SPI_CS_PIN, &stcGpioInit);
(void)GPIO_Init(SD_SPI_PORT, SD_SPI_SCK_PIN, &stcGpioInit);
(void)GPIO_Init(SD_SPI_PORT, SD_SPI_MOSI_PIN, &stcGpioInit);
stcGpioInit.u16PinDir = PIN_DIR_OUT;
(void)GPIO_Init(SD_SPI_CS_PORT, SD_SPI_CS_PIN, &stcGpioInit);
GPIO_SetFunc(SPI_SCK_PORT, SPI_SCK_PIN, SD_SPI_SCK_PIN_FUNC);
GPIO_SetFunc(SPI_MOSI_PORT, SPI_MOSI_PIN, SD_SPI_MOSI_PIN_FUNC);
GPIO_SetFunc(SPI_MISO_PORT, SPI_MISO_PIN, SD_SPI_MISO_PIN_FUNC);
/* Clear initialize structure */
(void)SPI_StructInit(&stcSpiInit);
(void)SPI_DelayStructInit(&stcSpiDelayCfg);
/* Configure peripheral clock */
FCG_Fcg1PeriphClockCmd(SD_SPI_PERIPH_CLK, ENABLE);
/* SPI De-initialize */
SPI_DeInit(SPI_UNIT);
/* Configuration SPI structure */
stcSpiInit.u32WireMode = SPI_3_WIRE;
stcSpiInit.u32TransMode = SPI_FULL_DUPLEX;
stcSpiInit.u32MasterSlave = SPI_MASTER;
stcSpiInit.u32ModeFaultDetect = SPI_MD_FAULT_DETECT_DISABLE;
stcSpiInit.u32Parity = SPI_PARITY_INVD;
stcSpiInit.u32SpiMode = SPI_MD_0;
stcSpiInit.u32BaudRatePrescaler = SPI_BR_CLK_DIV4;
stcSpiInit.u32DataBits = SPI_DATA_SIZE_8BIT;
stcSpiInit.u32FirstBit = SPI_FIRST_MSB;
(void)SPI_Init(SPI_UNIT, &stcSpiInit);
stcSpiDelayCfg.u32IntervalDelay = SPI_INTERVAL_TIME_8SCK;
stcSpiDelayCfg.u32ReleaseDelay = SPI_RELEASE_TIME_8SCK;
stcSpiDelayCfg.u32SetupDelay = SPI_SETUP_TIME_1SCK;
(void)SPI_DelayTimeConfig(SPI_UNIT, &stcSpiDelayCfg);
SPI_Cmd(SPI_UNIT, ENABLE);
}
|