有没有大神用过STM32控制AD7903的,我想要驱动程序,拜托各位大神了
答案:1 悬赏:70 手机版
解决时间 2021-11-17 02:02
- 提问者网友:書生途
- 2021-11-16 06:37
有没有大神用过STM32控制AD7903的,我想要驱动程序,拜托各位大神了
最佳答案
- 五星知识达人网友:酒安江南
- 2021-11-16 07:54
//================AD9834.h======================//
#ifndef __AD9834_H
#define __AD9834_H
#include "stm32f10x_lib.h"
#define Triangle_Wave
0x2002
#define Sine_Wave
0x2028
#define AD9834_SYSTEM_COLCK
50000000UL
#define AD9834_Control_Port
GPIOC
#define AD9834_FSYNC
GPIO_Pin_6
#define AD9834_SCLK
GPIO_Pin_7
#define AD9834_SDATA
GPIO_Pin_8
#define AD9834_RESET
GPIO_Pin_9
#define AD9834_FSYNC_SET
GPIO_SetBits(AD9834_Control_Port ,AD9834_FSYNC)
#define
AD9834_FSYNC_CLR
GPIO_ResetBits(AD9834_Control_Port ,AD9834_FSYNC)
#define AD9834_SCLK_SET
GPIO_SetBits(AD9834_Control_Port ,AD9834_SCLK)
#define AD9834_SCLK_CLR
GPIO_ResetBits(AD9834_Control_Port ,AD9834_SCLK)
#define AD9834_SDATA_SET
GPIO_SetBits(AD9834_Control_Port ,AD9834_SDATA)
#define
AD9834_SDATA_CLR
GPIO_ResetBits(AD9834_Control_Port ,AD9834_SDATA)
#define AD9834_RESET_SET
GPIO_SetBits(AD9834_Control_Port ,AD9834_RESET)
#define
AD9834_RESET_CLR
GPIO_ResetBits(AD9834_Control_Port ,AD9834_RESET)
#define FREQ_0
0
#define FREQ_1
1
#define DB15
0
#define DB14
0
#define DB13
B28
#define DB12
HLB
#define DB11
FSEL
#define DB10
PSEL
#define DB9
PIN_SW
#define DB8
RESET
#define DB7
SLEEP1
#define DB6
SLEEP12
#define DB5
OPBITEN
#define DB4
SIGN_PIB
#define DB3
DIV2
#define DB2
0
#define DB1
MODE
#define DB0
0
#define
CONTROL_REGISTER
(DB15<<15)|(DB14<<14)|(DB13<<13)|(DB12<<12)|(DB11<<1
1)|(DB10<<10)\
|(DB9<<9)|(DB8<<8)|(DB7<<7)|(DB6<<6)|(DB5<<5)|(DB4<<4)|(DB3<<3)|(DB2<<2)|(D
B1<<1)|(DB0<<0)
extern void AD9834_Write_16Bits(unsigned int data)
//
写一个字到
AD9834
extern void AD9834_Select_Wave(unsigned int initdata) //
选择输出波形
extern void Init_AD9834() //
初始化配置
extern void AD9834_Set_Freq(unsigned char freq_number, unsigned long freq) //
选择输
出寄存器和输出频率值
#endif
//================================================================//
//====================AD9834.c====================================//
#include "stm32f10x_lib.h"
#include "AD9834.h"
void AD9834_Write_16Bits(unsigned int data)
{
unsigned char i = 0
AD9834_SCLK_SET
AD9834_FSYNC_CLR
for(i=0 i<16 i++)
{
if(data & 0x8000)
AD9834_SDATA_SET
else
AD9834_SDATA_CLR
AD9834_SCLK_CLR
data <<= 1
AD9834_SCLK_SET
}
AD9834_FSYNC_SET
}
void AD9834_Select_Wave(unsigned int initdata)
{
AD9834_FSYNC_SET;
AD9834_SCLK_SET;
AD9834_RESET_SET;
AD9834_RESET_SET;
AD9834_RESET_CLR;
AD9834_Write_16Bits(initdata);
}
void Init_AD9834()
{
GPIO_InitTypeDef GPIO_InitStructure
GPIO_InitStructure.GPIO_Pin = AD9834_FSYNC | AD9834_SCLK | AD9834_SDATA |
AD9834_RESET
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP
GPIO_Init(AD9834_Control_Port ,&GPIO_InitStructure)
}
void AD9834_Set_Freq(unsigned char freq_number, unsigned long freq)
{
unsigned long FREQREG = (unsigned
long)(268435456.0/AD9834_SYSTEM_COLCK*freq);
unsigned int FREQREG_LSB_14BIT = (unsigned int)FREQREG;
unsigned int FREQREG_MSB_14BIT = (unsigned int)(FREQREG>>14);
if(freq_number == FREQ_0)
{
FREQREG_LSB_14BIT &= ~(1U<<15);
FREQREG_LSB_14BIT |= 1<<14;
FREQREG_MSB_14BIT &= ~(1U<<15);
FREQREG_MSB_14BIT |= 1<<14;
}
else
{
FREQREG_LSB_14BIT &= ~(1<<14);
FREQREG_LSB_14BIT |= 1U<<15;
FREQREG_MSB_14BIT &= ~(1<<14);
FREQREG_MSB_14BIT |= 1U<<15;
}
AD9834_Write_16Bits(FREQREG_LSB_14BIT);
AD9834_Write_16Bits(FREQREG_MSB_14BIT);
}
//============================================================//
写得不是很好,拿出来分享一下,希望大家能够提点建议!
1234567890ABCDEFGHIJKLMNabcdefghijklmn!@#$%^&&*()_+.一三五七九贰肆陆扒拾,。青玉案元夕东风夜放花千树更吹落星如雨宝马雕车香满路凤箫声动玉壶光转一夜鱼龙舞蛾儿雪柳黄金缕笑语盈盈暗香去众里寻他千百度暮然回首那人却在灯火阑珊处
如果你觉得我的答案还可以,请给个好评吧!谢谢!
#ifndef __AD9834_H
#define __AD9834_H
#include "stm32f10x_lib.h"
#define Triangle_Wave
0x2002
#define Sine_Wave
0x2028
#define AD9834_SYSTEM_COLCK
50000000UL
#define AD9834_Control_Port
GPIOC
#define AD9834_FSYNC
GPIO_Pin_6
#define AD9834_SCLK
GPIO_Pin_7
#define AD9834_SDATA
GPIO_Pin_8
#define AD9834_RESET
GPIO_Pin_9
#define AD9834_FSYNC_SET
GPIO_SetBits(AD9834_Control_Port ,AD9834_FSYNC)
#define
AD9834_FSYNC_CLR
GPIO_ResetBits(AD9834_Control_Port ,AD9834_FSYNC)
#define AD9834_SCLK_SET
GPIO_SetBits(AD9834_Control_Port ,AD9834_SCLK)
#define AD9834_SCLK_CLR
GPIO_ResetBits(AD9834_Control_Port ,AD9834_SCLK)
#define AD9834_SDATA_SET
GPIO_SetBits(AD9834_Control_Port ,AD9834_SDATA)
#define
AD9834_SDATA_CLR
GPIO_ResetBits(AD9834_Control_Port ,AD9834_SDATA)
#define AD9834_RESET_SET
GPIO_SetBits(AD9834_Control_Port ,AD9834_RESET)
#define
AD9834_RESET_CLR
GPIO_ResetBits(AD9834_Control_Port ,AD9834_RESET)
#define FREQ_0
0
#define FREQ_1
1
#define DB15
0
#define DB14
0
#define DB13
B28
#define DB12
HLB
#define DB11
FSEL
#define DB10
PSEL
#define DB9
PIN_SW
#define DB8
RESET
#define DB7
SLEEP1
#define DB6
SLEEP12
#define DB5
OPBITEN
#define DB4
SIGN_PIB
#define DB3
DIV2
#define DB2
0
#define DB1
MODE
#define DB0
0
#define
CONTROL_REGISTER
(DB15<<15)|(DB14<<14)|(DB13<<13)|(DB12<<12)|(DB11<<1
1)|(DB10<<10)\
|(DB9<<9)|(DB8<<8)|(DB7<<7)|(DB6<<6)|(DB5<<5)|(DB4<<4)|(DB3<<3)|(DB2<<2)|(D
B1<<1)|(DB0<<0)
extern void AD9834_Write_16Bits(unsigned int data)
//
写一个字到
AD9834
extern void AD9834_Select_Wave(unsigned int initdata) //
选择输出波形
extern void Init_AD9834() //
初始化配置
extern void AD9834_Set_Freq(unsigned char freq_number, unsigned long freq) //
选择输
出寄存器和输出频率值
#endif
//================================================================//
//====================AD9834.c====================================//
#include "stm32f10x_lib.h"
#include "AD9834.h"
void AD9834_Write_16Bits(unsigned int data)
{
unsigned char i = 0
AD9834_SCLK_SET
AD9834_FSYNC_CLR
for(i=0 i<16 i++)
{
if(data & 0x8000)
AD9834_SDATA_SET
else
AD9834_SDATA_CLR
AD9834_SCLK_CLR
data <<= 1
AD9834_SCLK_SET
}
AD9834_FSYNC_SET
}
void AD9834_Select_Wave(unsigned int initdata)
{
AD9834_FSYNC_SET;
AD9834_SCLK_SET;
AD9834_RESET_SET;
AD9834_RESET_SET;
AD9834_RESET_CLR;
AD9834_Write_16Bits(initdata);
}
void Init_AD9834()
{
GPIO_InitTypeDef GPIO_InitStructure
GPIO_InitStructure.GPIO_Pin = AD9834_FSYNC | AD9834_SCLK | AD9834_SDATA |
AD9834_RESET
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP
GPIO_Init(AD9834_Control_Port ,&GPIO_InitStructure)
}
void AD9834_Set_Freq(unsigned char freq_number, unsigned long freq)
{
unsigned long FREQREG = (unsigned
long)(268435456.0/AD9834_SYSTEM_COLCK*freq);
unsigned int FREQREG_LSB_14BIT = (unsigned int)FREQREG;
unsigned int FREQREG_MSB_14BIT = (unsigned int)(FREQREG>>14);
if(freq_number == FREQ_0)
{
FREQREG_LSB_14BIT &= ~(1U<<15);
FREQREG_LSB_14BIT |= 1<<14;
FREQREG_MSB_14BIT &= ~(1U<<15);
FREQREG_MSB_14BIT |= 1<<14;
}
else
{
FREQREG_LSB_14BIT &= ~(1<<14);
FREQREG_LSB_14BIT |= 1U<<15;
FREQREG_MSB_14BIT &= ~(1<<14);
FREQREG_MSB_14BIT |= 1U<<15;
}
AD9834_Write_16Bits(FREQREG_LSB_14BIT);
AD9834_Write_16Bits(FREQREG_MSB_14BIT);
}
//============================================================//
写得不是很好,拿出来分享一下,希望大家能够提点建议!
1234567890ABCDEFGHIJKLMNabcdefghijklmn!@#$%^&&*()_+.一三五七九贰肆陆扒拾,。青玉案元夕东风夜放花千树更吹落星如雨宝马雕车香满路凤箫声动玉壶光转一夜鱼龙舞蛾儿雪柳黄金缕笑语盈盈暗香去众里寻他千百度暮然回首那人却在灯火阑珊处
如果你觉得我的答案还可以,请给个好评吧!谢谢!
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯