예제 #1
0
파일: main.c 프로젝트: Wiznet/W7500P
void SSP1_Initialize(void)	//Slave
{
	SSP_StructInit(&SSP1_InitStructure);
	SSP1_InitStructure.SSP_DataSize = SSP_DataSize_8b;
	SSP1_InitStructure.SSP_Mode = SSP_Mode_Slave; // SSP1 = Slave
	SSP_Init(SSP1,&SSP1_InitStructure);
}
예제 #2
0
파일: main.c 프로젝트: Wiznet/W7500P
void SSP0_Initialize(void) //Master
{
	SSP_StructInit(&SSP0_InitStructure);
	SSP0_InitStructure.SSP_FrameFormat  = SSP_FrameFormat_MO; // Motorora SPI mode
	SSP0_InitStructure.SSP_DataSize = SSP_DataSize_8b;
	//SSP0_InitStructure.SSP_BaudRatePrescaler = SSP_BaudRatePrescaler_4;
	SSP_Init(SSP0,&SSP0_InitStructure);
}
예제 #3
0
//-----------------------------------------------------------------//
// Setup SSP module
// HCLK = 32 MHz
// The information rate is computed using the following formula:
//		F_SSPCLK / ( CPSDVR * (1 + SCR) )
// 3.2 MHz
//-----------------------------------------------------------------//
void HW_SSPInit(void)
{
    SSP_InitTypeDef sSSP;
    SSP_StructInit (&sSSP);

    SSP_BRGInit(MDR_SSP2,SSP_HCLKdiv1);		// F_SSPCLK = HCLK / 1

    sSSP.SSP_SCR  = 0x04;		// 0 to 255
    sSSP.SSP_CPSDVSR = 2;		// even 2 to 254
    sSSP.SSP_Mode = SSP_ModeMaster;
    sSSP.SSP_WordLength = SSP_WordLength9b;
    sSSP.SSP_SPH = SSP_SPH_1Edge;
    sSSP.SSP_SPO = SSP_SPO_Low;
    sSSP.SSP_FRF = SSP_FRF_SPI_Motorola;
    sSSP.SSP_HardwareFlowControl = SSP_HardwareFlowControl_SSE;
    SSP_Init (MDR_SSP2,&sSSP);

    SSP_Cmd(MDR_SSP2, ENABLE);
}
예제 #4
0
파일: main.c 프로젝트: Wiznet/W7500
/**
  * @brief  Main Function
  */
int main()
{

    /* Set Systme init */
    SystemInit();
//    *(volatile uint32_t *)(0x41001014) = 0x0060100; //clock setting 48MHz
    
    /* CLK OUT Set */
//    PAD_AFConfig(PAD_PA,GPIO_Pin_2, PAD_AF2); // PAD Config - CLKOUT used 3nd Function
    /* < SSP_StructInit default values
       SSP_InitStructure.SSP_SerialClockRate   = 0x00;
       SSP_InitStructure.SSP_FrameFormat       = SSP_FrameFormat_MO; 
       SSP_InitStructure.SSP_CPHA              = SSP_CPHA_1Edge;   
       SSP_InitStructure.SSP_CPOL              = SSP_CPOL_Low;
       SSP_InitStructure.SSP_DataSize          = SSP_DataSize_8b;
       SSP_InitStructure.SSP_SOD               = SSP_SOD_RESET;
       SSP_InitStructure.SSP_Mode              = SSP_Mode_Master;
       SSP_InitStructure.SSP_NSS               = SSP_NSS_Hard;
       SSP_InitStructure.SSP_LBM               = SSP_LBM_RESET;
       SSP_InitStructure.SSP_SSE               = SSP_SSE_SET;
       SSP_InitStructure.SSP_BaudRatePrescaler = SSP_BaudRatePrescaler_2;
    */

    /* SSP0 Init -- SSP Master */ 
    SSP_StructInit(&SSP0_InitStructure);
    SSP0_InitStructure.SSP_FrameFormat  = SSP_FrameFormat_MO; // Motorora SPI mode
    SSP0_InitStructure.SSP_DataSize = SSP_DataSize_16b;
    SSP_Init(SSP0,&SSP0_InitStructure);

    /* SSP1 Init -- SSP Slave */
    SSP_StructInit(&SSP1_InitStructure);
    SSP1_InitStructure.SSP_DataSize = SSP_DataSize_16b;
    SSP1_InitStructure.SSP_Mode = SSP_Mode_Slave; // SSP1 = Slave
    SSP_Init(SSP1,&SSP1_InitStructure);
        
    /* GPIO LED(R) Setting */
    GPIO_InitDef.GPIO_Pin = GPIO_Pin_8; // Connecting GPIO_Pin_8(LED(R))
    GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT; // Set to GPIO Mode to Output Port
    GPIO_Init(GPIOC, &GPIO_InitDef); // Set to GPIOC
	PAD_AFConfig(PAD_PC,GPIO_Pin_8, PAD_AF1); // PAD Config - LED used 2nd Function

    /* GPIO LED(G) Setting */
    GPIO_InitDef.GPIO_Pin = GPIO_Pin_9; // Connecting GPIO_Pin_9(LED(G))
    GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT; // Set to GPIO Mode to Output Port
    GPIO_Init(GPIOC, &GPIO_InitDef); // Set to GPIOC
	PAD_AFConfig(PAD_PC,GPIO_Pin_9, PAD_AF1); // PAD Config - LED used 2nd Function
            
    GPIO_SetBits(GPIOC, GPIO_Pin_8); // LED red off
    GPIO_SetBits(GPIOC, GPIO_Pin_9); // LED green off
        
    /* Send only data to SSP1 */ 
    for (TxIdx=0; TxIdx<BufferSize; TxIdx++)
    {
        SSP_SendData(SSP0, SSP0_Buffer_Tx[TxIdx]);
        while( SSP_GetFlagStatus(SSP0, SSP_FLAG_BSY) );
    }
    
    /* Receive only data from SSP0 */ 
    while(SSP_GetFlagStatus(SSP1, SSP_FLAG_RNE))
    {
        SSP1_Buffer_Rx[RxIdx] = (uint16_t)SSP_ReceiveData(SSP1);
        RxIdx++;
    }
    
    /* Check the received data with the send ones */
    TransferStatus = Buffercmp(SSP0_Buffer_Tx, SSP1_Buffer_Rx, BufferSize);
    /* TransferStatus = PASSED, if the data transmitted and received are correct */
    /* TransferStatus = FAILED, if the data transmitted and received are different */
    
    if(TransferStatus == PASSED)
    {
        GPIO_ResetBits(GPIOC, GPIO_Pin_9); //Received are correct == LED green On
    }
    else if(TransferStatus == FAILED)
    {
        GPIO_ResetBits(GPIOC, GPIO_Pin_8); //Received are different == LED red On
    }
    
}
예제 #5
0
void main(void)
#endif
{
  RST_CLK_DeInit();
  RST_CLK_CPU_PLLconfig (RST_CLK_CPU_PLLsrcHSIdiv2,0);
  /* Enable peripheral clocks --------------------------------------------------*/
  RST_CLK_PCLKcmd((RST_CLK_PCLK_RST_CLK | RST_CLK_PCLK_SSP1 | RST_CLK_PCLK_SSP2 | RST_CLK_PCLK_DMA),ENABLE);
  RST_CLK_PCLKcmd((RST_CLK_PCLK_PORTF | RST_CLK_PCLK_PORTD), ENABLE);

  /* Init NVIC */
  SCB->AIRCR = 0x05FA0000 | ((uint32_t)0x500);
  SCB->VTOR = 0x08000000;
  /* Disable all interrupt */
  NVIC->ICPR[0] = 0xFFFFFFFF;
  NVIC->ICER[0] = 0xFFFFFFFF;

  /* Disable all DMA request */
  MDR_DMA->CHNL_REQ_MASK_CLR = 0xFFFFFFFF;
  MDR_DMA->CHNL_USEBURST_CLR = 0xFFFFFFFF;

  /* Reset PORTD settings */
  PORT_DeInit(MDR_PORTD);
  /* Reset PORTF settings */
  PORT_DeInit(MDR_PORTF);

  /* Configure SSP2 pins: FSS, CLK, RXD, TXD */

  /* Configure PORTD pins 2, 3, 5, 6 */
  PORT_InitStructure.PORT_Pin   = (PORT_Pin_2 | PORT_Pin_3 | PORT_Pin_5);
  PORT_InitStructure.PORT_OE    = PORT_OE_IN;
  PORT_InitStructure.PORT_FUNC  = PORT_FUNC_ALTER;
  PORT_InitStructure.PORT_MODE  = PORT_MODE_DIGITAL;
  PORT_InitStructure.PORT_SPEED = PORT_SPEED_FAST;
  PORT_Init(MDR_PORTD, &PORT_InitStructure);
  PORT_InitStructure.PORT_OE    = PORT_OE_OUT;
  PORT_InitStructure.PORT_Pin   = (PORT_Pin_6);
  PORT_Init(MDR_PORTD, &PORT_InitStructure);

  /* Configure SSP1 pins: FSS, CLK, RXD, TXD */

  /* Configure PORTF pins 0, 1, 2, 3 */
  PORT_InitStructure.PORT_Pin   = (PORT_Pin_3);
  PORT_InitStructure.PORT_OE    = PORT_OE_IN;
  PORT_Init(MDR_PORTF, &PORT_InitStructure);
  PORT_InitStructure.PORT_Pin   = (PORT_Pin_0 | PORT_Pin_1 | PORT_Pin_2);
  PORT_InitStructure.PORT_OE    = PORT_OE_OUT;
  PORT_Init(MDR_PORTF, &PORT_InitStructure);


  /* Init RAM */
  Init_RAM (DstBuf1, BufferSize);
  Init_RAM (SrcBuf1, BufferSize);
  Init_RAM (DstBuf2, BufferSize);
  Init_RAM (SrcBuf2, BufferSize);

  /* Reset all SSP settings */
  SSP_DeInit(MDR_SSP1);
  SSP_DeInit(MDR_SSP2);

  SSP_BRGInit(MDR_SSP1,SSP_HCLKdiv16);
  SSP_BRGInit(MDR_SSP2,SSP_HCLKdiv16);

  /* SSP1 MASTER configuration ------------------------------------------------*/
  SSP_StructInit (&sSSP);

  sSSP.SSP_SCR  = 0x10;
  sSSP.SSP_CPSDVSR = 2;
  sSSP.SSP_Mode = SSP_ModeMaster;
  sSSP.SSP_WordLength = SSP_WordLength16b;
  sSSP.SSP_SPH = SSP_SPH_1Edge;
  sSSP.SSP_SPO = SSP_SPO_Low;
  sSSP.SSP_FRF = SSP_FRF_SPI_Motorola;
  sSSP.SSP_HardwareFlowControl = SSP_HardwareFlowControl_SSE;
  SSP_Init (MDR_SSP1,&sSSP);

  /* SSP2 SLAVE configuration ------------------------------------------------*/
  sSSP.SSP_SPH = SSP_SPH_1Edge;
  sSSP.SSP_SPO = SSP_SPO_Low;
  sSSP.SSP_CPSDVSR = 12;
  sSSP.SSP_Mode = SSP_ModeSlave;
  SSP_Init (MDR_SSP2,&sSSP);

  /* Enable SSP1 DMA Rx and Tx request */
  SSP_DMACmd(MDR_SSP1,(SSP_DMA_RXE | SSP_DMA_TXE), ENABLE);
  /* Enable SSP2 DMA Rx and Tx request */
  SSP_DMACmd(MDR_SSP2,(SSP_DMA_RXE | SSP_DMA_TXE), ENABLE);

  /* Reset all DMA settings */
  DMA_DeInit();
  DMA_StructInit(&DMA_InitStr);

  /* DMA_Channel_SSP1_RX configuration ---------------------------------*/
  /* Set Primary Control Data */
  DMA_PriCtrlStr.DMA_SourceBaseAddr = (uint32_t)(&(MDR_SSP1->DR));
  DMA_PriCtrlStr.DMA_DestBaseAddr = (uint32_t)DstBuf1;
  DMA_PriCtrlStr.DMA_SourceIncSize = DMA_SourceIncNo;
  DMA_PriCtrlStr.DMA_DestIncSize = DMA_DestIncHalfword;
  DMA_PriCtrlStr.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  DMA_PriCtrlStr.DMA_Mode = DMA_Mode_Basic;
  DMA_PriCtrlStr.DMA_CycleSize = BufferSize;
  DMA_PriCtrlStr.DMA_NumContinuous = DMA_Transfers_4;
  DMA_PriCtrlStr.DMA_SourceProtCtrl = DMA_SourcePrivileged;
  DMA_PriCtrlStr.DMA_DestProtCtrl = DMA_DestPrivileged;
  /* Set Channel Structure */
  DMA_InitStr.DMA_PriCtrlData = &DMA_PriCtrlStr;
  DMA_InitStr.DMA_Priority = DMA_Priority_High;
  DMA_InitStr.DMA_UseBurst = DMA_BurstClear;
  DMA_InitStr.DMA_SelectDataStructure = DMA_CTRL_DATA_PRIMARY;
  /* Init DMA channel */
  DMA_Init(DMA_Channel_SSP1_RX, &DMA_InitStr);

  /* DMA_Channel_SSP2_RX configuration ---------------------------------*/
  /* Set Primary Control Data */
  DMA_PriCtrlStr.DMA_SourceBaseAddr = (uint32_t)(&(MDR_SSP2->DR));
  DMA_PriCtrlStr.DMA_DestBaseAddr = (uint32_t)DstBuf2;
  /* Init DMA channel */
  DMA_Init(DMA_Channel_SSP2_RX, &DMA_InitStr);

  /* DMA_Channel_SSP1_TX configuration ---------------------------------*/
  /* Set Primary Control Data */
  DMA_PriCtrlStr.DMA_SourceBaseAddr = (uint32_t)SrcBuf1;
  DMA_PriCtrlStr.DMA_DestBaseAddr = (uint32_t)(&(MDR_SSP1->DR));
  DMA_PriCtrlStr.DMA_SourceIncSize = DMA_SourceIncHalfword;
  DMA_PriCtrlStr.DMA_DestIncSize = DMA_DestIncNo;
  DMA_InitStr.DMA_Priority = DMA_Priority_Default;
  /* Init DMA channel */
  DMA_Init(DMA_Channel_SSP1_TX, &DMA_InitStr);

  /* DMA_Channel_SSP2_TX configuration ---------------------------------*/
  /* Set Primary Control Data */
  DMA_PriCtrlStr.DMA_SourceBaseAddr = (uint32_t)SrcBuf2;
  DMA_PriCtrlStr.DMA_DestBaseAddr = (uint32_t)(&(MDR_SSP2->DR));
  /* Init DMA channel */
  DMA_Init(DMA_Channel_SSP2_TX, &DMA_InitStr);

  /* Enable SSP1 */
  SSP_Cmd(MDR_SSP1, ENABLE);
  /* Enable SSP2 */
  SSP_Cmd(MDR_SSP2, ENABLE);

  /* Transfer complete */
  while((SSP_GetFlagStatus(MDR_SSP1, SSP_FLAG_BSY)))
  {
  }
  while((SSP_GetFlagStatus(MDR_SSP2, SSP_FLAG_BSY)))
  {
  }

  /* Check the corectness of written dada */
  TransferStatus1 = Verif_mem ((BufferSize), SrcBuf1, DstBuf2);
  TransferStatus2 = Verif_mem ((BufferSize), SrcBuf2, DstBuf1);
  /* TransferStatus1, TransferStatus2 = PASSED, if the data transmitted and received
     are correct */
  /* TransferStatus1, TransferStatus2 = FAILED, if the data transmitted and received
     are different */

  while(1)
  {
  }
}