AnsweredAssumed Answered

stm32f100c8 SPI & SST25VF016B read/write operation

Question asked by nazuhin on Oct 13, 2012
Latest reply on Jun 24, 2015 by CagdasYet
hi all,i am working on external flash memory and stm32f100c8 communication via SPI,but in my code there is a wrong what i missed.perhaps you may see..
/*---------------------------------*/
#include "stm32f10x.h"
#include "stm32f10x_spi.h"
#include "sFlash.h" //sst25vf016b drivers


/*-------------------------------------------------------------*/
#define  FLASH_WriteAddress     0x700000 //flash memory address
#define  FLASH_ReadAddress      FLASH_WriteAddress
#define  FLASH_SectorToErase    FLASH_WriteAddress




#define  BufferSize (countof(Tx_Buffer)-1)


#define countof(a) (sizeof(a) / sizeof(*(a)))




uint8_t Tx_Buffer[] = "HELLO";//data to given memory address
uint8_t  Rx_Buffer[BufferSize];//read from given memory address


/*---------------------------------*/
/*---------------------------------*/
/*function prototypes*/


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




/*---------------------------------*/
/*---------------------------------*/


void RCC_Configuration(void)
{
          RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
          RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
     
}


/*---------------------------------*/
/*---------------------------------*/
void GPIO_Configuration(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
          //sck-5
          
          //mosi 7
          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_7;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //out pushpull
          GPIO_Init(GPIOA, &GPIO_InitStructure);
     
          //nss 4 chip select
          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
          GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //out pushpull
          GPIO_Init(GPIOA, &GPIO_InitStructure);
          //miso 6
          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//In floating
          GPIO_Init(GPIOA, &GPIO_InitStructure);
}


/*---------------------------------*/
/*---------------------------------*/
void SPI_Configuration(void){
     
          SPI_InitTypeDef SPI_InitStructure;
          
          GPIO_ResetBits(GPIOA,GPIO_Pin_5);
          sFLASH_CS_HIGH();
          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_Soft;
          SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
          SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
          SPI_InitStructure.SPI_CRCPolynomial = 7;
  
          SPI_Init(SPI1, &SPI_InitStructure);
     
          SPI_Cmd(SPI1, ENABLE);
     
     
}


/*---------------------------------*/
/*---------------------------------*/
int main(){
     
          RCC_Configuration();
          GPIO_Configuration();
          SPI_Configuration();
     
     
          /*erase chip*/
    sFLASH_EraseBulk();
          /*write tx buffer to Address with size*/
    sFLASH_WriteBuffer(Tx_Buffer, FLASH_WriteAddress, BufferSize);
          /*read buffer from given memory address*/
    sFLASH_ReadBuffer(Rx_Buffer, FLASH_ReadAddress, BufferSize);
     
          while(1);


}



when i write "hello" in TX,i see a strange char "ÿ"(dec 255-hex 0xFF) in RX buffer.But normally should "hello"..
thanks.

 

Outcomes