#define ADC_Pin_CS GPIO_Pin_12//PB
#define ADC_Pin_SCLK GPIO_Pin_13//PB
#define ADC_Pin_DOUT GPIO_Pin_14//PB
#define ADC_Pin_DIN GPIO_Pin_15//PB
#define ADC_Pin_SYNC GPIO_Pin_8//PD
#define ADC_GPIO_CS GPIOB//PB
#define ADC_GPIO_SCLK GPIOB//PB
#define ADC_GPIO_DOUT GPIOB//PB
#define ADC_GPIO_DIN GPIOB//PB
#define ADC_GPIO_SYNC GPIOD//PD
#define ADC_SPI SPI2//
void ADC_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD , ENABLE);
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = ADC_Pin_SYNC;
GPIO_Init(ADC_GPIO_SYNC , &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = ADC_Pin_SCLK;
GPIO_Init(ADC_GPIO_SCLK, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = ADC_Pin_DIN;
GPIO_Init(ADC_GPIO_DIN, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = ADC_Pin_DOUT;
GPIO_Init(ADC_GPIO_DOUT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = ADC_Pin_CS;
GPIO_Init(ADC_GPIO_CS, &GPIO_InitStructure);
ADC_CS(H);
ADC_SYNC(H);
}
void ADC_SPI_Init(void)
{
SPI_InitTypeDef SPI_InitStructure;
/* SPI1 configuration ------------------------------------------------------*/
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_High;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; //
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;//;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(ADC_SPI, &SPI_InitStructure);
/*Enable SPIx.NSS as a GPIO*/
SPI_SSOutputCmd(ADC_SPI, ENABLE);
SPI_Cmd(ADC_SPI, ENABLE);
}
uint16_t ADC_RW(uint16_t data)
{
while (SPI_I2S_GetFlagStatus(ADC_SPI, SPI_I2S_FLAG_TXE) == RESET);
/* Send SPIx data */
SPI_I2S_SendData(ADC_SPI, data);
while (SPI_I2S_GetFlagStatus(ADC_SPI, SPI_I2S_FLAG_RXNE) == RESET);
return SPI_I2S_ReceiveData(ADC_SPI);;
}
ADC_RW(0xAA);
SCLK 输出低电平! MOSI有数据输出. SCLK 无信号
但是添加代码运行
GPIO_SetBits(ADC_GPIO_SCLK,ADC_Pin_SCLK);
GPIO_ResetBits(ADC_GPIO_SCLK,ADC_Pin_SCLK);
引脚电平则有高低输出 上面配置不变
实在搞不懂是什么问题了.求高手解答....
(I/O 口全部悬空测量) |