STM32F100片外ADS1248,对寄存器操作不成功,求解…
代码如下
GPIO定义:
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_11; // SCLK、DIN、START
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; // DOUT
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; // DRDY
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOB, &GPIO_InitStructure);
void ADS1248WREG(unsigned char regaddr,unsigned char databyte)
{
ADS1248SPI(0x40+(regaddr&0x0F));
ADS1248SPI(0X00);
ADS1248SPI(databyte);
}
unsigned char ADS1248RREG(unsigned char regaddr)
{
unsigned char r=0X00;
ADS1248SPI(0x20+(regaddr&0x0F));
ADS1248SPI(0X00);
r=ADS1248SPI(0XFF);
return r;
}
unsigned char ADS1248SPI(unsigned char m)
{
unsigned char i,r=0;
for(i=0;i<8;i++) {
ADS1248_SCLK(1);
__NOP();__NOP();__NOP();__NOP();__NOP();
r<<=1;
if (m & 0x80) ADS1248_SADI(1);
else ADS1248_SADI(0);
__NOP();__NOP();__NOP();__NOP();__NOP();
ADS1248_SCLK(0);
__NOP();__NOP();__NOP();__NOP();__NOP();
if (GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_9)>0) r++;
__NOP();__NOP();__NOP();__NOP();__NOP();
m<<=1;
}
return r;
}
ADS1248WREG(0X00,0x01); // MUX0=00 000 001 = 0x01 AIN1
iads=ADS1248RREG(0X00);
按照官方给出的图纸设计电路,然后按照时序给RESERT、START信号,后续WREG、RREG、READDATA等都正常,一定要注意时序,不同MCU时间间隔不一样!
还有啥问题Q群:77203167