cancel
Showing results for 
Search instead for 
Did you mean: 

STM32g070 wrong data reading EEPROM on W25Q128FV

Jw.1
Associate II

Hi, I am trying to read the contents of the EEPROM on this W25Q128FVIQ. I am using SPI.

The data read looked wrong to me, and the Manufacture ID I am getting out of it is wrong. I am getting 0xDC instead of 0xEF.

I tried reading and writing data with a 4KB Microchip 25AA040A and that seemed to work fine. I wrote in 0xAB 0xCD and 0xEF and read it out successfully.

Test4 is the one for reading the Manufacture ID on the Winbond chip.

Also when I send it an address(not required for reading the Manufacture ID), I believe the chip is expecting it in Big Endian, so I believe I have to reverse the byte order of the address correct?

But again, test4(marked in the code) is the one I am most concerned with right now.

I should be reading 0xEF, but I get 0xDC

if(test == 4) { //read jedec id, test4
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
      HAL_Delay(10);
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
      HAL_SPI_Transmit(&hspi1, (uint8_t *)&EEPROM_RJEDEC, 1, 100);
      HAL_SPI_Receive(&hspi1, (uint8_t *)uart_buf, 3, 100);
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
      for(int i = 0; i <3; i++)
      printf("JEDEC MFR ID is %X\n", uart_buf[i]);
    }

SPI cubemx code:

static void MX_SPI1_Init(void)
{
 
  /* USER CODE BEGIN SPI1_Init 0 */
 
  /* USER CODE END SPI1_Init 0 */
 
  /* USER CODE BEGIN SPI1_Init 1 */
 
  /* USER CODE END SPI1_Init 1 */
  /* SPI1 parameter configuration*/
  hspi1.Instance = SPI1;
  hspi1.Init.Mode = SPI_MODE_MASTER;
  hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  hspi1.Init.NSS = SPI_NSS_SOFT;
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi1.Init.CRCPolynomial = 7;
  hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
  hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
  if (HAL_SPI_Init(&hspi1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN SPI1_Init 2 */
 
  /* USER CODE END SPI1_Init 2 */
 
}
const uint8_t EEPROM_READ = 0x03;
const uint8_t EEPROM_WRITE = 0x02;
const uint8_t EEPROM_WRDI = 0x04;
const uint8_t EEPROM_WREN = 0x06;
const uint8_t EEPROM_RDSR = 0x05;
const uint8_t EEPROM_RDSR2 = 0x35;
const uint8_t EEPROM_RDSR3 = 0x15;
const uint8_t EEPROM_WRSR = 0x01;
const uint8_t EEPROM_RMFR = 0x90;
const uint8_t EEPROM_RJEDEC = 0x9F;
 
Constants

I am using jumper wire on a bread board, but the results are always consistent, so I don't think it is a wiring problem?

Here is the data sheet for the chip https://www.winbond.com/resource-files/w25q128fv rev.m 05132016 kms.pdf 

Thanks

3 REPLIES 3
Jw.1
Associate II

Wait what?

I disconnected the 3.3V line and replugged it in from the nucleo board and got 0xEE instead of 0xDC

Thinking it is a wiring problem I tried shortening cables/replugging in cables.

Still getting 0xEE

I disconnect the 3.3V line from the Nucleo board and now I am getting the right info...? Where is the Winbond chip getting power from?

The 3 bytes returned are:

0xEF

0x40

0x18

This is consistent, what's going on? There is no 3.3V from the board connected to the Winbond, and these results are the same. If I disconnect the chip I get 0xFF for all 3 values as expected.

PA8 is D7 on the Nucleo (This is chip select)

PA9 is D8 on the Nucleo (This is write enable)

MISO, MOSI, etc are where you would expect.

0693W000008G3MnQAK.png 

0693W000008G3MsQAK.pngThe 3.3V is disconnected

0693W000008G3MxQAK.png 

I'd probably use the HAL_SPI_TransmitReceive() form.

Probably would have CS high at initialization, and perhaps dwell as it goes low.

The device does have an async reset, might want to check pin 7

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Jw.1
Associate II

Thanks for the idea. I tried TransmitReceive and got the same values unfortunately.

I made a new GPIO for PB14 and am using this as the reset now. I set it low for 50ms, and then high, and then ran my code with no difference.

I think there is an electrical problem going. I am reading 2.7V on VCC (pin 😎 without the 3.3V line connected from the Nucleo board. However if I use the 4KB chip, I only get .5V on VCC which is what I would expect (or 0 ideally).

I am not sure why there is voltage there. I have to basically disconnect almost every wire for it to read 0V.

With VCC disconnected, the Winbond chip seems to be giving me the correct values.