cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F030C6 problem SPI comunication

u23
Senior
Posted on September 04, 2014 at 10:07

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:

 0690X00000602xYQAQ.jpg

Thanks

4 REPLIES 4
Posted on September 04, 2014 at 11:16

The Input/Output sense seems backward. Wouldn't MOSI need to go to SI?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
u23
Senior
Posted on September 04, 2014 at 14:09

Exact!

I invert the pins and verify the source code!   

Thanks

u23
Senior
Posted on September 04, 2014 at 16:23

I eliminated the EEPROM device in schematic.

0690X00000602xdQAA.jpg

I send the char with SPI and monitoring the signal in output from microcontroller.

SSI_CLK --> is low;

CS_EEPROM  --> is  low for 100 ms (

duration

of

transmission of the

given

)

then

back high for 500 ms;

SSI_DIN --> is low.

T

he executed code is

the following:

int main(void)

{

    uint8_t Dato = 0xAA;

    /* Initialize the SPI EEPROM driver ----------------------------------------*/

    spiInit();

 

  /* Infinite loop */

  while (1)

  {

           

             SPI_SSOutputCmd(SPIx,ENABLE);    

        

            /*!< Send WriteAddr address byte to write to */

            SPI_SendData8(SPI1, Dato);

            Delay(100);          

        

            SPI_SSOutputCmd(SPIx,DISABLE); 

            

            Delay(500);

   }

}

Why the CLK signal is absent?

Help me!

u23
Senior
Posted on September 09, 2014 at 10:12

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6XM&d=%2Fa%2F0X0000000bqB%2FQtZP9P3zRxCC.cNnFgEO27ptJQ5J5iQZ3gW.Qa50CSk&asPdf=false