AnsweredAssumed Answered

Setting up SPI-bus

Question asked by andersson.fredri.002 on Apr 11, 2011
Latest reply on Oct 10, 2012 by nazuhin
Hey, Im trying to set up an SPI-bus between the STM32VLDISCOVERY and an external flash memory. I want the STM32-processor to be master and the flash-memory to be slave.

What ive tried to far is simply to set up the GPIOs and also trying to send simple data but i get nothing. Im using an oscilloscope to read Pin7 on PortA on the STM32board. Obviously im doing something wrong but i dont really know what. Probably its some code missing?

This is what i have so far:

#include "stddef.h"
#include "stm32f10x.h"
#include "stm32f10x_gpio.h"
#include <stm32f10x_spi.h>
#include "string.h"

#define SPI_COMMS           SPI1
#define PORT_SPI_COMMS      GPIOA
#define PIN_SPI_COMMS_NCS   GPIO_Pin_4
#define PIN_SPI_COMMS_SCK   GPIO_Pin_5
#define PIN_SPI_COMMS_MISO  GPIO_Pin_6
#define PIN_SPI_COMMS_MOSI  GPIO_Pin_7

void GPIO_Configuration(void);
void SPI_Configuration(void);
void RCC_Configuration(void);

int main(void)
{
    GPIO_Configuration();
    SPI_Configuration();
    RCC_Configuration();
     
    for(;;){
          SPI_I2S_SendData(SPI1,0xAAAA);
   
      }
}


void SPI_Configuration(void)
{
    SPI_InitTypeDef SPI_InitStructure;

    /* SPI_MASTER 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_High;
      SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
      SPI_InitStructure.SPI_NSS = SPI_NSS_Hard;
      SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
      SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
      SPI_InitStructure.SPI_CRCPolynomial = 7;
      SPI_Init(SPI_COMMS, &SPI_InitStructure);

    /* Enable SPI_MASTER TXE interrupt */
      SPI_I2S_ITConfig(SPI_COMMS, SPI_I2S_IT_TXE, ENABLE);

    /* Enable SPI_MASTER */
      SPI_Cmd(SPI_COMMS, ENABLE);
}


void GPIO_Configuration(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;

    // Enable SPI1 Pins Software Remapping //
    //GPIO_PinRemapConfig(GPIO_Remap_SPI1, ENABLE);

    // Configure SPI_MASTER pins: SCK, MISO and MOSI //

    GPIO_InitStructure.GPIO_Pin = PIN_SPI_COMMS_SCK | PIN_SPI_COMMS_MISO | PIN_SPI_COMMS_MOSI;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_Init(PORT_SPI_COMMS, &GPIO_InitStructure);

    GPIO_Init(PORT_SPI_COMMS, &GPIO_InitStructure);
}


void RCC_Configuration(void)
{
    // Enable GPIO clock //
    RCC_APB2PeriphClockCmd(PORT_SPI_COMMS, ENABLE);
}

What am i missing?

Thanks in advance for your help!!
//Fredrik

Outcomes