PIC Microcontoller Input / Ouput Method

SPI interface to AD7730

Tony Kübek, [tony.kubek at flintab.com] of Flintab AB says:

;*************** AnalogDevices AD7730 *******************

; for writing to registers
#define SELECT_WR_COMM          0x00    ; base adress for communication register
#define SELECT_WR_MODE          0x02    ; select mode reg write
#define SELECT_WR_FILTER        0x03    ; select filter reg write
#define SELECT_WR_DAC           0x04    ; select dac reg write
#define SELECT_WR_OFFSET        0x05    ; select offset reg write
#define SELECT_WR_GAIN          0x06    ; select gain reg write

; for reading registers
#define SELECT_RD_STATUS        0x10    ; read status reg once
        #define SELECT_RD_STATUS_CNT    0x20 ; continous read status cycle
        #define SELECT_RD_STATUS_END    0x30 ; returns to one write/read cycle

#define SELECT_RD_DATA          0x11    ; read data reg once
        #define SELECT_RD_DATA_CNT      0x21 ; continuos read data cycle
        #define SELECT_RD_DATA_END      0x30 ; returns to one write/read cycle

#define SELECT_RD_MODE          0x12    ; read mode reg once
        #define SELECT_RD_MODE_CNT      0x22 ; continous read mode cycle
        #define SELECT_RD_MODE_END      0x30 ; return to one write/read cycle

#define SELECT_RD_FILTER        0x13    ; read filter reg
#define SELECT_RD_DAC           0x14    ; read dac reg
#define SELECT_RD_OFFSET        0x15    ; read offset reg
#define SELECT_RD_GAIN          0x16    ; read gain reg

I use an pseudo SPI routine called AD_SEND_BYTE thats sends the byte in W to the AD7730 AND returns with the ( eventual ) byte from the AD in W. To read DATA reg:

        MOVLW   SELECT_RD_DATA
        CALL    AD_SEND_BYTE    ; send request
        
        MOVLW   0x00            ; dummy byte
        CALL    AD_SEND_BYTE    ; get top byte
        MOVWF   AD_NewValue     ; store it

        MOVLW   0x00            ; dummy byte
        CALL    AD_SEND_BYTE    ;
        MOVWF   AD_NewValue+1   ; store it
        
        MOVLW   0x00            ; dummy byte
        CALL    AD_SEND_BYTE    ;
        MOVWF   AD_NewValue+2   ; store it

Or to read status byte from AD:

        ; read AD status reg 
        MOVLW   SELECT_RD_STATUS
        CALL    AD_SEND_BYTE    ; send request
        
        MOVLW   0x00            ; dummy byte
        PCALL   AD_SEND_BYTE    ; get byte
        MOVWF   AD_Status

Interested:

Questions:

Questions:

See also:

See: