2013-10-17

CooCox SSP learning notes

SSP: LPC11xx Synchronous Serial Port Driver [from SSP Help]

Overview

The SPI/SSP is a Synchronous Serial Port (SSP) controller capable of operation on a SPI, 4-wire SSI, or Microwire bus. It can interact (with frames of 4 bits to 16 bits of data) with multiple masters and slaves on the bus. 

Usage

1. Enable SSP block clock using SYSCON_AHBPeriphClockCmd() (see SYSCON). 

2. Using SSP_SSPxPinsInit() to assign SSP0 or SSP1 pins. 

3. Init SSP using SSP_Init(). 

4. Enable SSP peripheral's operation using SSP_Cmd(). 

5. Then you can use SSP_SendData() and SSP_ReceiveData() or SSP_ReadWrite() for data transfer. 

Source files

lpc11xx_ssp.h 

lpc11xx_ssp.c 

Dependency

SYSCON    IOCON    

*******************************************************************************
1. Enable SSP block clock using SYSCON_AHBPeriphClockCmd() (see SYSCON). 
*******************************************************************************

/* Enable SSP0 block clock */
SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_SSP0, ENABLE);

References: 

/*********************************************************************//**
 * @brief               Configure power supply for each peripheral according to NewState
 * @param[in]   Periph  Type of peripheral used to enable power,
 *                                      should be one of the following:
 *              -  SYSCON_AHBPeriph_SYS        : AHB to APB bridge
 *              -  SYSCON_AHBPeriph_ROM        : ROM
 *              -  SYSCON_AHBPeriph_RAM        : RAM
 *              -  SYSCON_AHBPeriph_FLASHREG   : Flash register interface
 *              -  SYSCON_AHBPeriph_FLASHARRAY : Flash array access
 *              -  SYSCON_AHBPeriph_I2C        : I2C
 *              -  SYSCON_AHBPeriph_GPIO       : GPIO
 *              -  SYSCON_AHBPeriph_CT16B0     : 16-bit counter/timer 0
 *              -  SYSCON_AHBPeriph_CT16B1     : 16-bit counter/timer 1
 *              -  SYSCON_AHBPeriph_CT32B0     : 32-bit counter/timer 0
 *              -  SYSCON_AHBPeriph_CT32B1     : 32-bit counter/timer 1
 *              -  SYSCON_AHBPeriph_SSP0       : SSP0
 *              -  SYSCON_AHBPeriph_UART       : UART
 *              -  SYSCON_AHBPeriph_ADC        : ADC
 *              -  SYSCON_AHBPeriph_WDT        : WDT
 *              -  SYSCON_AHBPeriph_IOCON      : IOCON
 *              -  SYSCON_AHBPeriph_SSP1       : SSP1             
 * @param[in]   NewState        New state of Peripheral Power, should be:
 *                              - ENABLE        : Enable power for this peripheral
 *                              - DISABLE       : Disable power for this peripheral
 *
 * @return none
 **********************************************************************/

void SYSCON_AHBPeriphClockCmd(uint32_t Periph, FunctionalState NewState)
{
    if(NewState == DISABLE) {
        LPC_SYSCON->SYSAHBCLKCTRL &= (~Periph) & SYSCON_AHBPeriph_BITMASK;
    } else if (NewState == ENABLE) {
        LPC_SYSCON->SYSAHBCLKCTRL |= Periph & SYSCON_AHBPeriph_BITMASK;    
    }   
}

/*********************************************************************//**
 * @brief               Configures the SPI0 peripheral clock SPI0_PCLK. The 
 *              SPI0_PCLK can be shut down by setting the DIV bits to 0x0.
 * @param[in]   DivVal  Value of divider           
 *
 * @return none
 **********************************************************************/
void SYSCON_SetSPI0ClockDiv(uint32_t DivVal)
{
    CHECK_PARAM(PARAM_DIVVAL(DivVal));
    LPC_SYSCON->SSP0CLKDIV = DivVal;
}


/*********************************************************************//**
 * @brief               Configures the SPI1 peripheral clock SPI10_PCLK. The 
 *              SPI10_PCLK can be shut down by setting the DivVal to 0x0.
 * @param[in]   DivVal  Value of divider           
 *
 * @return none
 **********************************************************************/
void SYSCON_SetSPI1ClockDiv(uint32_t DivVal)
{
    CHECK_PARAM(PARAM_DIVVAL(DivVal));
    LPC_SYSCON->SSP1CLKDIV = DivVal;
}




*******************************************************************************
2. Using SSP_SSPxPinsInit() to assign SSP0 or SSP1 pins. 
*******************************************************************************

/ To write later, ...

References: 

xxxxxxxxxx

References: 

void SSP_SSP0PinsInit(SCK0_Position_Typedef sck0, FunctionalState useSSEL);

/********************************************************************//**
 * @brief Assigns SSP0 pins:
 *                MISO : PIO0_8
 *                MOSI : PIO0_9
 *                SCK  : PIO0_10/PIO2_11/PIO0_6
 *                SSEL : PIO0_2
 * @param[in] sck0 Locate SCK0 position, it can be
 *                   SCK0_PIO0_10 : pin location SWCLK/PIO0_10/SCK0/CT16B0_MAT2
 *                                  NOTE: SWCLK is JTAG pin
 *                   SCK0_PIO2_11 : pin location PIO2_11/SCK0
 *                   SCK0_PIO0_6  : pin location PIO0_6/SCK0
 *
 *               Note: SCK0_PIO0_10 is multiplexed with JTAG pins
 * @param[in] useSSEL Assign SSEL pin or not
 * @return None
 *********************************************************************/

void SSP_SSP0PinsInit(SCK0_Position_Typedef sck0, FunctionalState useSSEL)
{
    IOCON_SCK0Locate(sck0);

    IOCON_SetPinFunc(IOCON_PIO0_8, PIO0_8_FUN_MISO0);
    IOCON_SetPinFunc(IOCON_PIO0_9, PIO0_9_FUN_MOSI0);

    if(useSSEL == ENABLE) {
        IOCON_SetPinFunc(IOCON_PIO0_2, PIO0_2_FUN_SSEL0);
    }
           
    switch(sck0) {
    case SCK0_PIO0_10:
        IOCON_SetPinFunc(IOCON_PIO0_10, PIO0_10_FUN_SCK0); break;      
    case SCK0_PIO2_11:
        IOCON_SetPinFunc(IOCON_PIO2_11, PIO2_11_FUN_SCK0); break;
    case SCK0_PIO0_6:
        IOCON_SetPinFunc(IOCON_PIO0_6,  PIO0_6_FUN_SCK0);  break;
    default: break;
    }    

}

*******************************************************************************
3. / To continued, ... 
*******************************************************************************

.END

No comments:

Post a Comment