cancel
Showing results for 
Search instead for 
Did you mean: 

SPI2

frankfrank953
Associate II
Posted on May 13, 2010 at 00:44

SPI2

3 REPLIES 3
smart2
Associate II
Posted on May 17, 2011 at 13:50

/* Defines for the SPI and GPIO pins used to drive the SPI Flash */

  #define SPI_FLASH                      SPI2

  #define SPI_FLASH_CLK             RCC_APB1Periph_SPI2

  #define SPI_FLASH_GPIO            GPIOB

  #define SPI_FLASH_GPIO_CLK        RCC_APB1Periph_SPI2

  #define SPI_FLASH_CS_GPIO_CLK     RCC_APB2Periph_GPIOB

  #define SPI_FLASH_CS                      GPIO_Pin_12

  #define SPI_FLASH_PIN_SCK         GPIO_Pin_13

  #define SPI_FLASH_PIN_MISO        GPIO_Pin_14

  #define SPI_FLASH_PIN_MOSI        GPIO_Pin_15

  #define SPI_FLASH_CS_GPIO          GPIOB

/*******************************************************************************

* Function Name  : SPI_FRAM_Init

* Description    : Function to initialize SPI

* Return         : None

*******************************************************************************/

VOID SPI_FRAM_Init(VOID)

{

  SPI_InitTypeDef  SPI_InitStructure;

  GPIO_InitTypeDef GPIO_InitStructure;

  /* Enable SPI and GPIO clocks */

  RCC_APB1PeriphClockCmd(SPI_FLASH_CLK | SPI_FLASH_GPIO_CLK | SPI_FLASH_CS_GPIO_CLK, ENABLE);

  /* Configure SPI pins: SCK, MISO and MOSI */

  GPIO_InitStructure.GPIO_Pin = SPI_FLASH_PIN_SCK | SPI_FLASH_PIN_MISO | SPI_FLASH_PIN_MOSI;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(SPI_FLASH_GPIO, &GPIO_InitStructure);

  /* Configure I/O for Flash Chip select */

  GPIO_InitStructure.GPIO_Pin = SPI_FLASH_CS;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

  GPIO_Init(SPI_FLASH_CS_GPIO, &GPIO_InitStructure);

  /* Deselect the FLASH: Chip Select high */

  SPI_FLASH_CS_HIGH();

  /* SPI configuration */

  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_2; /* PCLK1 = HCLK/4  72/4=18= 18/2= 9Mhz*/

  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;

  SPI_InitStructure.SPI_CRCPolynomial = 7;

  SPI_Init(SPI_FLASH, &SPI_InitStructure);

  /* Enable the SPI  */

  SPI_Cmd(SPI_FLASH, ENABLE);

}

Posted on May 17, 2011 at 13:50

I am having a problem setting the RCC_APB2Periph_SPI2 because there is no define for the register value

Because it is on the APB1 bus, not APB2

RCC_APB1Periph_SPI2

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
frankfrank953
Associate II
Posted on May 17, 2011 at 13:50

Thanks guys. I spotted that about 20 minutes after posting .... I feel like such a muppet, I must stop working late as it all blurs together