This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

help me on 2808' spi to the dac of tlv5638

Other Parts Discussed in Thread: TLV5638, TLV5637

1,I writed a program for 2808's spi to slv5638 as bellow,but the results were error occasionally,why?

2,Where can I find such referrence program?can you sent me a example?

thank you.

/
/
// TITLE: DSP280x DAC Initialization & Support Functions.
//
//###########################################################################
// $TI Release: DSP280x,
// $Release Date: August 7th, 2008 $
//refer to Example_280xSpi_FFDLB.c
//###########################################################################

#include "DSP280x_Device.h"     // DSP280x Headerfile Include File
#include "DSP280x_Examples.h"   // DSP280x Examples Include File
#include "adc_function.h"
#include "dac_function.h"


void dac_init(DAC2CH *p)
{   
 SpiaRegs.SPICCR.bit.SPISWRESET = 0;         // Reset SPI
 SpiaRegs.SPICCR.all =0x004F;              //  falling edge, 16-bit char bits 
 SpiaRegs.SPICTL.all =0x000E;           // Enable master mode, SPICLK with delayed,
                                                 // enable talk, and SPI int disabled.
 SpiaRegs.SPIBRR =0x0005;                  //spi baud rate=100/5+1=16.6M/bps        
    SpiaRegs.SPIPRI.all = 0x0010;                // Set so breakpoints don't disturb xmission

// Initialize SPI FIFO registers
    SpiaRegs.SPIFFTX.all=0xC040;                //reset fifo pointer 
    SpiaRegs.SPIFFCT.all=0x0;

 SpiaRegs.SPICCR.bit.SPISWRESET = 1;         // Enable SPI
    SpiaRegs.SPIFFTX.bit.TXFIFO=1;              //enable fifo
    SpiaRegs.SPIFFRX.bit.RXFIFORESET=1;

    SpiaRegs.SPITXBUF=DAC_FIG_INIT;             // 0xD002
    SpiaRegs.SPITXBUF=DAC_B_INIT;               //0x4000
    SpiaRegs.SPITXBUF=DAC_A_INIT;              //0xC000
//    spi_xmit(DAC_FIG_INIT);           
//    spi_xmit(DAC_B_INIT);            
//    spi_xmit(DAC_A_INIT);           
}                                              

 

//for TLV5638:outputB:0100,aaaa,aaaa,aaaa  outputA:1100,aaaa,aaaa,aaaa  aaaa,aaaa,aaaa=12_bit DAC
//for TLV5637:outputB:0100,aaaa,aaaa,aa00  outputA:1100,aaaa,aaaa,aa00  aaaa,aaaa,aa=10_bit DAC
void dac_xmita(DAC2CH *p)
{
// write word to FIFO 
    SpiaRegs.SPITXBUF = (p->ChA & 0x0FFF) | 0xC000;
}

void dac_xmitb(DAC2CH *p)
{
// write word to FIFO 
    SpiaRegs.SPITXBUF = (p->ChB & 0x0FFF) | 0x4000;
}

 


void main(void)
{
.........
    SysCtrlRegs.HISPCP.all = 0x0000;     // HISCLK=SYSCLKOUT/1 =100M
    SysCtrlRegs.LOSPCP.all = 0x0000;      //LOSCLK= SYSCLKOUT/1 =100M
.........
}

  • Is this code that you obtained from an example?  If so, would you please indicate the source?

    What results do you see on the SPI interface pins to the TLV5638?  Is there any activity if you look at it on an oscilloscope?

  • The code didn't  come from an example.could you find some examples of slv5638 for me?thank you

     

  • Thank you for the background of the code example you provided.  This helps.

    What results do you see on the SPI interface pins to the TLV5638?
    Is there any activity if you look at it on an oscilloscope?

     

  • 1,The results  on the SPI interface pins to the TLV5638  satisfy   tlv5638' timing demands

    2,But the results are errors ocassinally.

    3,Whether there are some bug on the program for 2808'spi ?Could you give me some tips on it?

     

     

     

      

  • xufeihx said:

    1,The results  on the SPI interface pins to the TLV5638  satisfy   tlv5638' timing demands

    Okay.  I see that you appear to be using the "falling edge with delay", SPICCR.6 = 1 and SPICTL.3 = 1 SPI clocking scheme.  Another choice might be the "rising edge without delay" SPICCR.6 = 0 and SPICTL.3 = 0.

     

    xufeihx said:

    2,But the results are errors ocassinally.

    What are the errors that you are seeing?  Can you describe the sequences in the application code and the resultant output of the TLV5638?

  • some primer of working code for TLV5638 (avr asm):

     

      ;=================================================

      ; Initialization 5638 >

      ;==================================================

      cbi SPSR,0; SPI X1

      in resTemp,SPCR;

      cbr resTemp,0b11111111

      sbr resTemp,0b01010100;

      out SPCR,resTemp; SPI master CPOL=0, CPHA=1, k=1/4 (~3,7Mhz)

      nop;

      nop;

      nop;

      nop;

      ;==================================================

      cbi PortB,DAC0_CS; CS DAC low level

      ;==================================================

      ldi resTemp,0b10010000;

      out SPDR,resTemp; transmitt to DAC highest byte of control register

      InitDAC_1:

      sbis SPSR,7; wait while transmit

        rjmp InitDAC_1;

      ;

      ldi resTemp,0b00000010;

      out SPDR,resTemp; transmitt to DAC lowest byte of control register (2,048V)

      InitDAC_2:

      sbis SPSR,7; wait while transmit

        rjmp InitDAC_2;

      ;=================================================

      sbi PortB,DAC0_CS; CS DAC to high level

      ;=================================================

      cbi SPCR,6; SPI OFF;

      ;=================================================

      ; < Initialization 5638

      ;=================================================

     

     

    ;=================================================

    ;DATA TO DAC

    ;   

    cbi SPSR,0; SPI X1

    in mainTempL,SPCR;

    cbr mainTempL,0b11111111;

    sbr mainTempL,0b01010100;

    out SPCR,mainTempL; SPI master CPOL=0, CPHA=1, K=1/4 (~3.7 MHz)

    nop;

    nop;

    nop;

    nop;

    ;

    cbi PortB,DAC0_CS; CS low

    ;

    cbr mainTempB,0b11110000; mask high tetrade

    sbr mainTempB,0b00000000;

    out SPDR,mainTempB; High Byte to DAC

    mainResetDAC_1:

    sbis SPSR,7; wait trasmitt

    rjmp mainResetDAC_1;

    ;

    out SPDR,mainTempA; ПЕРЕДАЧА В ЦАП младшего БАЙТА

    mainResetDAC_2:

    sbis SPSR,7; пропуск если передача завершена

    rjmp mainResetDAC_2;

    ;

    sbi PortB,DAC0_CS; CS high

    cbi SPCR,6; SPI OFF

    ;=================================================