您的位置:首页 > 其它

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


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: