AnsweredAssumed Answered

STM32F030C6 problem SPI comunication

Question asked by LaserElettronicaSRL on Sep 4, 2014
Latest reply on Sep 9, 2014 by LaserElettronicaSRL
Hi,
the my problem is comunication with SPI.
The configuration SPI is following:


/* Private define ------------------------------------------------------------*/
    /* Uncomment the size of data to be transmetted (only one data size must be selected) */
    #define SPI_DATASIZE                     SPI_DataSize_8b

    #define SPIx                                        SPI1
    #define SPIx_CLK                             RCC_APB2Periph_SPI1
    #define SPIx_IRQn                            SPI1_IRQn
    #define SPIx_IRQHandler                 SPI1_IRQHandler

    #define SPIx_SCK_PIN                     GPIO_Pin_13
  #define SPIx_SCK_GPIO_PORT        GPIOB
  #define SPIx_SCK_GPIO_CLK          RCC_AHBPeriph_GPIOB
  #define SPIx_SCK_SOURCE              GPIO_PinSource13
  #define SPIx_SCK_AF                         GPIO_AF_0

  #define SPIx_MISO_PIN                    GPIO_Pin_14
  #define SPIx_MISO_GPIO_PORT     GPIOB
  #define SPIx_MISO_GPIO_CLK        RCC_AHBPeriph_GPIOB
  #define SPIx_MISO_SOURCE            GPIO_PinSource14
  #define SPIx_MISO_AF                       GPIO_AF_0

  #define SPIx_MOSI_PIN                    GPIO_Pin_15
  #define SPIx_MOSI_GPIO_PORT     GPIOB
  #define SPIx_MOSI_GPIO_CLK       RCC_AHBPeriph_GPIOB
  #define SPIx_MOSI_SOURCE           GPIO_PinSource15
  #define SPIx_MOSI_AF                      GPIO_AF_0

  #define SPIx_NSS_PIN                       GPIO_Pin_12
  #define SPIx_NSS_GPIO_PORT       GPIOB
  #define SPIx_NSS_GPIO_CLK         RCC_AHBPeriph_GPIOB
  #define SPIx_NSS_SOURCE             GPIO_PinSource12
  #define SPIx_NSS_AF                        GPIO_AF_0


void spiInit()
{
  GPIO_InitTypeDef GPIO_InitStructure;
    SPI_InitTypeDef  SPI_InitStructure;

  /* Enable the SPI peripheral */
  RCC_APB2PeriphClockCmd(SPIx_CLK, ENABLE);
 

  /* Enable SCK, MOSI, MISO and NSS GPIO clocks */
  RCC_AHBPeriphClockCmd(SPIx_SCK_GPIO_CLK | SPIx_MISO_GPIO_CLK | SPIx_MOSI_GPIO_CLK |
                        SPIx_NSS_GPIO_CLK , ENABLE);
 
  /* SPI pin mappings */
  GPIO_PinAFConfig(SPIx_SCK_GPIO_PORT, SPIx_SCK_SOURCE, SPIx_SCK_AF);
  GPIO_PinAFConfig(SPIx_MOSI_GPIO_PORT, SPIx_MOSI_SOURCE, SPIx_MOSI_AF);
  GPIO_PinAFConfig(SPIx_MISO_GPIO_PORT, SPIx_MISO_SOURCE, SPIx_MISO_AF);
  GPIO_PinAFConfig(SPIx_NSS_GPIO_PORT, SPIx_NSS_SOURCE, SPIx_NSS_AF);
 
  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_Level_3;

  /* SPI SCK pin configuration */
  GPIO_InitStructure.GPIO_Pin = SPIx_SCK_PIN;
  GPIO_Init(SPIx_SCK_GPIO_PORT, &GPIO_InitStructure);

  /* SPI  MOSI pin configuration */
  GPIO_InitStructure.GPIO_Pin =  SPIx_MOSI_PIN;
  GPIO_Init(SPIx_MOSI_GPIO_PORT, &GPIO_InitStructure);

  /* SPI MISO pin configuration */
  GPIO_InitStructure.GPIO_Pin = SPIx_MISO_PIN;
  GPIO_Init(SPIx_MISO_GPIO_PORT, &GPIO_InitStructure);
 
  /* SPI NSS pin configuration */
  GPIO_InitStructure.GPIO_Pin = SPIx_NSS_PIN;
  GPIO_Init(SPIx_NSS_GPIO_PORT, &GPIO_InitStructure);
 
  /* SPI configuration -------------------------------------------------------*/
  SPI_I2S_DeInit(SPIx);
  SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
  SPI_InitStructure.SPI_DataSize = SPI_DATASIZE;
  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;
  /* Initializes the SPI communication */
  SPI_Init(SPIx, &SPI_InitStructure);

  /* Enable the SPI peripheral */
  SPI_Cmd(SPIx, ENABLE);

}

I ask you if this configuration is correct!

The use the SPI for comunication EEPROM with the following schematic:

 SPI_EEPROM.JPG


Thanks


Outcomes