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

ARM7 LPC2138 SPIO issues

I am attempting to communicate as a master with the Phillips LPC2138 over the SPI0 interface with a digital potentiometer. The potentiometer does not have a serial output feeding back into the LPC2138. In the debugger when you track the registers for the SPI0 peripheral the data that I write to be transmitted never shows up in the S0SPDR. Below is the relevant code that I use to interface with the SPI0.

The initializing code is given below:

 /***********************************************/
void InitLampControl(void)
{
        /* set pins to use SPI interface as follows: */
        /* P0.4 as SPI SCK0 */
        /* P0.5 as SPI MISO0 */
        /* P0.6 as SPI MOSI0 */
        /* P0.7 as SPI SSEL_POT */
        PINSEL0 = PINSEL0 | 0x00001500;

        /* set SPI clock divider */
        /* PCLK is 14.7456 MHz */
        /* want SPI clock about 7MHz */
        /* set SPI clock divider to 148, divider value must be even */
        S0SPCCR = 148;  /* decimal value */

        /* set SPI control register */
        /* 16 bit data, phase 0, SCK active high, master */
        /* MSb first, interrupts inactive */
        S0SPCR = 0x0024;

        /* Set P0.7 (GPIO7 "SSEL_POT") as an output tied low */
        IODIR0 = 0x00000080;
        IOSET0 = 0x00000080; /* SSEL_POT = 1 */

        /* set interrupt addr for SPI interface */
        /* VICVectAddr5 = (unsigned long) SPI0IRQHandler; */
        /* enable vectored interrupt for slot 5 and assign to SPI */
        /* VICVectCntl5 = 0x2A; */
        /* enable interrupts for SPI interface */
        /* VICIntEnable = VICIntEnable | 0x400; */
}

and the following code is what I used to try and send the data to the digital potentiometer

           /* write value to AD5290 out the SPI interface */
                g_SPIReady = FALSE;

                IOCLR0 = 0x00000080;    /* set SSEL low to target POT */
                S0SPDR = 0x11E3;
                do
                {
                        nDummyRead = S0SPSR;
                        if((nDummyRead & 0x80)==0x80)
                        {
                                nDummyRead = S0SPDR;
                                g_SPIReady = TRUE;
                        }
                }
                while (g_SPIReady==FALSE); /* wait for end of transfer */
                IOSET0 = 0x00000080; /* set SSEL back high */

Any help or suggestions as to why my code is not communicating correctly would be greatly appreciated.
Thanks
Jonathan

Parents
  • The data written to S0SPDR is transmitted over SPI and the data which is received in parallel is shown in S0SPDR after the transmission is completed (SPIF set in S0SPSR).

    Since you don't have the serial output from potentiometer connected back you will never read back anything useful. But this is not a problem since you use the data sent from LPC to setup the potentiometer value.

    The AD5290 is a 256 position digital potentiometer and accepts 8 bit SPI data and not 16 bits like you use in your example and therefore might not work as expected.

    Note also that reading the status register will also clear the status flags in this register. Therefore debugging with open dialog might disrupt the application.

Reply
  • The data written to S0SPDR is transmitted over SPI and the data which is received in parallel is shown in S0SPDR after the transmission is completed (SPIF set in S0SPSR).

    Since you don't have the serial output from potentiometer connected back you will never read back anything useful. But this is not a problem since you use the data sent from LPC to setup the potentiometer value.

    The AD5290 is a 256 position digital potentiometer and accepts 8 bit SPI data and not 16 bits like you use in your example and therefore might not work as expected.

    Note also that reading the status register will also clear the status flags in this register. Therefore debugging with open dialog might disrupt the application.

Children
No data