STM32F0 SPI buffer

Başlatan ea, 25 Ocak 2015, 16:47:22

ea

Herkese Merhaba;
stm32f0 ile spi kullanarak eeproma veri yazma okuma yapmaya calışıyorum fakat söyle bi sorun oluşuyor; eeproma bir byte veri gonderdiğimde sanırım spi bunu buffera yüklüyor fakat gondermiyor, çünkü eeprom cevap olarak değer dondurmesi gerekiyor fakat rx reğisterını okuduğumda 0x00 okuyorum. arkasından tekrar bir byte gönderdiğimde bu defa spi bytı eeproma gonderiyor, geriyede olması gereken değer donuyor ve okuyorum.bunun sebebi ne olabilir?
spi init kodlarım;

void AT45DB_Hard_Init(void)
{

    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_InitTypeDef GPIOB_InitStructure;
    GPIO_InitTypeDef GPIOA_InitStructure;
    SPI_InitTypeDef  SPI_InitStructure;
    /* Enable the SPI periph */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);

    /* Enable SCK, MOSI, MISO and NSS GPIO clocks */
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB, ENABLE);

    GPIOB_InitStructure.GPIO_Pin =  GPIO_Pin_9 ; //chip select pin
    GPIOB_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIOB_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIOB_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIOB_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_Init(GPIOB, &GPIOB_InitStructure);

    GPIOA_InitStructure.GPIO_Pin =  GPIO_Pin_15; // reset pin
    GPIOA_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIOA_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIOA_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIOA_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_Init(GPIOA, &GPIOA_InitStructure);

    GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_AF_0);
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_0);
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_0);

    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 = GPIO_Pin_3;
    GPIO_Init(GPIOB, &GPIO_InitStructure);

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

    /* SPI MISO pin configuration */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
    GPIO_Init(GPIOB, &GPIO_InitStructure);

    /* SPI configuration -------------------------------------------------------*/
    SPI_I2S_DeInit(SPI1);

    SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
    SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
    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;
    SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
    SPI_Init(SPI1, &SPI_InitStructure);

    SPI_RxFIFOThresholdConfig(SPI1, SPI_RxFIFOThreshold_QF);
    //SPI_CalculateCRC(SPI1,DISABLE);
    SPI_SSOutputCmd(SPI1,ENABLE);
    SPI_Cmd(SPI1,ENABLE);

    /* Enable the Rx buffer not empty interrupt */
     SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_RXNE, DISABLE);
     SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_TXE, DISABLE);

    /* Enable the SPI Error interrupt */
    // SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_ERR, ENABLE);
    while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET) {
    }

    SPI_ReceiveData8(SPI1);

}


bir byte gonderip geri donen değeri okuduğum kod;
uint8_t stm32_spi_rw(uint8_t out) {

  GPIO_ResetBits(GPIOB,ChipSelect); // CS low
  /*!< Wait until the transmit buffer is empty */
  while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET) {
  }

  /*!< Send the byte */
  SPI_SendData8(SPI1, out);

  /*!< Wait to receive a byte*/
  while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET) {
  }

  /*!< Return the byte read from the SPI bus */
  return SPI_ReceiveData8(SPI1);

}


Teşekkürler..
www.gstelektronik.com.tr  |  www.inohom.com