本帖最后由 skay5288 于 2022-4-14 09:44 编辑
最近在使用GD32E230K8T6配置SPI通信时,发现SPI1在主机模式下,接收时间段内居然无时钟输出,导致读取到的数据全部为0;而实际上MISO线上是有电平变化的;时序如下图所示:
因为刚开始使用GD库的时候,发现SPIEN位设置不成功,没办法只能自己写了SPI1的初始化程序了,如下:
void a7196_spi_init(void)
{
uint32_t reg_value = 0;
rcu_periph_clock_enable(RCU_SPI1);
SPI_CTL0(SPI1) = 0x00;
//SPI_CTL0(SPI1) |= SPI_PSC_16; //1,设置分频
SPI_CTL0(SPI1) |= SPI_PSC_256; //1,设置分频
SPI_CTL0(SPI1) |= SPI_CK_PL_LOW_PH_1EDGE; //2,设置模式
//SPI_CTL0(SPI1) |= SPI_CK_PL_LOW_PH_2EDGE; //2,设置模式
//...3
SPI_CTL1(SPI1) = 0x00;
SPI_CTL1(SPI1) |= SPI_FRAMESIZE_8BIT; //4,设置数据格式,8位
SPI_CTL1(SPI1) |= SPI_CTL1_BYTEN; //4,设置数据寄存器的访问大小,一个字节
//SPI_CTL1(SPI1) |= SPI_CTL1_NSSDRV; //5
//...6,...7
SPI_CTL0(SPI1) |= SPI_CTL0_MSTMOD; //8
SPI_CTL0(SPI1) |= SPI_CTL0_SWNSS;
SPI_CTL0(SPI1) |= SPI_CTL0_SWNSSEN;
SPI_CTL0(SPI1) |= SPI_CTL0_SPIEN; //...9,...10,11
/* select SPI mode */
SPI_I2SCTL(SPI1) &= (uint32_t)(~SPI_I2SCTL_I2SSEL);
}
收发采用GD的库函数的:
spi_i2s_data_transmit(SPI1, addr);
data = spi_i2s_data_receive(SPI1);
请问高手,这是哪里配置有问题呢?我该怎么修改呢?
|