AnsweredAssumed Answered

SPI need help

Question asked by salazar.timothy on Jul 16, 2013
Latest reply on Aug 9, 2013 by khoe.septi
So ive been trying to get the SPI interface working. Here's what i have so far.

void SPI_Setup(void)
{
  SPI_InitTypeDef SPI_InitStructure;
   SPI_I2S_DeInit(SPI1);
    SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
    SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
    SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;
    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_64;
    SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
    SPI_InitStructure.SPI_CRCPolynomial = 0x1021;
 
    SPI_Init(SPI1, &SPI_InitStructure);
    SPI_CalculateCRC(SPI1, ENABLE);
    SPI_Cmd(SPI1, ENABLE);
   
}
void SPI_conf(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOA, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1 ,ENABLE);
         
      //  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
      //  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
         
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;  //PA7-MOSI
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
         
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;  //PA7-MOSI
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
     
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;  //PA5-SCK
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
         
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;  //PA4-NSS
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
   
}
 I dont know what else to do. so any help is welcome.  Next is how im Sending data, i hope
                                                               
           
SPI_I2S_SendData(SPI1, 0x1);
           
                                                                                               
           
           
SPI_I2S_SendData(SPI1, 0x1);




Outcomes