SPI设置
void SPI1_Init(void)
{
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_128;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure);
SPI_Cmd(SPI1, ENABLE); //使能SPI1
}
注意:
1、CPOL 应设置为 0,CPOL表示时钟线 SCK空闲时的电平高低,高1低0,根据CS5532手册可知,SDO读时序和SDI写时序,时钟空闲时为低,单片机要与CS5532通信,当然应该一致。
2、SPI_BaudRatePrescaler 大一点比较好,太小读数会出错。
SPI设置
void SPI1_Init(void)
{
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_128;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure);
SPI_Cmd(SPI1, ENABLE); //使能SPI1
}
注意:
1、CPOL 应设置为 0,CPOL表示时钟线 SCK空闲时的电平高低,高1低0,根据CS5532手册可知,SDO读时序和SDI写时序,时钟空闲时为低,单片机要与CS5532通信,当然应该一致。
2、SPI_BaudRatePrescaler 大一点比较好,太小读数会出错。
1
举报
-
jf_60474043:
用过,好像是硬件威廉希尔官方网站
设计的问题,cs5532有两个电源,数字电源如果用3.3V,输出就会一直是高电平