新手入门
- 积分
- 3
- 金钱
- 3
- 注册时间
- 2021-12-11
- 在线时间
- 0 小时
|
1金钱
控制12位AD输出不了电压,所有寄存器都配置完成,就是输出不了电压,希望大佬可以解答,附上代码:#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "AD5722.h"
#include "Relay.h"
#include "adc.h"
int main()
{
u16 adcx;
float temp;
delay_init(); //延时函数初始化
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级
uart_init(115200); //串口初始化为115200
delay_init(); //延时函数初始化
Adc_Init(); //ADC初始化
LED_Init(); //LED端口初始化
RELAY_Init(); //继电器初始化
AD5722_Init(); //DAC初始化
while(1)
{
//信号指示流水灯
LED0=0;
LED1=1;
delay_ms(300); //延时300ms
LED0=1;
LED1=0;
delay_ms(300); //延时300ms
DA_Write_DAC(ADD_DAC_A,4096);//输出10V
delay_ms(10);
DA_Write_Control(LOAD,0,0,0,0);//更新DAC寄存器,更新输出
}
}
#include "AD5722.h"
#include "stm32f10x.h"
#include "stm32f10x_spi.h"
#include "stdio.h"
#include "delay.h"
#include "spi.h"
//static void delay_nus(unsigned int nus)
//{
// unsigned int i = 0;
// while(nus--)
// {
// for(i=0; i<12; i++);//延时一段时间
// }
//}
void AD5722_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//SPI1初始化
SPI1_Init();
//PB5 SYNC /PB6 CLR /PB7 LDAC
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //使能PB;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
CLR_LOW;//拉低CLR,开始清零
delay_ms(10);//计数粗略延时
CLR_HIGH;//拉高CLR,停止清零
LDAC_LOW;//保持LDAC低电平,寄存器在SYNC上升沿更新
//通道A输出控制
SYNC_LOW;//拉低,允许传输
DA_Write_Control(CLEAR,0,0,0,0);//DAC写入,清零DAC寄存器,更新输出
delay_ms(10);
DA_Write_Range(ADD_DAC_A,RANGE0_10V);//输出范围0-10V设置
delay_ms(10);
DA_Write_Power(POWER_A);//DAC A上电
delay_ms(10);
SYNC_HIGH;//拉高,禁止数据传输
}
//写DAC寄存器
uint32_t DA_Write_DAC(uint8_t address, uint16_t data)//DA_Write_DAC(ADD_DAC_A,2000);//输出10V
{
uint32_t ReturnData;
SYNC_LOW;//拉低,允许传输
ReturnData = SPI2_ReadWriteByte(address);
ReturnData = (uint32_t) ((SPI2_ReadWriteByte((data >> 4) & 0xff)) << 16);
ReturnData = (uint32_t) ((SPI2_ReadWriteByte((data << 4) & 0xf0)) << 8);
SYNC_HIGH;//拉高,禁止数据传输,并更新寄存器数据
return ReturnData;
}
//写RANGE寄存器
uint32_t DA_Write_Range(uint8_t address, uint8_t range)//DA_Write_Range(ADD_DAC_A,RANGE0_10V);
{
uint32_t ReturnData;
SYNC_LOW;//拉低,允许传输
ReturnData = SPI2_ReadWriteByte(address | REG0_1);
ReturnData = (uint32_t) (SPI2_ReadWriteByte(0) << 16);
ReturnData = (uint32_t) (SPI2_ReadWriteByte(range) << 8);
SYNC_HIGH;//拉高,禁止数据传输
return ReturnData;
}
//写CONTROL寄存器
uint32_t DA_Write_Control(uint8_t mode, uint8_t tsd, uint8_t clamp, uint8_t clr, uint8_t sdo)//DA_Write_Control(LOAD,0,0,0,0);//更新DAC寄存器,更新输出
{
uint32_t ReturnData;
SYNC_LOW;//拉低,允许传输
ReturnData = SPI2_ReadWriteByte(mode | REG0_1 | REG1_1);
ReturnData = (uint32_t) (SPI2_ReadWriteByte(0) << 16);
ReturnData = (uint32_t) (SPI2_ReadWriteByte(tsd | clamp | clr | sdo) << 8);
SYNC_HIGH;//拉高,禁止数据传输
return ReturnData;
}
//写POWER寄存器
uint32_t DA_Write_Power(uint8_t pu)
{
uint32_t ReturnData;
SYNC_LOW;//拉低,允许传输
ReturnData = SPI2_ReadWriteByte(REG1_1);//传八位打开控制寄存器
ReturnData = (uint32_t) (SPI2_ReadWriteByte(ALERT_OCB) << 16);
ReturnData = (uint32_t) (SPI2_ReadWriteByte(ALERT_OCA | TSD | pu) << 8);
SYNC_HIGH;//拉高,禁止数据传输
return ReturnData;
}
|
|