AD5065和AD1232使用例程

公司要用这两个芯片,查了半天没查到,只能自己写驱动,下面共享出来吧。

AD5065:

void AD5065_ReadWrite32Bit(u32 cmd)
{
    u8 i;
    AD5065_PDL_Pin_SET();
    AD5065_LDAC_Pin_SET();
    AD5065_SYNC_Pin_SET();
    delay_us(10);
    AD5065_SYNC_Pin_RESET();
    AD5065_CLR_Pin_RESET();
    delay_us(1);
    AD5065_CLR_Pin_SET();
    for(i = 0; i < 32; i++)
    {
        delay_us(1);
        AD5065_SCLK_Pin_SET();
        delay_us(1);
        if(cmd & 0x80000000) AD5065_DIN_Pin_SET();
        else AD5065_DIN_Pin_RESET();
        cmd <<= 1;
        AD5065_SCLK_Pin_RESET();
    }
    AD5065_SYNC_Pin_SET();
    delay_us(1);
    AD5065_PDL_Pin_RESET();
    AD5065_LDAC_Pin_RESET();
    delay_us(1);
    AD5065_LDAC_Pin_SET();
    AD5065_PDL_Pin_SET();
}
void AD5065_SetVol(uint8_t Command, uint8_t  AddressCommands, float Vol)//mV
{
    uint32_t dat = (((Command | AddressCommands) << 16) | ((uint16_t)(Vol/3000.0f*65535))) << 4;
    AD5065_ReadWrite32Bit(dat);
}

AD5065_ReadWrite32Bit为写数据函数,使用的时候调用AD5065_SetVol函数即可,Command 和 AddressCommands参考datasheet,我这里用的如下:

#define AD5065_COMMAND_WRITE_CHANNEL 0x30  //Write to and update DAC Channel n1
#define AD5065_ADDRESS_A 0x00 //DAC A 
#define AD5065_ADDRESS_B 0x03 //DAC B 
#define AD5065_ADDRESS_AB 0x0F //DAC AB通道同时设置一个值

AD1232:

long AD1232_24Bit(void)
{
    int i=0;
    unsigned long ad_value=0;
    ADS1232_Init(0);
    while(HAL_GPIO_ReadPin(AD1232_DOUT_GPIO_Port, AD1232_DOUT_Pin)) {}
    for(i=0; i<24; i++)
    {
        ad_value=ad_value<<1;
        HAL_GPIO_WritePin(AD1232_SCLK_GPIO_Port, AD1232_SCLK_Pin, GPIO_PIN_SET);
        HAL_GPIO_WritePin(AD1232_SCLK_GPIO_Port, AD1232_SCLK_Pin, GPIO_PIN_RESET);
        if(HAL_GPIO_ReadPin(AD1232_DOUT_GPIO_Port, AD1232_DOUT_Pin)==GPIO_PIN_SET)
        {
            ad_value|=0x01;
        }
        else ;
        ad_value &= 0x7fffff;
    }
    HAL_GPIO_WritePin(AD1232_SCLK_GPIO_Port, AD1232_SCLK_Pin, GPIO_PIN_SET);
    delay_us(1);
    HAL_GPIO_WritePin(AD1232_SCLK_GPIO_Port, AD1232_SCLK_Pin, GPIO_PIN_RESET);
    delay_us(1);

    HAL_GPIO_WritePin(AD1232_SCLK_GPIO_Port, AD1232_SCLK_Pin, GPIO_PIN_SET);
    delay_us(1);
    HAL_GPIO_WritePin(AD1232_SCLK_GPIO_Port, AD1232_SCLK_Pin, GPIO_PIN_RESET);
    delay_us(1);
    return ad_value;
}

采用的是HAL库编写,具体要看情况进行修改。

你可能感兴趣的:(AD5065,AD1232)