程序调试快一周了,用软件spi能检测到电压,硬件spi死活检测不到,,,,,配置函数都检查了N次了,引脚也换了好几次,都不行,测的是5V和3.3V还有0V的板子上的电压····
//CS片选
#define RCC_CS RCC_AHB1Periph_GPIOD
#define PORT_CS GPIOD
#define PIN_CS GPIO_Pin_8
//RESET复位
#define RCC_RESET RCC_AHB1Periph_GPIOD
#define PORT_RESET GPIOD
#define PIN_RESET GPIO_Pin_12
//RANGE测量范围
#define RCC_RANGE RCC_AHB1Periph_GPIOD
#define PORT_RANGE GPIOD
#define PIN_RANGE GPIO_Pin_9
//开始转换 CONVSTA,B
#define RCC_CONVST RCC_AHB1Periph_GPIOD
#define PORT_CONVST GPIOD
#define PIN_CONVST GPIO_Pin_6
#define RCC_CONVST2 RCC_AHB1Periph_GPIOD
#define PORT_CONVST2 GPIOD
#define PIN_CONVST2 GPIO_Pin_7
//忙信号BUSY
#define RCC_BUSY RCC_AHB1Periph_GPIOD
#define PORT_BUSY GPIOD
#define PIN_BUSY GPIO_Pin_13
#define AD_CS_SET_0() GPIO_ResetBits(PORT_CS,PIN_CS)
#define AD_CS_SET_1() GPIO_SetBits(PORT_CS,PIN_CS)
#define AD_RESET_SET_0() GPIO_ResetBits(PORT_RESET,PIN_RESET)
#define AD_RESET_SET_1() GPIO_SetBits(PORT_RESET,PIN_RESET)
#define AD_RANGE_SET_5V() GPIO_ResetBits(PORT_RANGE,PIN_RANGE)
#define AD_RANGE_SET_10V() GPIO_SetBits(PORT_RANGE,PIN_RANGE)
#define AD_CONVST_SET_0() GPIO_ResetBits(PORT_CONVST,PIN_CONVST | PIN_CONVST2)
#define AD_CONVST_SET_1() GPIO_SetBits(PORT_CONVST,PIN_CONVST | PIN_CONVST2)
//高电平正在转换 低电平转换结束
#define AD_BUSY_INPUT() GPIO_ReadInputDataBit(PORT_BUSY,PIN_BUSY)
static void AD7606_GPIO_Cfg(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/*****************AD7606 SPI communication interface setting*********************************/
//enable GPIO clock
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
/********enable SPI1 Port PB3,4,5*******/
//++ SPI1
// GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_AF_SPI1);
// GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_SPI1);
// GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_SPI1);
//++ SPI3
GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_AF_SPI3);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_SPI3);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_SPI3);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
//GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/*****************AD7606 Control interface setting*********************************/
RCC_AHB1PeriphClockCmd(RCC_CS | RCC_RANGE | RCC_BUSY | RCC_RESET | RCC_CONVST, ENABLE);
//GPIO output mode
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Pin = PIN_RESET;
GPIO_Init(PORT_RESET, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = PIN_CONVST;
GPIO_Init(PORT_CONVST, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = PIN_CONVST2;
GPIO_Init(PORT_CONVST2, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = PIN_RANGE;
GPIO_Init(PORT_RANGE, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = PIN_CS;
GPIO_Init(PORT_CS, &GPIO_InitStructure);
//OS0
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//OS1
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//OS2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//output low level
GPIO_ResetBits(GPIOD,GPIO_Pin_3 |GPIO_Pin_4 |GPIO_Pin_5);
GPIO_ResetBits(GPIOD,GPIO_Pin_5);
GPIO_ResetBits(GPIOD,GPIO_Pin_3 |GPIO_Pin_4);
//STBY
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//output high level
GPIO_SetBits(GPIOD,GPIO_Pin_11);
//GPIO input mode
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = PIN_BUSY;
GPIO_Init(PORT_BUSY, &GPIO_InitStructure);
}
static void AD7606_SPI_Cfg(void)
{
SPI_InitTypeDef SPI_InitStructure;
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_RxOnly;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;
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_64;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
//++ SPI1
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
// SPI_Init(SPI1, &SPI_InitStructure);
// SPI_Cmd(SPI1, ENABLE);
//++ SPI3
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);
SPI_Init(SPI3, &SPI_InitStructure);
SPI_Cmd(SPI3, ENABLE);
}
static uint16_t AD7606_SPI_Read_Data(void)
{
uint16_t read;
//++ SPI1
// while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
// SPI_I2S_SendData(SPI1, 0);
// while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
// read = SPI_I2S_ReceiveData(SPI1);
//++ SPI3
while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI3, 0);
while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_RXNE) == RESET);
read = SPI_I2S_ReceiveData(SPI3);
return read;
}
static void AD7606_Start_Convert(void)
{
AD_CONVST_SET_0();
AD_CONVST_SET_0();
AD_CONVST_SET_0();
AD_CONVST_SET_0();
AD_CONVST_SET_1();
}
static void AD76060_Reset(void)
{
AD_RESET_SET_0();
//高电平复位 维持50ns
AD_RESET_SET_1();
AD_RESET_SET_1();
AD_RESET_SET_1();
AD_RESET_SET_1();
AD_RESET_SET_1();
AD_RESET_SET_1();
AD_RESET_SET_0();
}
void AD7606_Read_8_Channel_Data(void)
{
static uint8_t led_status=0;
if(AD_BUSY_INPUT()== Bit_RESET)
{
AD_CS_SET_0();
for(int i=0;i<8;i++)
{
AD_data[i] = AD7606_SPI_Read_Data();
//AD_data[i] = AD_data[i]*256+AD7606_SPI_Read_Data();
printf("
value=%f
",AD_data[i]);
delay_ms(250);
}
AD_CS_SET_1();
// LED_ON();
//读取完数据 继续转换
AD7606_Start_Convert();
}
}
void AD7606_Init(void)
{
AD7606_GPIO_Cfg();
AD7606_SPI_Cfg();
//设置采样范围
AD_RANGE_SET_5V();
//复位
AD76060_Reset();
//启动转换
AD7606_Start_Convert();
}
以第二个为准
一周热门 更多>