用
STM32F207控制,AD5315供电和参考电压都是3.3V,结果无电压输出,以下是相关代码:
void main(void)
{
int i,j;
SystemInit();
delay_init(120);
GPIO_Init();
SPI_Init();
GPIOA->ODR |= SCLK_5315;
GPIOA->ODR |= SDA_5315;
GPIOA->ODR = ~A0_5315;
Write_5315(DACA,0x3FF);
while(1);
}
void Write_5315(u8 number,u16 data)
{
int i;
u8 AddressByte=0x18;
u8 PointerByte;
u16 DataByte;
switch(number)
{
case DACA:
PointerByte=0x01;
break;
case DACB:
PointerByte=0x02;
break;
case DACC:
PointerByte=0x04;
break;
case DACD:
PointerByte=0x08;
break;
default :break;
}
DataByte=0x3000|(data<<2);
//address byte
for(i=7;i>=0;i--)
WriteOneBit((AddressByte>>i) 0x01);
WriteOneBit(0);//wait
//pointer byte
for(i=7;i>=0;i--)
WriteOneBit((PointerByte>>i) 0x01);
WriteOneBit(0);//waite
//DataByte
for(i=15;i>=0;i--)
WriteOneBit((DataByte>>i) 0x01);
WriteOneBit(0);//wait
WriteOneBit(0);//wait
GPIOA->ODR |= SDA_5315;
}
void WriteOneBit(u8 bit)
{
if(bit)
{
GPIOA->ODR =~ SCLK_5315;
delay_us(1);
GPIOA->ODR |= SDA_5315;
delay_us(1);
GPIOA->ODR |= SCLK_5315;
delay_us(1);
}
else
{
GPIOA->ODR =~ SCLK_5315;
delay_us(1);
GPIOA->ODR =~ SDA_5315;
delay_us(1);
GPIOA->ODR |= SCLK_5315;
delay_us(1);
}
}