资源简介
AD9833可编程信号发生器驱动代码,STM32F1+UCOS-II平台,已经使用在项目中
代码片段和文件信息
//----------------------------------------------------------------
// INCLUDES
//----------------------------------------------------------------
#include “stm32f10x.h“
#include “config.h“
#include “stm32f10x_rcc.h“
#include “stm32f10x_gpio.h“
#include “ad9833.h“
#include “xprintf.h“
void AD9833_SetPhase(uint32 type);
void AD9833_CS1_High(void)
{
GPIOD->BSRR = GPIO_Pin_3;
}
void AD9833_CS1_Low(void)
{
GPIOD->BRR = GPIO_Pin_3;
}
void AD9833_CS2_High(void)
{
GPIOD->BSRR = GPIO_Pin_6;
}
void AD9833_CS2_Low(void)
{
GPIOD->BRR = GPIO_Pin_6;
}
void AD9833_CLK_High(void)
{
GPIOD->BSRR = GPIO_Pin_4;
}
void AD9833_CLK_Low(void)
{
GPIOD->BRR = GPIO_Pin_4;
}
void AD9833_SDI_High(void)
{
GPIOD->BSRR = GPIO_Pin_5;
}
void AD9833_SDI_Low(void)
{
GPIOD->BRR = GPIO_Pin_5;
}
void GPIO_AD9833_Init(void)
{
GPIO_AD9833_PORT->BSRR = GPIO_AD9833_SCLK_PIN;
GPIO_AD9833_PORT->BSRR = GPIO_AD9833_FSYNC1_PIN;
GPIO_AD9833_PORT->BSRR = GPIO_AD9833_FSYNC2_PIN;
}
void AD9833_WriteData(uint16 dat)
{
int32 i;
GPIO_AD9833_PORT->BSRR = GPIO_AD9833_SCLK_PIN;
GPIO_AD9833_PORT->BRR = GPIO_AD9833_FSYNC1_PIN;
Delay(5);
//send data
for(i = 0; i < 16; i++)
{
if(dat & 0x8000)
{
GPIO_AD9833_PORT->BSRR = GPIO_AD9833_MOSI_PIN;
}
else
{
GPIO_AD9833_PORT->BRR = GPIO_AD9833_MOSI_PIN;
}
Delay(2);
GPIO_AD9833_PORT->BRR = GPIO_AD9833_SCLK_PIN;
Delay(2);
dat = dat << 1;
GPIO_AD9833_PORT->BSRR = GPIO_AD9833_SCLK_PIN;
Delay(2);
}
GPIO_AD9833_PORT->BSRR = GPIO_AD9833_FSYNC1_PIN;
Delay(2);
}
void AD9833_WriteData2(uint16 dat)
{
int32 i;
GPIO_AD9833_PORT->BSRR = GPIO_AD9833_SCLK_PIN;
GPIO_AD9833_PORT->BRR = GPIO_AD9833_FSYNC2_PIN;
Delay(5);
//send data
for(i = 0; i < 16; i++)
{
if(dat & 0x8000)
{
GPIO_AD9833_PORT->BSRR = GPIO_AD9833_MOSI_PIN;
}
else
{
GPIO_AD9833_PORT->BRR = GPIO_AD9833_MOSI_PIN;
}
Delay(2);
GPIO_AD9833_PORT->BRR = GPIO_AD9833_SCLK_PIN;
Delay(2);
dat = dat << 1;
GPIO_AD9833_PORT->BSRR = GPIO_AD9833_SCLK_PIN;
Delay(2);
}
GPIO_AD9833_PORT->BSRR = GPIO_AD9833_FSYNC2_PIN;
Delay(2);
}
void AD9833_SetOutputMode(uint8 mode)
{
}
int AD9833_Sine_SetFreq(uint32 freq)
{
uint64 tmp64;
uint32 dat;
if (freq > HIGH_FREQ_LIMIT)
{
xprintf(“AD9833_Sine_SetFreq frequency %dHz over range!\r\n“ freq);
return -1;
}
if (freq < LOW_FREQ_LIMIT)
{
xprintf(“AD9833_Sine_SetFreq frequency %dHz over range!\r\n“ freq);
return -1;
}
tmp64 = 0x10000000;
tmp64 = tmp64 * freq;
tmp64 = tmp64 / MCLK_FREQ;
AD9
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 7013 2015-09-29 15:59 AD9833\ad9833.c
文件 1417 2015-09-29 15:59 AD9833\ad9833.h
文件 524032 2015-06-24 14:53 AD9833\AD9833_CH.pdf
文件 751104 2015-06-24 14:04 AD9833\AD9833应用笔记.doc
目录 0 2016-01-20 10:16 AD9833
----------- --------- ---------- ----- ----
1283566 5
评论
共有 条评论