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

USB peripheral through SPI interface

I am using the SPI interface to connect the MAX3420e with lpc11A14 mcu and am enabling the GPIO pins of the MAX3420e . Am not finding any signal on the SCLK line of the device. Below mentioned is my code. Kindly help me to achieve the result.

/*****************************************************************************/
#include "lpc11Axx.h"
#include "gpio.h"
#include "spi.h"
#include "type.h"

/*****************************************************************************
** Function name:               SSP_IOConfig
**
** Descriptions:                SSP port initialization routine
**
** parameters:                  None
** Returned value:              None
**
*****************************************************************************/
void SSP_IOConfig( void )
{

        LPC_SYSCON->PRESETCTRL |= (0x1<<0);
        LPC_SYSCON->SYSAHBCLKCTRL |= (0x1<<11);
        LPC_SYSCON->SSP0CLKDIV = 0x1;                        /* Divided by 1 */

        LPC_IOCON->PIO0_22 &= ~0x07;     /*  SSP I/O config */
        LPC_IOCON->PIO0_22 |= 0x01;          /* SSP MISO */
        LPC_IOCON->PIO0_19 &= ~0x07;
        LPC_IOCON->PIO0_19 |= 0x03;          /* SSP MOSI */
        LPC_IOCON->PIO0_20 &= ~0x07;
        LPC_IOCON->PIO0_20 |= 0x01;          /* SSP CLK */

        /* Enable AHB clock to the GPIO domain. */
        LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);

        LPC_IOCON->PIO0_18 &= ~0x07;             /* SSP SSEL is a GPIO pin */

        /* port0, bit 18 is set to GPIO output and high */

        GPIOSetDir(PORT0, 18, 1 );
        GPIOSetBitValue( PORT0, 18, 1 );

}

/*****************************************************************************
** Function name:               SSP_Init
**
** Descriptions:                SSP port initialization routine
**
** parameters:                  None
** Returned value:              None
**
*****************************************************************************/
void SSP_Init( void )
{
  uint8_t i, Dummy=Dummy;

  /* Set DSS data to 8-bit, Frame format SPI, CPOL = 0, CPHA = 0, and SCR is 15 */
        LPC_SSP0->CR0 = 0x0707;

        /* SSPCPSR clock prescale register, master mode, minimum divisor is 0x02 */
        LPC_SSP0->CPSR = 0x2;

        for ( i = 0; i < FIFOSIZE; i++ )
        {
          Dummy = LPC_SSP0->DR;              /* clear the RxFIFO */
        }

                /* Master mode */
        LPC_SSP0->CR1 |= 2;
}

/*****************************************************************************
** Function name:               SSP_Send
**
** Descriptions:                Send a block of data to the SSP port, the
**                                              first parameter is the buffer pointer, the 2nd
**                                              parameter is the block length.
**
** parameters:                  register address, register value
** Returned value:              None
**
*****************************************************************************/
void SPISend( unsigned char Radd,unsigned char Rval )
{
                uint8_t Dummy=Dummy;
                Radd|=0x02;

                /* Move on only if NOT busy and TX FIFO not full. */
                while ( (LPC_SSP0->SR & (SSPSR_TNF|SSPSR_BSY)) != SSPSR_TNF );

                LPC_SSP0->DR = Radd;
                while ( (LPC_SSP0->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE );
                Dummy = LPC_SSP0->DR;

                while ( (LPC_SSP0->SR & (SSPSR_TNF|SSPSR_BSY)) != SSPSR_TNF );

                LPC_SSP0->DR = Rval;
                while ( (LPC_SSP0->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE );
                Dummy = LPC_SSP0->DR;
                return;
}

unsigned char SPIReceive(unsigned char Radd)
{
        unsigned char SPIRECV = 0;
        Radd&=0xFF;


        LPC_SSP0->DR = Radd;
        while ( LPC_SSP0->SR & SSPSR_BSY );

        LPC_SSP0->DR = 0xFF;
        while ( (LPC_SSP0->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE );

        SPIRECV = LPC_SSP0->DR;
        return SPIRECV;
}


/******************************************************************************
**                           Main program
******************************************************************************/

#define SystemCoreClock 12000000UL
#define IOPIN     0xA0
#define PINCTL    0x88
#define USBCTL          0x78

void delay_ms(int y);

uint8_t destination = 0x00;
uint8_t data = 0xF2;
uint8_t f_duplex = 0x10;
uint8_t chip_res = 0x20;
uint8_t dis_reset = 0x00;

unsigned int test;

void delay_ms(int y)          // argument y gives the delay in ms, approximately.
{
   int x,z;
   for(x = 0; x < 60; x++)
   {
      for(z = 0; z < y*100; z++)
      {
      }
   }
}

/* Main Program */

int main (void)
{

  SystemInit();   // for initializing clocks

  /* Enable AHB clock to the GPIO domain. */
  LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);

        LPC_IOCON->PIO0_26 = 0x00;

        UARTInit(9600); // for serial & Printf communication

  /* Set port 1_0 to output */
  GPIOSetDir(0,26,1);

        SSP_IOConfig(); // IO Configuration for EM783-SPI

        SSP_Init();     // Initialize the registers in SPI

  GPIOSetBitValue(PORT0,18,0);   // Slave select

        SPISend(PINCTL,f_duplex);         // Register 17

        delay_ms(1);

        SPISend(USBCTL,chip_res);               // Register 15,  Reset the chip

        SPISend(USBCTL,dis_reset);              // Register 15,  disable Reset the chip

        delay_ms(1);

        SPISend(IOPIN,data);                     // Register 20, set the GPIO pin

        delay_ms(1);

        destination = SPIReceive(PINCTL);       //      Reading the register 20


  while (1)                                /* Loop forever */
  {

                //test = getkey();
                //sendchar(destination);

                /*if(destination== 0x00)
                {
                        GPIOSetBitValue( 0, 26, 0 );
            delay_ms(20);
      GPIOSetBitValue( 0, 26, 1 );
            delay_ms(20);
    }
                else
                {


    }*/

 }

}


0