已回答假定已回答

关于AD9911的SPI编程问题,请求帮助

angrygrape 在 2013-6-7 詢問的問題
最後回覆由ADI_Wei於2013-6-18提供

我使用PIC18LF4520通过SPI配置AD9911寄存器,测试SDO端口有正确脉冲,SYNC_CLK引脚有25MHz信号(我使用100MHz恒温晶振),IOUT以及IOUTB没有信号输出。我计划使用Single Bit, 2-Wire Mode,实现AD9911点频和频率扫描功能。我将P0、P2、P3、SDIO1悬空了。另附上程序如下,在下先谢过了!

//AD9911Alpha.c

//Single-tone Mode

//12.5MHz is expected

//auhtor cheung, created on 2013/06/06 15:42

#pragma config OSC=HS

#pragma config PWRT=ON, BOREN=OFF

#pragma config WDT=OFF

#pragma config LVP=OFF //configuration bits setting

 

 

#include<p18cxxx.h>

#include<spi.h>

#include<delays.h>

#define uchar unsigned char

#define MRESET LATCbits.LATC1 //AD9911 master reset outpout, PORTC pin1

#define SYNC LATCbits.LATC2 //AD9911 SYNC_IO function output, PORTC pin2

#define SCK LATCbits.LATC3 //Serial CLK

#define SDO LATCbits.LATC5 //Serial Data Output

#define CSN LATDbits.LATD4 //CSN output pin, PORTD pin4

#define UPDATE LATDbits.LATD5 //AD9911 IO_UPDATE function output, PORTD pin5

#define PRO LATDbits.LATD6 //AD9911 Profile Pin1, PORTD pin6

 

 

void Initial(void);

void SPIiniti(void); //function prototypes

 

 

void main()

{

    Initial();

    SPIiniti();

    CSN=0; //CSN Low

    Delay10TCYx(10); //a delay in 40us

          WriteSPI(0b00000000); //instruction byte, write operation, CSR

          WriteSPI(0b00100010); //Phase 2 of IO cycle, disable CH3\CH2\CH0,

    //enable CH1, bit3 must be 0, single bit serial(3-wire mode), MSB first

          WriteSPI(0b00000100); //CTW0 is accessed during phase 2, 4 bytes wide

    WriteSPI(0b00100000); //12.5MHz is expected, FTW, bits<31:24>

          WriteSPI(0b00000000); //bits<23:16>

    WriteSPI(0b00000000); //bits<15:8>

    WriteSPI(0b00000000); //bits<7:0>

    CSN=1; //CSN High

    UPDATE=1; //IO_UPDATE High, a rising edge triggers data transfer from the

    //IO port buffer to active registers

    Delay10TCYx(10); //a delay in 40us

    UPDATE=0; //IO_UPDATE Low

    while(1);

}

 

 

void Initial()

{

    INTCON=0x00;

    PIE1=0x00;

    PIE2=0x00;

          TRISCbits.TRISC1=0; //RESET output

    TRISCbits.TRISC2=0; //SYNC_IO output

          TRISCbits.TRISC3=0; //SCK output

          TRISCbits.TRISC5=0; //SDO output

    TRISDbits.TRISD4=0; //CSN output

    TRISDbits.TRISD5=0; //IO_UPDATE output

    TRISDbits.TRISD6=0; //Profile Pin1 output

    MRESET=1; //Issue a Master Reset

    Delay100TCYx(50); //a delay in 2ms

    MRESET=0; //Master Reset Low

    Delay100TCYx(50); //a delay in 2ms

          SCK=0; //SCK Low

          SDO=0; //SDO Low

    SYNC=0; //SYNC_IO Low

    CSN=1; //CSN High

    UPDATE=0; //IO_UPDATE Low

    PRO=0; //Profile Pin1 Low

}

 

 

void SPIiniti()

{

    OpenSPI(SPI_FOSC_16,MODE_01,SMPEND);

}

結果