/** * @brief Initializes the SSPx peripheral according to the specified * parameters in the SSP_InitStruct. * @param SSPx: Select the SSP peripheral. * This parameter can be one of the following values: * SSP1, SSP2. * @param SSP_InitStruct: pointer to a SSP_InitTypeDef structure * that contains the configuration information for the specified SSP peripheral. * @retval None */ void SSP_Init(MDR_SSP_TypeDef* SSPx, const SSP_InitTypeDef* SSP_InitStruct) { uint32_t tmpreg; /* Check the parameters */ assert_param(IS_SSP_ALL_PERIPH(SSPx)); assert_param(IS_SSP_SPEED_FACTOR(SSP_InitStruct->SSP_SCR)); assert_param(IS_SSP_SPEED_DIVIDER(SSP_InitStruct->SSP_CPSDVSR)); assert_param(IS_SSP_MODE(SSP_InitStruct->SSP_Mode)); assert_param(IS_SSP_WORD_LENGTH(SSP_InitStruct->SSP_WordLength)); assert_param(IS_SSP_SPH(SSP_InitStruct->SSP_SPH)); assert_param(IS_SSP_SPO(SSP_InitStruct->SSP_SPO)); assert_param(IS_SSP_FRF(SSP_InitStruct->SSP_FRF)); assert_param(IS_SSP_HARDWARE_FLOW_CONTROL(SSP_InitStruct->SSP_HardwareFlowControl)); /* SSPx CPSR Configuration */ SSPx->CPSR = SSP_InitStruct->SSP_CPSDVSR; /* SSPx CR0 Configuration */ tmpreg = (SSP_InitStruct->SSP_SCR << SSP_CR0_SCR_Pos) + SSP_InitStruct->SSP_SPH + SSP_InitStruct->SSP_SPO + SSP_InitStruct->SSP_FRF + SSP_InitStruct->SSP_WordLength; SSPx->CR0 = tmpreg; /* SSPx CR1 Configuration */ tmpreg = SSP_InitStruct->SSP_HardwareFlowControl + SSP_InitStruct->SSP_Mode; SSPx->CR1 = tmpreg; }
/** * @brief Initializes the SSPx peripheral according to the specified * parameters in the SSP_InitStruct. * @param SSPx: where x can be 1 or 2 to select the SSP peripheral. * @param SSP_InitStruct: pointer to a SSP_InitTypeDef structure that * contains the configuration information for the specified SSP peripheral. * @retval None */ void SSP_Init(SSP_TypeDef* SSPx, SSP_InitTypeDef* SSP_InitStruct) { uint32_t tmpreg = 0; /* check the parameters */ assert_param(IS_SSP_ALL_PERIPH(SSPx)); /* Check the SSP parameters */ assert_param(IS_SSP_SERIALCLOCKRATE(SSP_InitStruct->SSP_SerialClockRate)); assert_param(IS_SSP_FRAMEFORMAT(SSP_InitStruct->SSP_FrameFormat)); assert_param(IS_SSP_CPHA(SSP_InitStruct->SSP_CPHA)); assert_param(IS_SSP_CPOL(SSP_InitStruct->SSP_CPOL)); assert_param(IS_SSP_DATASIZE(SSP_InitStruct->SSP_DataSize)); assert_param(IS_SSP_SOD(SSP_InitStruct->SSP_SOD)); assert_param(IS_SSP_MODE(SSP_InitStruct->SSP_Mode)); assert_param(IS_SSP_NSS(SSP_InitStruct->SSP_NSS)); assert_param(IS_SSP_LBM(SSP_InitStruct->SSP_LBM)); assert_param(IS_SSP_SSE(SSP_InitStruct->SSP_SSE)); assert_param(IS_SSP_BAUDRATE_PRESCALER(SSP_InitStruct->SSP_BaudRatePrescaler)); /*---------------------------- SSPx CR0 Configuration ------------------------*/ /* Get the SSPx CR0 value */ tmpreg = SSPx->CR0; /* Clear bits */ //tmpreg &= CR1_CLEAR_Mask; tmpreg |= (uint32_t)(SSP_InitStruct->SSP_SerialClockRate | SSP_InitStruct->SSP_FrameFormat | SSP_InitStruct->SSP_CPHA | SSP_InitStruct->SSP_CPOL | SSP_InitStruct->SSP_DataSize ); //printf("CR0: %.8X \r\n",tmpreg); /* Write to SSPx CR0 */ SSPx->CR0 = tmpreg; /*---------------------------- SSPx CR1 Configuration ------------------------*/ /* Write to SSPx CR1 */ tmpreg = SSPx->CR1; /* Clear bits */ //tmpreg &= CR1_CLEAR_Mask; tmpreg |= (uint32_t)(SSP_InitStruct->SSP_SOD | SSP_InitStruct->SSP_Mode | SSP_InitStruct->SSP_NSS | SSP_InitStruct->SSP_SSE | SSP_InitStruct->SSP_LBM ); SSPx->CR1 = tmpreg; //printf("CR1: %.8X \r\n",tmpreg); /*---------------------------- SSPx Clock prescal register ------------------------*/ SSPx->CPSR = SSP_InitStruct->SSP_BaudRatePrescaler; }