void cpu_deinit_all() { //** ADC_DeInit(LPC_ADC); CAN_DeInit(LPC_CAN1); CAN_DeInit(LPC_CAN2); EMAC_DeInit(); EXTI_DeInit(); I2C_DeInit(LPC_I2C0); I2C_DeInit(LPC_I2C1); I2C_DeInit(LPC_I2C2); I2S_DeInit(LPC_I2S); NVIC_DeInit(); NVIC_SCBDeInit(); PWM_DeInit(LPC_PWM1); QEI_DeInit(LPC_QEI); //** RIT_DeInit(LPC_RIT); RTC_DeInit(LPC_RTC); SPI_DeInit(LPC_SPI); SSP_DeInit(LPC_SSP0); SSP_DeInit(LPC_SSP1); UART_DeInit(LPC_UART0); UART_DeInit((LPC_UART_TypeDef *) LPC_UART1); //** UART_DeInit(LPC_UART2); //** UART_DeInit(LPC_UART3); TIM_DeInit(LPC_TIM0); TIM_DeInit(LPC_TIM1); //** TIM_DeInit(LPC_TIM2); //** TIM_DeInit(LPC_TIM3); }
//SpeedSet: //SPI_BAUDRATEPRESCALER_2 //SPI_BAUDRATEPRESCALER_4 //SPI_BAUDRATEPRESCALER_8 //SPI_BAUDRATEPRESCALER_16 static void spi_init(SPI_BaudRatePrescaler_TypeDef SPI_BaudRatePrescaler) { GPIO_Init(LCD_CS_PIN,GPIO_MODE_OUT_PP_HIGH_FAST); GPIO_Init(LCD_CD_PIN,GPIO_MODE_OUT_PP_HIGH_FAST); GPIO_Init(LCD_RST_PIN,GPIO_MODE_OUT_PP_HIGH_FAST); GPIO_Init(LCD_LIGHT_PIN,GPIO_MODE_OUT_PP_HIGH_FAST); GPIO_Init(SPI_SCK_PIN,GPIO_MODE_OUT_PP_LOW_FAST); GPIO_Init(SPI_MOSI_PIN,GPIO_MODE_OUT_PP_HIGH_FAST); GPIO_Init(SPI_MISO_PIN,GPIO_MODE_IN_PU_NO_IT); //打开flash电源 开发板独有 GPIO_Init(GPIOE,GPIO_PIN_0,GPIO_MODE_OUT_PP_HIGH_FAST); GPIO_WriteHigh(GPIOE,GPIO_PIN_0); //打开背光 GPIO_WriteLow(LCD_LIGHT_PIN); GPIO_WriteLow(LCD_RST_PIN); u8g_10MicroDelay(); GPIO_WriteHigh(LCD_RST_PIN); //关闭FLASH CS GPIO_WriteLow(GPIOG,GPIO_PIN_0); //初始化SPI SPI_DeInit(); SPI_Init(SPI_FIRSTBIT_MSB, SPI_BaudRatePrescaler, SPI_MODE_MASTER, SPI_CLOCKPOLARITY_LOW, SPI_CLOCKPHASE_1EDGE, SPI_DATADIRECTION_2LINES_FULLDUPLEX, SPI_NSS_SOFT, 0x00); SPI_Cmd(ENABLE); }
/** * @brief DeInitializes the SPI interface. * @param None * @retval None */ void RF95W_LowLevel_DeInit(void) { GPIO_InitTypeDef GPIO_InitStructure; SPI_Cmd(RF95W_SPI, DISABLE); /*!< SD_SPI disable */ SPI_DeInit(RF95W_SPI); /*!< DeInitializes the SD_SPI */ /*!< SD_SPI Periph clock disable */ RCC_APB1PeriphClockCmd(RF95W_SPI_CLK, DISABLE); /*!< Configure SD_SPI pins: SCK */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Pin = RF95W_SCK_PIN; GPIO_Init(RF95W_SCK_GPIO_PORT, &GPIO_InitStructure); /*!< Configure SD_SPI pins: MISO */ GPIO_InitStructure.GPIO_Pin = RF95W_MISO_PIN; GPIO_Init(RF95W_MISO_GPIO_PORT, &GPIO_InitStructure); /*!< Configure SD_SPI pins: MOSI */ GPIO_InitStructure.GPIO_Pin = RF95W_MOSI_PIN; GPIO_Init(RF95W_MOSI_GPIO_PORT, &GPIO_InitStructure); /*!< Configure RF95W_CS_PIN pin: SD Card CS pin */ GPIO_InitStructure.GPIO_Pin = RF95W_CS_PIN; GPIO_Init(RF95W_CS_GPIO_PORT, &GPIO_InitStructure); /*!< Configure RF95W_DIO0_PIN pin: SD Card detect pin */ GPIO_InitStructure.GPIO_Pin = RF95W_DIO0_PIN; GPIO_Init(RF95W_DIO0_GPIO_PORT, &GPIO_InitStructure); }
/** * @brief Configure SPI peripheral * @param None * @retval None */ static void SPI_Config(void) { SPI_DeInit(SPI1); /* SPI Configuration --------------------------------------------------------*/ SPI_Init(SPI1, SPI_FirstBit_LSB, SPI_BaudRatePrescaler_2, SPI_Mode_Slave, SPI_CPOL_Low, SPI_CPHA_2Edge, SPI_Direction_2Lines_FullDuplex, SPI_NSS_Soft, (uint8_t)0x07); }
static void SPI_to_default_config(void) { SPI_DeInit(); SPI_Init(SPI_FIRSTBIT_LSB, SPI_BAUDRATEPRESCALER_16, SPI_MODE_MASTER, SPI_CLOCKPOLARITY_HIGH, SPI_CLOCKPHASE_2EDGE, SPI_DATADIRECTION_1LINE_TX, SPI_NSS_SOFT,(uint8_t)0x07); //Delay_blocking(0xFFF); SPI_Cmd(ENABLE); }
/** * @brief Initializes the SPI for SPIRIT * @param None * @retval None */ void SpiritSpiInit(void) { SPI_InitTypeDef SPI_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* Enable SPI periph clock */ RCC_APB2PeriphClockCmd(SPIRIT_SPI_PERIPH_RCC, ENABLE); /* Enable SCLK, MOSI, MISO and CS GPIO clocks */ RCC_AHBPeriphClockCmd(SPIRIT_SPI_PERIPH_MOSI_RCC | SPIRIT_SPI_PERIPH_MISO_RCC | SPIRIT_SPI_PERIPH_SCLK_RCC | SPIRIT_SPI_PERIPH_CS_RCC, ENABLE); /* Configure the AF for MOSI, MISO and SCLK GPIO pins*/ GPIO_PinAFConfig(SPIRIT_SPI_PERIPH_MOSI_PORT, SPIRIT_SPI_PERIPH_MOSI_RCC_SOURCE, SPIRIT_SPI_PERIPH_MOSI_AF); GPIO_PinAFConfig(SPIRIT_SPI_PERIPH_MISO_PORT, SPIRIT_SPI_PERIPH_MISO_RCC_SOURCE, SPIRIT_SPI_PERIPH_MISO_AF); GPIO_PinAFConfig(SPIRIT_SPI_PERIPH_SCLK_PORT, SPIRIT_SPI_PERIPH_SCLK_RCC_SOURCE, SPIRIT_SPI_PERIPH_SCLK_AF); /* Configure SPI pins:SCLK, MISO and MOSI */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_InitStructure.GPIO_Pin = SPIRIT_SPI_PERIPH_SCLK_PIN; GPIO_Init(SPIRIT_SPI_PERIPH_SCLK_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = SPIRIT_SPI_PERIPH_MISO_PIN; GPIO_Init(SPIRIT_SPI_PERIPH_MISO_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = SPIRIT_SPI_PERIPH_MOSI_PIN; GPIO_Init(SPIRIT_SPI_PERIPH_MOSI_PORT, &GPIO_InitStructure); /* Configure SPI pin: CS */ GPIO_InitStructure.GPIO_Pin = SPIRIT_SPI_PERIPH_CS_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_Init(SPIRIT_SPI_PERIPH_CS_PORT, &GPIO_InitStructure); /* Configure SPI peripheral */ SPI_DeInit(SPIRIT_SPI_PERIPH_NB); SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; //SPI_BaudRatePrescaler_8; /*Baud_Rate= fpclk/4=32MHz/4=8MHZ*/ SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPIRIT_SPI_PERIPH_NB, &SPI_InitStructure); SPI_Cmd(SPIRIT_SPI_PERIPH_NB, ENABLE); /* SPIRIT_SPI enable */ }
/*---------------------------------------------------------------------------- SPI Serial Device "LPC17xx" uninitialize *----------------------------------------------------------------------------*/ static int SpiDev_UnInit (void) { #if (_SPI_ == 0) SPI_DeInit(LPC_SPI); #else #error "SPI not defined!" #endif SpiInfo.State = _STATE_UNKNOWN_; return(0); /* Success */ }
void accelInit() { SPI_InitTypeDef SPI_InitTypeDefStruct; GPIO_InitTypeDef GPIO_InitTypeDefStruct; RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE , ENABLE); SPI_InitTypeDefStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitTypeDefStruct.SPI_Mode = SPI_Mode_Master; SPI_InitTypeDefStruct.SPI_DataSize = SPI_DataSize_8b; SPI_InitTypeDefStruct.SPI_CPOL = SPI_CPOL_High; SPI_InitTypeDefStruct.SPI_CPHA = SPI_CPHA_2Edge; SPI_InitTypeDefStruct.SPI_NSS = SPI_NSS_Soft; SPI_InitTypeDefStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; //seems like it was here causing trouble SPI_InitTypeDefStruct.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitTypeDefStruct.SPI_CRCPolynomial = 1; SPI_DeInit(SPI1); SPI_Init(SPI1, &SPI_InitTypeDefStruct); GPIO_InitTypeDefStruct.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_7 | GPIO_Pin_6; GPIO_InitTypeDefStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_InitTypeDefStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitTypeDefStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitTypeDefStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitTypeDefStruct); GPIO_InitTypeDefStruct.GPIO_Pin = GPIO_Pin_3; GPIO_InitTypeDefStruct.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitTypeDefStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitTypeDefStruct.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitTypeDefStruct.GPIO_OType = GPIO_OType_PP; GPIO_Init(GPIOE, &GPIO_InitTypeDefStruct); GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_SPI1); GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_SPI1); GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_SPI1); GPIO_SetBits(GPIOE, GPIO_Pin_3); SPI_Cmd(SPI1, ENABLE); SPI_send(ACCEL_CTRL_REG6, 0x01); //reboot SPI_send(ACCEL_CTRL_REG3, 0xc9); // resetting the accelerometer internal circuit SPI_send(ACCEL_CTRL_REG4, 0x67); // 100Hz data update rate, block data update disable, x/y/z enabled SPI_send(ACCEL_CTRL_REG4, 0x67); // 100Hz data update rate, block data update disable, x/y/z enabled SPI_send(ACCEL_CTRL_REG4, 0x67); // 100Hz data update rate, block data update disable, x/y/z enabled SPI_send(ACCEL_CTRL_REG5, 0x20); // Anti aliasing filter bandwidth 800Hz, 16G, no self-test, 4-wire interface }
void HAL_SPI_End(HAL_SPI_Interface spi) { if(spiState[spi].SPI_Enabled != false) { if (spiState[spi].mode == SPI_MODE_SLAVE) { HAL_Interrupts_Detach(spiState[spi].SPI_SS_Pin); } SPI_Cmd(spiMap[spi].SPI_Peripheral, DISABLE); HAL_SPI_DMA_Transfer_Cancel(spi); SPI_DeInit(spiMap[spi].SPI_Peripheral); spiState[spi].SPI_Enabled = false; } }
void spi_init(void) { SPI_DeInit(); /* Set the MOSI,MISO and SCK at high level */ GPIO_ExternalPullUpConfig(GPIOC, (GPIO_Pin_TypeDef)(GPIO_PIN_7 | GPIO_PIN_6 | GPIO_PIN_5), ENABLE); /* SD_SPI Configuration */ SPI_Init( SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_4, SPI_MODE_MASTER, // for baud rate we have to check else is done as per below working configuration. SPI_CLOCKPOLARITY_LOW, SPI_CLOCKPHASE_1EDGE, SPI_DATADIRECTION_2LINES_FULLDUPLEX, SPI_NSS_SOFT, 0x07); Delay(0xFFF); /* SD_SPI enable */ SPI_Cmd( ENABLE); GPIO_Init(GPIOC,GPIO_PIN_4, GPIO_MODE_OUT_PP_HIGH_FAST); /*CS*/ }
void spiFlashInit() { GPIO_Init(FLASH_CS_PIN,GPIO_MODE_OUT_PP_HIGH_FAST); GPIO_Init(SPI_SCK_PIN,GPIO_MODE_OUT_PP_LOW_FAST); GPIO_Init(SPI_MOSI_PIN,GPIO_MODE_OUT_PP_HIGH_FAST); GPIO_Init(SPI_MISO_PIN,GPIO_MODE_IN_PU_NO_IT); //打开flash电源 开发板独有 GPIO_Init(GPIOE,GPIO_PIN_0,GPIO_MODE_OUT_PP_HIGH_FAST); GPIO_WriteHigh(GPIOE,GPIO_PIN_0); //初始化SPI SPI_DeInit(); SPI_Init(SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_4, SPI_MODE_MASTER, SPI_CLOCKPOLARITY_LOW, SPI_CLOCKPHASE_1EDGE, SPI_DATADIRECTION_2LINES_FULLDUPLEX, SPI_NSS_SOFT, 0x00); SPI_Cmd(ENABLE); }
void SPI2_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; SPI_InitTypeDef SPI_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE); //GPIOB CLOCK RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); //SPI2 CLOCK //SPI SCK GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_PinAFConfig(GPIOB,GPIO_PinSource13,GPIO_AF_SPI2); GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL; GPIO_Init(GPIOB, &GPIO_InitStructure); //SPI MOSI GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_PinAFConfig(GPIOB,GPIO_PinSource15,GPIO_AF_SPI2); GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL; GPIO_Init(GPIOB, &GPIO_InitStructure); //SPI MISO GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_PinAFConfig(GPIOB,GPIO_PinSource14,GPIO_AF_SPI2); GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL; GPIO_Init(GPIOB, &GPIO_InitStructure); //SPI configuration SPI_DeInit(SPI2); SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //Full Duplex SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //As master SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //8bit SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //MSB first SPI_InitStructure.SPI_CRCPolynomial = 7; //CRC SPI_Init(SPI2, &SPI_InitStructure); SPI_ClearITPendingBit(SPI2,SPI_IT_TXE|SPI_IT_RXNE); SPI_Cmd(SPI2,ENABLE); }
/** * @brief Example main entry point. * @par Parameters: * None * @retval * None */ void main(void) { /* Initialize SPI for LCD */ SPI_DeInit(); SPI_Init(SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_128, SPI_MODE_MASTER, SPI_CLOCKPOLARITY_HIGH, SPI_CLOCKPHASE_2EDGE, SPI_DATADIRECTION_1LINE_TX, SPI_NSS_SOFT, 0x07); SPI_Cmd(ENABLE); /* Configure GPIO used to drive the joystick JOYSTICK_UP --> PB6 JOYSTICK_DOWN --> PB7 JOYSTICK_LEFT --> PB4 */ GPIO_Init(GPIOB, GPIO_PIN_4 | GPIO_PIN_6 | GPIO_PIN_7, GPIO_MODE_IN_FL_IT); EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOB, EXTI_SENSITIVITY_FALL_LOW); enableInterrupts(); /* Initialize LCD */ LCD_Init(); /* Clear LCD lines */ LCD_Clear(); LCD_Backlight(ENABLE); LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, "Clock Selection"); LCD_PrintString(LCD_LINE2, ENABLE, DISABLE, " Use joystick"); CLK_DeInit(); CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); /* Output Fcpu on CLK_CCO pin */ CLK_CCOConfig(CLK_OUTPUT_MASTER); while (1) { } }
static void HAL_SPI_RX_DMA_Stream_InterruptHandler(HAL_SPI_Interface spi) { if (DMA_GetITStatus(spiMap[spi].SPI_RX_DMA_Stream, spiMap[spi].SPI_RX_DMA_Stream_TC_Event) == SET) { uint32_t remainingCount = DMA_GetCurrDataCounter(spiMap[spi].SPI_RX_DMA_Stream); if (!spiState[spi].SPI_DMA_Aborted) { while (SPI_I2S_GetFlagStatus(spiMap[spi].SPI_Peripheral, SPI_I2S_FLAG_TXE) == RESET); while (SPI_I2S_GetFlagStatus(spiMap[spi].SPI_Peripheral, SPI_I2S_FLAG_BSY) == SET); } if (spiState[spi].mode == SPI_MODE_SLAVE) { SPI_Cmd(spiMap[spi].SPI_Peripheral, DISABLE); if (spiState[spi].SPI_DMA_Aborted) { /* Reset SPI peripheral completely, othewise we might end up with a case where * SPI peripheral has already loaded some data from aborted transfer into its circular register, * but haven't transferred it out yet. The next transfer then will start with this remainder data. * The only way to clear it out is by completely disabling SPI peripheral (stopping its clock). */ spiState[spi].SPI_DMA_Aborted = 0; SPI_DeInit(spiMap[spi].SPI_Peripheral); HAL_SPI_Begin_Ext(spi, SPI_MODE_SLAVE, spiState[spi].SPI_SS_Pin, NULL); } } DMA_ClearITPendingBit(spiMap[spi].SPI_RX_DMA_Stream, spiMap[spi].SPI_RX_DMA_Stream_TC_Event); SPI_I2S_DMACmd(spiMap[spi].SPI_Peripheral, SPI_I2S_DMAReq_Rx, DISABLE); DMA_Cmd(spiMap[spi].SPI_RX_DMA_Stream, DISABLE); spiState[spi].SPI_DMA_Last_Transfer_Length = spiState[spi].SPI_DMA_Current_Transfer_Length - remainingCount; spiState[spi].SPI_DMA_Configured = 0; HAL_SPI_DMA_UserCallback callback = spiState[spi].SPI_DMA_UserCallback; if (callback) { // notify user program about transfer completion callback(); } } }
void LCD_Init(void) { int i; SPI_DeInit(); /* Initialize SPI in Master mode */ SPI_Init(SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_2, SPI_MODE_MASTER, SPI_CLOCKPOLARITY_HIGH, SPI_CLOCKPHASE_2EDGE, SPI_DATADIRECTION_1LINE_TX, SPI_NSS_SOFT, 0x07); SPI_Cmd(ENABLE); /* Set S65 ChipSelect RS RST pin in Output push-pull high level */ GPIO_Init(S65_CS_PORT, S65_CS_PIN, GPIO_MODE_OUT_PP_HIGH_FAST); GPIO_Init(S65_RS_RST_PORT, S65_RS_PIN, GPIO_MODE_OUT_PP_HIGH_FAST); GPIO_Init(S65_RS_RST_PORT, S65_RST_PIN, GPIO_MODE_OUT_PP_HIGH_FAST); //reset LCD_CS_DISABLE(); LCD_RS_DISABLE(); LCD_RST_ENABLE(); delay_ms(50); LCD_RST_DISABLE(); delay_ms(50); LCD_SendCMD(DISOFF); //display off LCD_SendCMD(DATCTL); LCD_SendDAT8(0x2B); //565 mode, 0x2A=normal, 0x2B=180 LCD_SendCMD(DISCTL); for (i=0; i<9; i++) { LCD_SendDAT8(disctl[i]); } delay_ms(10); LCD_SendCMD(SLPOUT); delay_ms(10); LCD_SendCMD(DISON); }
int main( void ) { uint16_t i; GPIO_DeInit(GPIOD); SPI_DeInit(); GPIO_Init(GPIOD, GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_FAST); init_spi(); // The main loop while( 1 ){ for(i=0;i<150;i++) // A delay loop { nop(); } GPIO_WriteReverse(GPIOD, GPIO_PIN_0); // spi_write_data_8t("keep going...", 0x40);//Random Address 0x40 for now. spi_write_data_8t("msg", 0x55);//Random Address 0x40 for now. } }
/** * @brief Example main entry point. * @par Parameters: * None * @retval * None */ void main(void) { u8 i = 0; /* Initialization of the clock */ /* Clock divider to HSI/1 */ CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); /* Initialization of I/Os in Output Mode */ GPIO_Init(LEDS_PORT, (LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN), GPIO_MODE_OUT_PP_LOW_FAST); /* Initialization of I/O in Input Mode with Interrupt */ GPIO_Init(BUTTON_PORT, BUTTON_PIN, GPIO_MODE_IN_FL_IT); /* Initialization of the Interrupt sensitivity */ EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOC, EXTI_SENSITIVITY_FALL_ONLY); /* BEEP calibration */ BEEP_LSICalibrationConfig(LSIMeasurment()); GPIO_Write(LEDS_PORT, (LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN)); /* All LEDs ON */ /* Initialize SPI for LCD */ SPI_DeInit(); SPI_Init(SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_128, SPI_MODE_MASTER, SPI_CLOCKPOLARITY_HIGH, SPI_CLOCKPHASE_2EDGE, SPI_DATADIRECTION_1LINE_TX, SPI_NSS_SOFT, 0x07); SPI_Cmd(ENABLE); /* Initialize LCD */ LCD_Init(); /* Clear LCD lines */ LCD_Clear(); /* Enable general interrupts for Key button reading */ enableInterrupts(); LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, " BEEPER OFF"); LCD_PrintString(LCD_LINE2, ENABLE, DISABLE, " Press Key"); while (1) { /* Check button status */ if (ButtonPressed == TRUE) /* Button is pressed */ { ButtonPressed = FALSE; /* Change BEEP frequency */ switch (i) { case 0: BEEP_Cmd(DISABLE); Delay(100); BEEP_Init(BEEP_FREQUENCY_1KHZ); BEEP_Cmd(ENABLE); GPIO_Write(LEDS_PORT, LED1_PIN); /* LED1 ON */ LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, " BEEPER 1kHz"); i = 1; break; case 1: BEEP_Cmd(DISABLE); Delay(100); BEEP_Init(BEEP_FREQUENCY_2KHZ); BEEP_Cmd(ENABLE); GPIO_Write(LEDS_PORT, LED2_PIN); /* LED2 ON */ LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, " BEEPER 2kHz"); i = 2; break; case 2: BEEP_Cmd(DISABLE); Delay(100); BEEP_Init(BEEP_FREQUENCY_4KHZ); BEEP_Cmd(ENABLE); GPIO_Write(LEDS_PORT, LED3_PIN); /* LED3 ON */ LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, " BEEPER 4kHz"); i = 3; break; case 3: BEEP_Cmd(DISABLE); GPIO_Write(LEDS_PORT, LED4_PIN); /* LED4 ON */ LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, " BEEPER OFF"); i = 0; break; default: break; } } } }
void HardwareSPI::end(void) { SPI_DeInit(SPIx); }
/** * Initialise a single Overo device */ int32_t PIOS_OVERO_Init(uint32_t *overo_id, const struct pios_overo_cfg *cfg) { PIOS_DEBUG_Assert(overo_id); PIOS_DEBUG_Assert(cfg); struct pios_overo_dev *overo_dev; overo_dev = (struct pios_overo_dev *)PIOS_OVERO_alloc(); if (!overo_dev) { goto out_fail; } /* Bind the configuration to the device instance */ overo_dev->cfg = cfg; overo_dev->writing_buffer = 1; // First writes to second buffer /* Put buffers to a known state */ memset(&overo_dev->tx_buffer[0][0], 0xFF, PACKET_SIZE); memset(&overo_dev->tx_buffer[1][0], 0xFF, PACKET_SIZE); memset(&overo_dev->rx_buffer[0][0], 0xFF, PACKET_SIZE); memset(&overo_dev->rx_buffer[1][0], 0xFF, PACKET_SIZE); /* * Enable the SPI device * * 1. Enable the SPI port * 2. Enable DMA with circular buffered DMA (validate config) * 3. Enable the DMA Tx IRQ */ // PIOS_Assert(overo_dev->cfg->dma.tx-> == CIRCULAR); // PIOS_Assert(overo_dev->cfg->dma.rx-> == CIRCULAR); /* only legal for single-slave config */ PIOS_Assert(overo_dev->cfg->slave_count == 1); SPI_SSOutputCmd(overo_dev->cfg->regs, DISABLE); /* Initialize the GPIO pins */ /* note __builtin_ctz() due to the difference between GPIO_PinX and GPIO_PinSourceX */ GPIO_PinAFConfig(overo_dev->cfg->sclk.gpio, __builtin_ctz(overo_dev->cfg->sclk.init.GPIO_Pin), overo_dev->cfg->remap); GPIO_PinAFConfig(overo_dev->cfg->mosi.gpio, __builtin_ctz(overo_dev->cfg->mosi.init.GPIO_Pin), overo_dev->cfg->remap); GPIO_PinAFConfig(overo_dev->cfg->miso.gpio, __builtin_ctz(overo_dev->cfg->miso.init.GPIO_Pin), overo_dev->cfg->remap); GPIO_PinAFConfig(overo_dev->cfg->ssel[0].gpio, __builtin_ctz(overo_dev->cfg->ssel[0].init.GPIO_Pin), overo_dev->cfg->remap); GPIO_Init(overo_dev->cfg->sclk.gpio, (GPIO_InitTypeDef *)&(overo_dev->cfg->sclk.init)); GPIO_Init(overo_dev->cfg->mosi.gpio, (GPIO_InitTypeDef *)&(overo_dev->cfg->mosi.init)); GPIO_Init(overo_dev->cfg->miso.gpio, (GPIO_InitTypeDef *)&(overo_dev->cfg->miso.init)); /* Configure circular buffer targets. Configure 0 to be initially active */ DMA_InitTypeDef dma_init; DMA_DeInit(overo_dev->cfg->dma.rx.channel); dma_init = overo_dev->cfg->dma.rx.init; dma_init.DMA_Memory0BaseAddr = (uint32_t)overo_dev->rx_buffer[0]; dma_init.DMA_MemoryInc = DMA_MemoryInc_Enable; dma_init.DMA_BufferSize = PACKET_SIZE; DMA_Init(overo_dev->cfg->dma.rx.channel, &dma_init); DMA_DoubleBufferModeConfig(overo_dev->cfg->dma.rx.channel, (uint32_t)overo_dev->rx_buffer[1], DMA_Memory_0); DMA_DoubleBufferModeCmd(overo_dev->cfg->dma.rx.channel, ENABLE); DMA_DeInit(overo_dev->cfg->dma.tx.channel); dma_init = overo_dev->cfg->dma.tx.init; dma_init.DMA_Memory0BaseAddr = (uint32_t)overo_dev->tx_buffer[0]; dma_init.DMA_MemoryInc = DMA_MemoryInc_Enable; dma_init.DMA_BufferSize = PACKET_SIZE; DMA_Init(overo_dev->cfg->dma.tx.channel, &dma_init); DMA_DoubleBufferModeConfig(overo_dev->cfg->dma.tx.channel, (uint32_t)overo_dev->tx_buffer[1], DMA_Memory_0); DMA_DoubleBufferModeCmd(overo_dev->cfg->dma.tx.channel, ENABLE); /* Set the packet size */ DMA_SetCurrDataCounter(overo_dev->cfg->dma.rx.channel, PACKET_SIZE); DMA_SetCurrDataCounter(overo_dev->cfg->dma.tx.channel, PACKET_SIZE); /* Initialize the SPI block */ SPI_DeInit(overo_dev->cfg->regs); SPI_Init(overo_dev->cfg->regs, (SPI_InitTypeDef *)&(overo_dev->cfg->init)); SPI_CalculateCRC(overo_dev->cfg->regs, DISABLE); /* Enable SPI */ SPI_Cmd(overo_dev->cfg->regs, ENABLE); /* Enable SPI interrupts to DMA */ SPI_I2S_DMACmd(overo_dev->cfg->regs, SPI_I2S_DMAReq_Tx | SPI_I2S_DMAReq_Rx, ENABLE); /* Configure DMA interrupt */ NVIC_Init((NVIC_InitTypeDef *)&(overo_dev->cfg->dma.irq.init)); DMA_ITConfig(overo_dev->cfg->dma.tx.channel, DMA_IT_TC, ENABLE); /* Enable the DMA channels */ DMA_Cmd(overo_dev->cfg->dma.tx.channel, ENABLE); DMA_Cmd(overo_dev->cfg->dma.rx.channel, ENABLE); *overo_id = (uint32_t)overo_dev; return 0; out_fail: return -1; }
/** * @brief Initializes the SPI for SPIRIT * @param None * @retval None */ void SdkEvalSpiInit(void) { SPI_InitTypeDef SPI_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; s_SpiPort = s_SpiPortVersion[SdkEvalGetVersion()]; s_vectnSpiPin = (uint16_t *)&s_vectpxSpiCsPinVersion[SdkEvalGetVersion()]; s_vectpxSpiPort = &s_vectpxSpiCsPortVersion[SdkEvalGetVersion()]; if(!SdkEvalGetVersion()) { /* Enable SPI periph and SCLK, MOSI, MISO and CS GPIO clocks */ RCC_APB2PeriphClockCmd(SDK_EVAL_V2_SPI_PERIPH_RCC, ENABLE); RCC_AHBPeriphClockCmd(SDK_EVAL_V2_SPI_PERIPH_MOSI_RCC | SDK_EVAL_V2_SPI_PERIPH_MISO_RCC | SDK_EVAL_V2_SPI_PERIPH_SCLK_RCC | SDK_EVAL_V2_SPI_PERIPH_CS_RCC, ENABLE); /* Configure the AF for MOSI, MISO and SCLK GPIO pins*/ GPIO_PinAFConfig(SDK_EVAL_V2_SPI_PERIPH_MOSI_PORT, SDK_EVAL_V2_SPI_PERIPH_MOSI_RCC_SOURCE, SDK_EVAL_V2_SPI_PERIPH_MOSI_AF); GPIO_PinAFConfig(SDK_EVAL_V2_SPI_PERIPH_MISO_PORT, SDK_EVAL_V2_SPI_PERIPH_MISO_RCC_SOURCE, SDK_EVAL_V2_SPI_PERIPH_MISO_AF); GPIO_PinAFConfig(SDK_EVAL_V2_SPI_PERIPH_SCLK_PORT, SDK_EVAL_V2_SPI_PERIPH_SCLK_RCC_SOURCE, SDK_EVAL_V2_SPI_PERIPH_SCLK_AF); /* Configure SPI pins:SCLK, MISO and MOSI */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_InitStructure.GPIO_Pin = SDK_EVAL_V2_SPI_PERIPH_SCLK_PIN; GPIO_Init(SDK_EVAL_V2_SPI_PERIPH_SCLK_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = SDK_EVAL_V2_SPI_PERIPH_MISO_PIN; GPIO_Init(SDK_EVAL_V2_SPI_PERIPH_MISO_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = SDK_EVAL_V2_SPI_PERIPH_MOSI_PIN; GPIO_Init(SDK_EVAL_V2_SPI_PERIPH_MOSI_PORT, &GPIO_InitStructure); /* Configure SPI pin: CS */ GPIO_InitStructure.GPIO_Pin = SDK_EVAL_V2_SPI_PERIPH_CS_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_Init(SDK_EVAL_V2_SPI_PERIPH_CS_PORT, &GPIO_InitStructure); } else { /* Enable SPI periph and SCLK, MOSI, MISO and CS GPIO clocks */ RCC_AHBPeriphClockCmd(SDK_EVAL_V3_SPI_PERIPH_MOSI_RCC | SDK_EVAL_V3_SPI_PERIPH_MISO_RCC | SDK_EVAL_V3_SPI_PERIPH_SCLK_RCC | SDK_EVAL_V3_SPI_PERIPH_CS_RCC, ENABLE); /* Configure the AF for MOSI, MISO and SCLK GPIO pins*/ GPIO_PinAFConfig(SDK_EVAL_V3_SPI_PERIPH_MOSI_PORT, SDK_EVAL_V3_SPI_PERIPH_MOSI_RCC_SOURCE, SDK_EVAL_V3_SPI_PERIPH_MOSI_AF); GPIO_PinAFConfig(SDK_EVAL_V3_SPI_PERIPH_MISO_PORT, SDK_EVAL_V3_SPI_PERIPH_MISO_RCC_SOURCE, SDK_EVAL_V3_SPI_PERIPH_MISO_AF); GPIO_PinAFConfig(SDK_EVAL_V3_SPI_PERIPH_SCLK_PORT, SDK_EVAL_V3_SPI_PERIPH_SCLK_RCC_SOURCE, SDK_EVAL_V3_SPI_PERIPH_SCLK_AF); /* Configure SPI pins:SCLK, MISO and MOSI */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_InitStructure.GPIO_Pin = SDK_EVAL_V3_SPI_PERIPH_SCLK_PIN; GPIO_Init(SDK_EVAL_V3_SPI_PERIPH_SCLK_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = SDK_EVAL_V3_SPI_PERIPH_MISO_PIN; GPIO_Init(SDK_EVAL_V3_SPI_PERIPH_MISO_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = SDK_EVAL_V3_SPI_PERIPH_MOSI_PIN; GPIO_Init(SDK_EVAL_V3_SPI_PERIPH_MOSI_PORT, &GPIO_InitStructure); /* Configure SPI pin: CS */ GPIO_InitStructure.GPIO_Pin = SDK_EVAL_V3_SPI_PERIPH_CS_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_Init(SDK_EVAL_V3_SPI_PERIPH_CS_PORT, &GPIO_InitStructure); /* Enable SPI periph and SCLK, MOSI, MISO and CS GPIO clocks */ RCC_APB1PeriphClockCmd(SDK_EVAL_V3_SPI_PERIPH_RCC, ENABLE); } /* Configure SPI peripheral */ SPI_DeInit(s_SpiPort); SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(s_SpiPort, &SPI_InitStructure); SPI_Cmd(s_SpiPort, ENABLE); #ifdef FREERTOS xSpiMutex = xSemaphoreCreateMutex(); if (!xSpiMutex) /* Error in resource creation. */ for (;;); xSemaphoreGive(xSpiMutex); #endif SdkEvalSPICSHigh(); }
/************************************************************************* * Function Name: MmcInit * Parameters: none * Return: none * * Description: Init SPI, Cart Present, Write Protect and Chip select pins * *************************************************************************/ void MmcInit (void) { SPI_InitTypeDef SPI_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; // Enable GPIO clocks RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC, ENABLE); // Enable SPI2 Periphery clock RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); // Deinitializes the SPI2 SPI_DeInit(SPI2); // Release reset of GPIOB, GPIOC RCC_APB2PeriphResetCmd( RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC, DISABLE); // Configure SPI2_CLK, SPI2_MOSI, SPI2_nCS1, Card Present and Write Protect pins GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Pin = SD_CS; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Pin = SD_SCLK | SD_MOSI | SD_MISO; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Pin = SD_CP | SD_WP; GPIO_Init(GPIOC, &GPIO_InitStructure); // Chip select MmcChipSelect(0); // Spi init SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI2, &SPI_InitStructure); // Enable SPI2 */ SPI_Cmd(SPI2, ENABLE); // Clock Freq. Identification Mode < 400kHz MmcSetClockFreq(IdentificationModeClock); #if SPI_DMA_ENA > 0 // Enable DMA clock RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA, ENABLE); // Clear pending interrupt DMA_ClearITPendingBit( DMA_IT_GL4 | DMA_IT_GL5); // Interrupts DMA enable SPI_DMACmd(SPI2,SPI_DMAReq_Rx,DISABLE); SPI_DMACmd(SPI2,SPI_DMAReq_Tx,DISABLE); #ifndef DMA_ERRATA NVIC_InitTypeDef NVIC_InitStructure; // VIC configuration NVIC_InitStructure.NVIC_IRQChannel = DMAChannel4_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = SPI_DMA_INTR_PRIO; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = DMAChannel5_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = SPI_DMA_INTR_PRIO; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); #endif #endif // SPI_DMA_ENA > 0 }
/** * @brief Validation firmware main entry point. * @par Parameters: * None * @retval * None */ void main(void) { int ButtonIndex =0; u8 i =0; u8 LedState =1; u8 pos =0; u8 s[16]; /* Initialize I/Os in Output Mode for LEDs */ GPIO_Init(LEDS_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN,GPIO_MODE_OUT_PP_LOW_FAST); /* Initialization of I/O in Input Mode with Interrupt for Key button */ GPIO_Init(BUTTON_PORT, BUTTON_PIN, GPIO_MODE_IN_FL_IT); /* Initialization of the Interrupt sensitivity */ EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOC, EXTI_SENSITIVITY_FALL_ONLY); /* Enable general interrupts for Key button reading */ enableInterrupts(); /* Initialize SPI */ SPI_DeInit(); SPI_Init(SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_128, SPI_MODE_MASTER, SPI_CLOCKPOLARITY_HIGH, SPI_CLOCKPHASE_2EDGE, SPI_DATADIRECTION_1LINE_TX, SPI_NSS_SOFT, 0x07); SPI_Cmd(ENABLE); /* Initialize LCD */ LCD_Init(); /* Clear LCD lines */ LCD_Clear(); /* Display "moving" ST logo on first line */ for (pos = 0x80; pos < 0x88; pos++) { LCD_Clear(); LCD_DisplayLogo(pos); Delay(20000); } /* Display "moving" ST logo on second line */ for (pos = 0x90; pos < 0x98; pos++) { LCD_Clear(); LCD_DisplayLogo(pos); Delay(20000); } LCD_Clear(); /* More than 15 characters: the message is displayed on 2 lines */ /* LCD_PrintMsg("STM8S - SPI/LCD example"); */ /* Max 15 characters per line */ LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, " *** STM8S *** "); LCD_PrintString(LCD_LINE2, ENABLE, DISABLE, "SPI-LCD example"); for (i = 0; i < 10; i++) { Delay(0xFFFF); } LCD_Clear(); LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, "Press KEY..."); while (1) { /* Check button status */ if (GetVar_ButtonPressed() == TRUE) /* Button is pressed */ { ButtonPressed = FALSE; LCD_ClearLine(LCD_LINE2); LCD_PrintString(LCD_LINE2, DISABLE, DISABLE, "LED #"); /*Use the sprintf() and LCD_Print() function to print a digit on the LCD */ if (LedState == 0) { sprintf(s,"%d ", ButtonIndex + 1); LCD_Print(s); LCD_SetCursorPos(LCD_LINE2, 4); /* 8th position */ LCD_PrintChar('O'); LCD_PrintChar('F'); LCD_PrintChar('F'); } /*Use the LCD_PrintDec1() function to print a digit on the LCD */ else { LCD_PrintDec1((u8)(ButtonIndex + 1)); /* Display at current cursor position */ LCD_SetCursorPos(LCD_LINE2, 4); /* 8th position */ LCD_PrintChar('O'); LCD_PrintChar('N'); LCD_PrintChar(' '); } switch (ButtonIndex) { case 0: GPIO_WriteReverse(LEDS_PORT, LED1_PIN); ButtonIndex++; break; case 1: GPIO_WriteReverse(LEDS_PORT, LED2_PIN); ButtonIndex++; break; case 2: GPIO_WriteReverse(LEDS_PORT, LED3_PIN); ButtonIndex++; break; default: case 3: GPIO_WriteReverse(LEDS_PORT, LED4_PIN); ButtonIndex = 0; LedState ^= 0x01; break; } } } }
/** * @brief Main program. * @param None * @retval None */ void main(void) { /*High speed internal clock prescaler: 1*/ CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); /* UART1 configuration -------------------------------------------------------*/ /* UART1 configured as follow: - Word Length = 8 Bits - 1 Stop Bit - No parity - BaudRate = 9600 baud - UART1 Clock enabled - Polarity Low - Phase Middle - Last Bit enabled - Receive and transmit enabled */ UART1_DeInit(); UART1_Init((uint32_t)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, (UART1_SyncMode_TypeDef)(UART1_SYNCMODE_CLOCK_ENABLE | UART1_SYNCMODE_CPOL_LOW |UART1_SYNCMODE_CPHA_MIDDLE |UART1_SYNCMODE_LASTBIT_ENABLE), UART1_MODE_TXRX_ENABLE); UART1_Cmd(DISABLE); /* SPI configuration */ SPI_DeInit(); /* Initialize SPI in Slave mode */ SPI_Init(SPI_FIRSTBIT_LSB, SPI_BAUDRATEPRESCALER_2, SPI_MODE_SLAVE, SPI_CLOCKPOLARITY_LOW, SPI_CLOCKPHASE_1EDGE, SPI_DATADIRECTION_2LINES_FULLDUPLEX, SPI_NSS_SOFT,(uint8_t)0x07); /* Enable the UART1*/ UART1_Cmd(ENABLE); Delay(0xFFF); /* Enable the SPI*/ SPI_Cmd(ENABLE); while (NbrOfDataToRead--) { /* Wait until end of transmit */ while (SPI_GetFlagStatus(SPI_FLAG_TXE)== RESET) { } /* Write one byte in the SPI Transmit Data Register */ SPI_SendData(TxBuffer2[TxCounter]); /* Write one byte in the UART1 Transmit Data Register */ UART1_SendData8(TxBuffer1[TxCounter++]); /* Wait until end of transmit */ while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET) { } /* Wait the byte is entirely received by UART1 */ while (UART1_GetFlagStatus(UART1_FLAG_RXNE) == RESET) { } /* Store the received byte in the RxBuffer1 */ RxBuffer1[RxCounter] = UART1_ReceiveData8(); /* Wait the byte is entirely received by SPI */ while (SPI_GetFlagStatus(SPI_FLAG_RXNE) == RESET) { } /* Store the received byte in the RxBuffer2 */ RxBuffer2[RxCounter++] = SPI_ReceiveData(); } /* Check the received data with the sent ones */ TransferStatus1 = Buffercmp(TxBuffer1, RxBuffer2, TxBufferSize1); /* TransferStatus = PASSED, if the data transmitted from UART1 and received by SPI are the same */ /* TransferStatus = FAILED, if the data transmitted from UART1 and received by SPI are different */ TransferStatus2 = Buffercmp(TxBuffer2, RxBuffer1, TxBufferSize2); /* TransferStatus = PASSED, if the data transmitted from SPI and received by UART1 are the same */ /* TransferStatus = FAILED, if the data transmitted from SPI and received by UART11 are different */ while (1); }
/** * @brief Initializes the SPI for the EEPROM. * SPI, MISO, MOSI and SCLK are the same used for the SPIRIT1. * This function can be replaced by EepromCsPinInitialization if * SpiritSpiInit is called. * @param None * @retval None */ void EepromSpiInitialization(void) { SPI_InitTypeDef SPI_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; s_EepromSpiPort = s_EepromSpiPortVersion[SdkEvalGetVersion()]; s_vectnEepromSpiCsPin = (uint16_t *)&s_vectpxEepromSpiCsPinVersion[SdkEvalGetVersion()]; s_vectpxEepromSpiCsPort = &s_vectpxEepromSpiCsPortVersion[SdkEvalGetVersion()]; if(SdkEvalGetVersion() == SDK_EVAL_VERSION_2_1) { /* Enable SPI periph and SCLK, MOSI, MISO and CS GPIO clocks */ RCC_APB2PeriphClockCmd(EEPROM_V2_SPI_PERIPH_RCC, ENABLE); RCC_AHBPeriphClockCmd(EEPROM_V2_SPI_PERIPH_MOSI_RCC | EEPROM_V2_SPI_PERIPH_MISO_RCC | EEPROM_V2_SPI_PERIPH_SCLK_RCC | EEPROM_V2_SPI_PERIPH_CS_RCC, ENABLE); /* Configure the AF for MOSI, MISO and SCLK GPIO pins*/ GPIO_PinAFConfig(EEPROM_V2_SPI_PERIPH_MOSI_PORT, EEPROM_V2_SPI_PERIPH_MOSI_RCC_SOURCE, EEPROM_V2_SPI_PERIPH_MOSI_AF); GPIO_PinAFConfig(EEPROM_V2_SPI_PERIPH_MISO_PORT, EEPROM_V2_SPI_PERIPH_MISO_RCC_SOURCE, EEPROM_V2_SPI_PERIPH_MISO_AF); GPIO_PinAFConfig(EEPROM_V2_SPI_PERIPH_SCLK_PORT, EEPROM_V2_SPI_PERIPH_SCLK_RCC_SOURCE, EEPROM_V2_SPI_PERIPH_SCLK_AF); /* Configure SPI pins:SCLK, MISO and MOSI */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_InitStructure.GPIO_Pin = EEPROM_V2_SPI_PERIPH_SCLK_PIN; GPIO_Init(EEPROM_V2_SPI_PERIPH_SCLK_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = EEPROM_V2_SPI_PERIPH_MISO_PIN; GPIO_Init(EEPROM_V2_SPI_PERIPH_MISO_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = EEPROM_V2_SPI_PERIPH_MOSI_PIN; GPIO_Init(EEPROM_V2_SPI_PERIPH_MOSI_PORT, &GPIO_InitStructure); } else if(SdkEvalGetVersion() == SDK_EVAL_VERSION_3 || SdkEvalGetVersion() == SDK_EVAL_VERSION_D1) { /* Enable SPI periph and SCLK, MOSI, MISO and CS GPIO clocks */ RCC_APB1PeriphClockCmd(EEPROM_V3_SPI_PERIPH_RCC, ENABLE); RCC_AHBPeriphClockCmd(EEPROM_V3_SPI_PERIPH_MOSI_RCC | EEPROM_V3_SPI_PERIPH_MISO_RCC | EEPROM_V3_SPI_PERIPH_SCLK_RCC | EEPROM_V3_SPI_PERIPH_CS_RCC, ENABLE); /* Configure the AF for MOSI, MISO and SCLK GPIO pins*/ GPIO_PinAFConfig(EEPROM_V3_SPI_PERIPH_MOSI_PORT, EEPROM_V3_SPI_PERIPH_MOSI_RCC_SOURCE, EEPROM_V3_SPI_PERIPH_MOSI_AF); GPIO_PinAFConfig(EEPROM_V3_SPI_PERIPH_MISO_PORT, EEPROM_V3_SPI_PERIPH_MISO_RCC_SOURCE, EEPROM_V3_SPI_PERIPH_MISO_AF); GPIO_PinAFConfig(EEPROM_V3_SPI_PERIPH_SCLK_PORT, EEPROM_V3_SPI_PERIPH_SCLK_RCC_SOURCE, EEPROM_V3_SPI_PERIPH_SCLK_AF); /* Configure SPI pins:SCLK, MISO and MOSI */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_InitStructure.GPIO_Pin = EEPROM_V3_SPI_PERIPH_SCLK_PIN; GPIO_Init(EEPROM_V3_SPI_PERIPH_SCLK_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = EEPROM_V3_SPI_PERIPH_MISO_PIN; GPIO_Init(EEPROM_V3_SPI_PERIPH_MISO_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = EEPROM_V3_SPI_PERIPH_MOSI_PIN; GPIO_Init(EEPROM_V3_SPI_PERIPH_MOSI_PORT, &GPIO_InitStructure); } /* Configure SPI pin: CS */ GPIO_InitStructure.GPIO_Pin = *s_vectnEepromSpiCsPin; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_Init(*s_vectpxEepromSpiCsPort, &GPIO_InitStructure); /* Configure SPI peripheral */ SPI_DeInit(s_EepromSpiPort); SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(s_EepromSpiPort, &SPI_InitStructure); SPI_Cmd(s_EepromSpiPort, ENABLE); EepromSPICSHigh(); }
/** * @brief Save Demonstration context (GPIOs Configurations, peripherals,...). * @param None * @retval None */ void IDD_Measurement_SaveContext(void) { GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; /* Deinitialize all peripherals used in the Demo */ DAC_DeInit(); ADC_DeInit(ADC1); DMA_DeInit(DMA1_Channel2); SPI_DeInit(SPI1); TIM_DeInit(TIM2); EXTI_DeInit(); TIM_DeInit(TIM6); LCD_DeInit(); SYSCFG_DeInit(); I2C_DeInit(I2C1); COMP_DeInit(); GPIOA_MODER = GPIOA->MODER; GPIOB_MODER = GPIOB->MODER; GPIOC_MODER = GPIOC->MODER; GPIOD_MODER = GPIOD->MODER; GPIOE_MODER = GPIOE->MODER; GPIOH_MODER = GPIOH->MODER; GPIOA_PUPDR = GPIOA->PUPDR; GPIOB_PUPDR = GPIOB->PUPDR; GPIOC_PUPDR = GPIOC->PUPDR; GPIOD_PUPDR = GPIOD->PUPDR; GPIOE_PUPDR = GPIOE->PUPDR; GPIOH_PUPDR = GPIOH->PUPDR; /* Configure all GPIO port pins in Analog Input mode */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_Init(GPIOE, &GPIO_InitStructure); GPIO_Init(GPIOH, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = IDD_CNT_EN_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(IDD_CNT_EN_GPIO_PORT, &GPIO_InitStructure); /* Configure IDD_CNT_EN pin as output push-pull ----------------------------*/ GPIO_SetBits(IDD_CNT_EN_GPIO_PORT, IDD_CNT_EN_PIN); /* Connect Button EXTI Line to Button GPIO Pin */ SYSCFG_EXTILineConfig(IDD_WAKEUP_EXTI_PORTSOURCE, IDD_WAKEUP_EXTI_PINSOURCE); /* Configure IDD_WAKEUP pin as input pull-down -----------------------------*/ GPIO_InitStructure.GPIO_Pin = IDD_WAKEUP_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(IDD_WAKEUP_GPIO_PORT, &GPIO_InitStructure); /* Configure the IDD_WAKEUP EXTI Line */ EXTI_ClearITPendingBit(IDD_WAKEUP_EXTI_LINE); EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Line = IDD_WAKEUP_EXTI_LINE; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Enable the EXTI Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = IDD_WAKEUP_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); }
/*********************************************************************** * @brief Deal with the event handler for cc112x. * @param p_event_data * @param event_size * @retval None ************************************************************************/ void cc112x_event_handler(void * p_event_data, uint16_t event_size) { cc112x_event_t * p_cc112x_event_temp = p_event_data; uint8_t part_num = 0; uint8_t i,readByte; switch(p_cc112x_event_temp->eCC112x_event) { case CC112X_INIT_EVENT: #ifdef CC112x_DEBUG printf("[CC112X] CC112X_INIT_EVENT...\r\n"); #endif cc112x_init(); GPIO_ResetBits(GPIO_PORT_CC112X_RESET, GPIO_PIN_CC112X_RESET); delay1ms(1); GPIO_SetBits(GPIO_PORT_CC112X_RESET, GPIO_PIN_CC112X_RESET); // Power Up Reset rf_PowerUpReset(); registerConfig(); #ifdef CC112x_DEBUG printf("[CC112X] registerConfiging OK...\r\n"); cc112xSpiReadReg(CC112X_PARTNUMBER, &part_num, 1); printf("[CC112X] cc112xSpiReadReg,part_num = 0x%02x\r\n",part_num); #endif SPI_DeInit(APP_CC112X_SPI); GPIO_DeInit(GPIO_PORT_CC112X_SPI_NSS); break; case CC112X_TRANSMIT_EVENT: #ifdef CC112x_DEBUG printf("[CC112X] CC112X_TRANSMIT_EVENT...\r\n"); #endif trxRfSpiInterfaceInit(); #ifdef CC112x_DEBUG printf("[CC112X] cc112xSpiReadReg,part_num = 0x%02x\r\n",part_num); for(i = 0;i < (sizeof(preferredSettings)/sizeof(registerSetting_t)); i++) { cc112xSpiReadReg(preferredSettings[i].addr, &readByte, 1); printf("[CC112X] i = %d : 0x%02x \r\n",i,readByte); } #endif SPI_DeInit(APP_CC112X_SPI); GPIO_DeInit(GPIO_PORT_CC112X_SPI_NSS); break; case CC112X_RECEIVE_EVENT: trxRfSpiInterfaceInit(); #ifdef CC112x_DEBUG cc112xSpiReadReg(CC112X_PARTNUMBER, &part_num, 1); printf("[CC112X] cc112xSpiReadReg,part_num = 0x%02x\r\n",part_num); for(i = 0;i < (sizeof(preferredSettings)/sizeof(registerSetting_t)); i++) { cc112xSpiReadReg(preferredSettings[i].addr, &readByte, 1); printf("[CC112X] i = %d : 0x%02x \r\n",i,readByte); } #endif SPI_DeInit(APP_CC112X_SPI); GPIO_DeInit(GPIO_PORT_CC112X_SPI_NSS); break; default: break; } }
/*********************************************************************//** * @brief c_entry: Main SPI program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { uint8_t tmpchar[2] = {0, 0}; PINSEL_CFG_Type PinCfg; __IO FlagStatus exitflag; /* * Initialize SPI pin connect * P0.15 - SCK; * P0.16 - SSEL - used as GPIO * P0.17 - MISO * P0.18 - MOSI */ PinCfg.Funcnum = 3; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 15; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 17; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 18; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 16; PinCfg.Funcnum = 0; PINSEL_ConfigPin(&PinCfg); /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); // initialize SPI configuration structure to default SPI_ConfigStructInit(&SPI_ConfigStruct); // Initialize SPI peripheral with parameter given in structure above SPI_Init(LPC_SPI, &SPI_ConfigStruct); // Initialize /CS pin to GPIO function CS_Init(); /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(SPI_IRQn, ((0x01<<3)|0x01)); /* Enable SSP0 interrupt */ NVIC_EnableIRQ(SPI_IRQn); /* First, send some command to reset SC16IS740 chip via SPI bus interface * note driver /CS pin to low state before transferring by CS_Enable() function */ complete = RESET; CS_Force(0); xferConfig.tx_data = iocon_cfg; xferConfig.rx_data = spireadbuf; xferConfig.length = sizeof (iocon_cfg); SPI_ReadWrite(LPC_SPI, &xferConfig, SPI_TRANSFER_INTERRUPT); while (complete == RESET); CS_Force(1); complete = RESET; CS_Force(0); xferConfig.tx_data = iodir_cfg; xferConfig.rx_data = spireadbuf; xferConfig.length = sizeof (iodir_cfg); SPI_ReadWrite(LPC_SPI, &xferConfig, SPI_TRANSFER_INTERRUPT); while (complete == RESET); CS_Force(1); // Reset exit flag exitflag = RESET; // Start to use SPI polling mode /* Read some data from the buffer */ while (exitflag == RESET) { while((tmpchar[0] = _DG) == 0); if (tmpchar[0] == 27){ /* ESC key, set exit flag */ _DBG_(menu2); exitflag = SET; } else if (tmpchar[0] == 'r'){ print_menu(); } else { if (tmpchar[0] == '1') { // LEDs are ON now... CS_Force(0); xferConfig.tx_data = iostate_on; xferConfig.rx_data = spireadbuf; xferConfig.length = sizeof (iostate_on); SPI_ReadWrite(LPC_SPI, &xferConfig, SPI_TRANSFER_POLLING); CS_Force(1); } else if (tmpchar[0] == '2') { // LEDs are OFF now... CS_Force(0); xferConfig.tx_data = iostate_off; xferConfig.rx_data = spireadbuf; xferConfig.length = sizeof (iostate_off); SPI_ReadWrite(LPC_SPI, &xferConfig, SPI_TRANSFER_POLLING); CS_Force(1); } /* Then Echo it back */ _DBG_(tmpchar); } } // DeInitialize UART0 peripheral SPI_DeInit(LPC_SPI); /* Loop forever */ while(1); return 1; }
/*********************************************************************//** * @brief c_entry: Main SPI program body * @param[in] None * @return int **********************************************************************/ int c_entry(void) { PINSEL_CFG_Type PinCfg; SPI_DATA_SETUP_Type xferConfig; /* * Initialize SPI pin connect * P0.15 - SCK; * P0.16 - SSEL - used as GPIO * P0.17 - MISO * P0.18 - MOSI */ PinCfg.Funcnum = 3; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Portnum = 0; PinCfg.Pinnum = 15; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 17; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 18; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 16; PinCfg.Funcnum = 0; PINSEL_ConfigPin(&PinCfg); /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); // print welcome screen print_menu(); SPI_ConfigStruct.CPHA = SPI_CPHA_SECOND; SPI_ConfigStruct.CPOL = SPI_CPOL_LO; SPI_ConfigStruct.ClockRate = 2000000; SPI_ConfigStruct.DataOrder = SPI_DATA_MSB_FIRST; SPI_ConfigStruct.Databit = SPI_DATABIT_SIZE; SPI_ConfigStruct.Mode = SPI_MASTER_MODE; // Initialize SPI peripheral with parameter given in structure above SPI_Init(LPC_SPI, &SPI_ConfigStruct); /* Initialize Buffer */ Buffer_Init(); xferConfig.tx_data = Tx_Buf; xferConfig.rx_data = Rx_Buf; xferConfig.length = BUFFER_SIZE; SPI_ReadWrite(LPC_SPI, &xferConfig, SPI_TRANSFER_POLLING); // Verify buffer after transferring Buffer_Verify(); _DBG_("Verify complete"); SPI_DeInit(LPC_SPI); /* Loop forever */ while(1); return 1; }
/** * @brief Initializes the SPI for the EEPROM. * SPI, MISO, MOSI and SCLK are the same used for the BlueNRG. * This function can be replaced by EepromCsPinInitialization() if * SdkEvalSpiInit() is called. * @param None * @retval Status */ int8_t EepromSpiInitialization(void) { int8_t retValue; SPI_InitTypeDef SPI_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* Configure Eeprom SPI initialization parameters depending on the selected platform: BlueNRG EVal Kits or User Defined platforms */ retValue = EepromSpi_Configure_Platform(); if (retValue == -1) /* BlueNRG Development Kit platfrom is not supported */ return (retValue); /* Configure the AF for MOSI, MISO and SCLK GPIO pins */ GPIO_PinAFConfig(Get_vectEepromSpiMosiPort(), Get_vectEepromSpiMosiPinSource(), Get_vectEepromSpiMosiAF()); GPIO_PinAFConfig(Get_vectEepromSpiMisoPort(), Get_vectEepromSpiMisoPinSource(), Get_vectEepromSpiMisoAF()); GPIO_PinAFConfig(Get_vectEepromSpiSclkPort(), Get_vectEepromSpiSclkPinSource(), Get_vectEepromSpiSclkAF()); /* Configure SPI pins:SCLK, MISO and MOSI */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_InitStructure.GPIO_Pin = Get_vectEepromSpiSclkPin(); GPIO_Init(Get_vectEepromSpiSclkPort(), &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = Get_vectpxEepromSpiMisoPin(); GPIO_Init(Get_vectEepromSpiMisoPort(), &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = Get_vectEepromSpiMosiPin(); GPIO_Init(Get_vectEepromSpiMosiPort(), &GPIO_InitStructure); /* Configure SPI pin: CS */ GPIO_InitStructure.GPIO_Pin = Get_vectEepromSpiCsPin(); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_WriteBit(Get_vectEepromSpiCsPort(), Get_vectEepromSpiCsPin(), Bit_SET); GPIO_Init(Get_vectEepromSpiCsPort(), &GPIO_InitStructure); /* Configure SPI peripheral */ SPI_DeInit(Get_EepromSpiPort()); SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(Get_EepromSpiPort(), &SPI_InitStructure); SPI_Cmd(Get_EepromSpiPort(), ENABLE); EepromSPICSHigh(Get_vectEepromSpiCsPort(),Get_vectEepromSpiCsPin()); /* TBR */ return(0); }/* end EepromSpiInitialization() */