This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem of using LPC2138 to SPI interface with DAC LTC1451

Dear all,

i am trying to use LPC2138 to control LTC1451 (DAC) by SPI protocol. I use Keil MDK-ARM uvision4.
LTC1451: 12 bit, CPHA=0, CPOL=0; When CS is low the CLK signal is enable, so the data can be locked in. When CS is pulled high, data is loaded from the shift register into the DAC register. Load MSB first.
My code is as the following. However, when I simulated with Proteus, it is not as the value that I put in.
- It seems that I am only transferring 8 bit even I set 12 bit transfer in the S0SPCR. For example value = 0x3FF to 0x5FF. Output does not change. Vout=4.09.
- It seems that I am sending LSB even though I am sending MSB first in the S0SPCR.
- I have to send twice the signal so that I can somehow work!
- When value = 0x0F, output is 0.24V but when value=0x10, output=2.06V!
Does anybody knows what the problems are? Is that the problem with the code or with the simulation software?
Any suggestion would be very appreciated. I am stuck now!

#include <LPC213x.H>

void delay();
unsigned int value=0; //0-4095
unsigned int buffer=0;
unsigned char status=0;
int main (void)
{
        VPBDIV          = 0x00000002;   //Set pclk to 30 Mhz
        value = 0x3FF;
        PINSEL0                 =       0x00005500;//Enable SPI0 pins SCK, MISO, MOSI and SSEL
        IODIR0                  =       0x00000400;//Enable Chipselect pin as output


        S0SPCCR                 =       200;    //Set bit timing
        S0SPCR                  =       0x0C64; //Configure as SPI Master interrupts disabled
                                                                                                                        //Transfer MSB first; CPHA=0, CPOL=0; 12 bit transfer

        IOCLR0=0x400; //pull chip select low
        S0SPDR=value;
        while ((S0SPSR&0x80)!=0x80); //wait until value is already transfer
        status = S0SPSR;
        buffer = S0SPDR; //to clear the SPIF bit
        IOSET0 = 0x400; // pull chip select high
        delay(1000);

        IOCLR0=0x400; //pull chip select low
        delay(1000);
        S0SPDR = value;
        while ((S0SPSR&0x80)!=0x80);  //wait until value is already transfer
        status = S0SPSR;
        buffer = S0SPDR; //to clear the SPIF bit
        IOSET0 = 0x400; // pull chip select high
        delay(1000);


}

void delay(unsigned int n)
{
        unsigned int i;
        for(i=0;i<n;i++)
        {
                        ;//do nothing
        }
}

.