STM32并口驱动AD9854——HAL库
2015-07-15 08:59
344 查看
并口方式:
//对AD9854写地址和数据
void ad9854_write(uint16_t add,uint16_t cmd)
{
GPIOA->ODR=((GPIOA->ODR)&0xff00)+cmd;
GPIOE->ODR=((GPIOE->ODR)&0xff00)+add;
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,GPIO_PIN_RESET);
HAL_Delay(2);
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,GPIO_PIN_SET);
}
//reset
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,GPIO_PIN_SET);//WR无效
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,GPIO_PIN_RESET);//UD CLK 0
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,GPIO_PIN_SET);//reset 1
HAL_Delay(20);
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,GPIO_PIN_RESET);//reset 0
ad9854_write(0x1d,0x10);//关闭比较器
ad9854_write(0x1e,0x0a);//设置系统时钟倍频 30*10
ad9854_write(0x1f,0x02);//模式:FSK 外部更新
ad9854_write(0x20,0x60);//设置为可调节幅度,取消插值补偿
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,GPIO_PIN_SET);//UDCLK 1 ¸更新输出
HAL_Delay(20);
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,GPIO_PIN_RESET);//UDCLK 0
//init
//31M 1A 74 0D A7 40 D5
ad9854_write(0x04,0x1A);
ad9854_write(0x05,0x74);
ad9854_write(0x06,0x0D);
ad9854_write(0x07,0xA7);
ad9854_write(0x08,0x40);
ad9854_write(0x09,0xD5);
//30M 19 99 99 99 99 94
ad9854_write(0x0A,0x19);
ad9854_write(0x0B,0x99);
ad9854_write(0x0C,0x99);
ad9854_write(0x0D,0x99);
ad9854_write(0x0E,0x99);
ad9854_write(0x0F,0x94);
//设置I通道幅度
const uint16_t shape=4000;//幅值设置,为12bit,取值范围为0~4095
ad9854_write(0x21,shape>>8);//设置I通道幅度
ad9854_write(0x22,(uint8_t)(shape&0xff));
ad9854_write(0x23,shape>>8);//设置Q通道幅度
ad9854_write(0x24,(uint8_t)(shape&0xff));
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,GPIO_PIN_SET);//UDCLK 1 ¸更新输出
HAL_Delay(20);
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,GPIO_PIN_RESET);//UDCLK 0
程序包下载地址:http://download.csdn.net/detail/u014357799/8900409
//对AD9854写地址和数据
void ad9854_write(uint16_t add,uint16_t cmd)
{
GPIOA->ODR=((GPIOA->ODR)&0xff00)+cmd;
GPIOE->ODR=((GPIOE->ODR)&0xff00)+add;
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,GPIO_PIN_RESET);
HAL_Delay(2);
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,GPIO_PIN_SET);
}
//reset
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,GPIO_PIN_SET);//WR无效
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,GPIO_PIN_RESET);//UD CLK 0
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,GPIO_PIN_SET);//reset 1
HAL_Delay(20);
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,GPIO_PIN_RESET);//reset 0
ad9854_write(0x1d,0x10);//关闭比较器
ad9854_write(0x1e,0x0a);//设置系统时钟倍频 30*10
ad9854_write(0x1f,0x02);//模式:FSK 外部更新
ad9854_write(0x20,0x60);//设置为可调节幅度,取消插值补偿
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,GPIO_PIN_SET);//UDCLK 1 ¸更新输出
HAL_Delay(20);
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,GPIO_PIN_RESET);//UDCLK 0
//init
//31M 1A 74 0D A7 40 D5
ad9854_write(0x04,0x1A);
ad9854_write(0x05,0x74);
ad9854_write(0x06,0x0D);
ad9854_write(0x07,0xA7);
ad9854_write(0x08,0x40);
ad9854_write(0x09,0xD5);
//30M 19 99 99 99 99 94
ad9854_write(0x0A,0x19);
ad9854_write(0x0B,0x99);
ad9854_write(0x0C,0x99);
ad9854_write(0x0D,0x99);
ad9854_write(0x0E,0x99);
ad9854_write(0x0F,0x94);
//设置I通道幅度
const uint16_t shape=4000;//幅值设置,为12bit,取值范围为0~4095
ad9854_write(0x21,shape>>8);//设置I通道幅度
ad9854_write(0x22,(uint8_t)(shape&0xff));
ad9854_write(0x23,shape>>8);//设置Q通道幅度
ad9854_write(0x24,(uint8_t)(shape&0xff));
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,GPIO_PIN_SET);//UDCLK 1 ¸更新输出
HAL_Delay(20);
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,GPIO_PIN_RESET);//UDCLK 0
程序包下载地址:http://download.csdn.net/detail/u014357799/8900409
相关文章推荐
- linux中strcpy strncpy memcpy sprintf snprintf区别总结
- Cocos观察者设计模式和通报机制
- Android 使用zxing包生成中间有logo的二维码图片
- windows 下redis使用
- 自适应网页设计(Responsive Web Design)
- 如何写出无法维护的代码
- oracle rac 日志体系结构
- Android 优化SQLite数据库
- asp.net弹出层实例
- 编程中的命名设计那点事
- Cookie
- 技术需要沉淀
- Activity、Task、应用和进程
- 程序命名的一些提示
- Android Hardware Acceleration(硬件加速)详解
- 编程命名中的7+1个提示
- org.springframework.core.BridgeMethodResolver异常的解决
- U盘版Win10家庭版和专业版在美国亚马逊开启预订:家庭版120美元
- Java Bean 简介及其应用
- Codeforces Round #312 (Div. 2)