cancel
Showing results for 
Search instead for 
Did you mean: 

M95512 and STM32F103 SPI3 (no have Read Data)

Kim Sang Hyouk
Associate II

Dear all

Hello?

Now I use STM32F103 SPI3 and M95512(SPI EEPROM).

  
void SPI3_Config(void){
  SPI_InitTypeDef SPI_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure;
 
  SPI_Cmd(SPI3, DISABLE);
  SPI_I2S_DeInit(SPI3);
  
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
  GPIO_PinRemapConfig(GPIO_Remap_SPI3, ENABLE);
  
  //                            SCK          MOSI
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_5;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
 
  //                            MISO
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;  
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
   GPIO_Init(GPIOB, &GPIO_InitStructure); 
  
  //                            CS 
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;  
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
 
  // SPI configuration -------------------------------------------------------
  SPI_I2S_DeInit(SPI3);
  EEPROM_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_4;
  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  SPI_InitStructure.SPI_CRCPolynomial = 7;
  SPI_Init(SPI3, &SPI_InitStructure);
  SPI_Cmd(SPI3, ENABLE);
}

and

uint8_t SPI_SendByte(uint8_t Data){
  while ((SPI3 -> SR & SPI_I2S_FLAG_TXE) == RESET);
  SPI_I2S_SendData(SPI3, Data);
  while ((SPI3 -> SR & SPI_I2S_FLAG_RXNE) == RESET);
  return SPI_I2S_ReceiveData(SPI3);
}
 
void SPI_WriteByte(unsigned char Data){
  while ((SPI3 -> SR & SPI_I2S_FLAG_TXE) == RESET);
  SPI3 -> DR = Data;
  while ((SPI3 -> SR & SPI_I2S_FLAG_RXNE) == RESET);
  Data = SPI3 -> DR; 
}

unsigned int M95512_RDSR(void){//0x05 Read Status Register
  unsigned char data_H, data_L;
  unsigned int data;
 
  EEPROM_CS_LOW();
  SPI_SendByte(RDSR);
  data_H = SPI_SendByte(DUMMY); //SPI_ReadByte();
  data_L = SPI_SendByte(DUMMY); //SPI_ReadByte();
  EEPROM_CS_HIGH();
  return data = (data_H << 1) + (data_L << 7);
}

When I read RDSR data  is  0x0104

I don't know mean

0690X000006C0EjQAK.jpgWhen I see data sheet  RDSR is only 8 bit

But read 2 byte.

0690X000006C0EoQAK.jpg

now STM32F103 SPI3  work   CS, SCK, MOSI clock.

When I read another adress. than no have receive data.

How can I check.

Please help me. Thank you~

and sorry My english.

4 REPLIES 4
MAsga
Associate

Hi @Kim Sang Hyouk​ 

First of all, you just mention your STM32F103 family and you didn't clarify your exact MCU.

you should config your MISO pin as 'Alternative Function and Push Pull' to be able to read from SPI.

Input Floating is a legitimate setting for MISO on the F1 series parts

You'll basically have to scope the pin, or use logic/protocol analyzer, and confirm the patterns seen on the pin to those reported by the STM32. You might have to review polarity/phase of clock.

Sorry not using either of these parts.

With PB3 you might want to make sure SWV functionality is not mapped on the pin, so check the SWD/JTAG remapping options in manual.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Kim Sang Hyouk
Associate II
  //                            MISO
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;  
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;       // GPIO_Mode_IN_FLOATING;
   GPIO_Init(GPIOB, &GPIO_InitStructure);

MISO Pin  GPIO_Mode_AF_PP or GPIO_Mode_IN_FLOATING

both  Work is Good.

This is RDSR Requeset 0x05;0690X000006C0QQQA0.bmp

RDSR Read Data 0x02 0x02

0690X000006C0QLQA0.bmp

Kim Sang Hyouk
Associate II

​now Just can Read RDSR

  while(1){
    M95512_WRDI(); //Write Disable
    Error = M95512_RDSR();    
    delay_us(1);    
    M95512_WREN(); //Write Enable
    Error = M95512_RDSR();    
    delay_us(10);
  }

When I test .... Cand Read 0x00  0x00    and  0x02  0x02

But Can't Read

void Read_Door_Sens(void){
  unsigned char data;
 
  ADDRESS = 0x0000;
 
  EEPROM_CS_LOW();
  SPI_SendByte(READ);   //0x03
  SPI_SendByte((ADDRESS & 0xFF00) >> 8);
  SPI_SendByte(ADDRESS & 0xFF);
  data = SPI_SendByte(DUMMY);
  EEPROM_CS_HIGH();
 
  Door_Sens_Use = data;
}
 
void Write_Door_Sens(unsigned char data){
  ADDRESS = 0x0000;
//  M95512_WREN();
  EEPROM_CS_LOW();
  SPI_SendByte(WRITE);//0x02
  SPI_SendByte((ADDRESS & 0xFF00) >> 8);
  SPI_SendByte(ADDRESS & 0xFF);
  SPI_SendByte(data);
  EEPROM_CS_HIGH();
}

MOSI Signal Can work.

But MISO Signal Can't work.

0690X000006C0QaQAK.bmp