Skip to main content
Associate
February 19, 2025
Solved

EEPROM SPI Reading issue

  • February 19, 2025
  • 17 replies
  • 2567 views

Hello, 

I am trying to write and read from stm32f105 to an eeprom 93AA46A, using Full-Duplex Master. 

To write into the eeprom, I am using following code:

void EEPROM_WriteEnable(void)
{
 uint8_t cmd = EEPROM_CMD_WRITE_ENABLE; //0x98

 EEPROM_CS_HIGH();
 HAL_Delay(1);

 HAL_SPI_Transmit(&hspi1, &cmd, 1, HAL_MAX_DELAY);

 EEPROM_CS_LOW();
}
void EEPROM_WriteByte(uint8_t address, uint8_t data)
{
 uint8_t txData[3];
 // Enable Write Operation
 EEPROM_WriteEnable();

 // Prepare Write Command (101xxxxx | 6-bit address)
	txData[0] = EEPROM_CMD_WRITE; //0xA0
	txData[1] = 0x00; //address
	txData[2] = 0x55; // Data

	// Send Write Command
	EEPROM_CS_HIGH();
	HAL_Delay(1);

	HAL_SPI_Transmit(&hspi1, txData, 3, HAL_MAX_DELAY);

	EEPROM_CS_LOW();
}

 

and to read from EEPROM, I have follwoing code:

void EEPROM_ReadByte(uint8_t address)
{
uint8_t txData_read[3];
uint8_t rxData = 0;

	txData_read[0] = EEPROM_CMD_READ; //0xC0
	txData_read[1] = 0x00; //address
	txData_read[2] = 0x01; // dummy

 EEPROM_CS_HIGH();
 HAL_Delay(1);
 HAL_SPI_Transmit(&hspi1, txData_read, 3, HAL_MAX_DELAY);

 HAL_SPI_Receive(&hspi1, rxData, 1, HAL_MAX_DELAY);

 EEPROM_CS_LOW();
}

 

I don't get anything from eeprom, the HAL_SPI_Receive doesn't make anything. Is there anyone that can verify that the code is correct?

Thank you.

This topic has been closed for replies.
Best answer by bmckenney

The datasheet I see for the 93AA46A says it's a Microwire device. Microwire is kind of a first-cousin to SPI.

In particular, the request [Ref Table 1-4] is 10 bits, not 8: {1-bit Start, 2-bits Op-code, 7-bits Address}. The Read/Write data is in units of 8-bits. Microwire has no objection to this, but the STM32F105 [Ref RM0008] only supports 8/16-bits, and I don't think I've seen an STM32 where the Rx and Tx frame sizes can be different. (RM0008 also doesn't mention Microwire.)

You may want to consider bit-banging. (There are only 128 bytes, so speed probably isn't a big deal.)

Also: In

> HAL_SPI_Receive(&hspi1, rxData, 1, HAL_MAX_DELAY);

 I expect you meant

> HAL_SPI_Receive(&hspi1, &rxData, 1, HAL_MAX_DELAY);

I'm a bit surprised the compiler didn't object.

[Edit: Fixed some minor specifics. The principle is the same.]

 

17 replies

Andrew Neil
Super User
February 19, 2025

Welcome to the forums.

 


@Siva21 wrote:

I am trying to write and read from stm32f105 to an eeprom 93AA46A


Please give full details of your hardware - see: 

How to write your question to maximize your chances to find a solution.

 

Use  HAL_SPI_TransmitReceive()rather than separate transmit & receive:

https://community.st.com/t5/stm32-mcus-products/what-is-hal-spi-transmitreceive-purpose-and-how-it-works/td-p/337551

 

Have you used an oscilloscope or logic analyser to see what's actually happening on the wires?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Siva21Author
Associate
February 19, 2025

Thank you for your reply. 

Here is the diagram:

eeprom.pngstm32.png

The supply voltage is wrong and it is 3.3V. 

I have also tried without pull-up resistor. 

I do have an oscilloscope, and the DO trigger from low to high, when HAL_SPI_Receive or HAL_SPI_TransmitReceive are called. 

Andrew Neil
Super User
February 19, 2025

Sorry, those images are too low resolution to read.

Are the EEPROM & STM32 on the same board? Is it a custom board? Or what?

SPI shouldn't need pullups - the lines should be actively driven both high & low.

 


@Siva21 wrote:

I do have an oscilloscope, and the DO trigger from low to high, when HAL_SPI_Receive or HAL_SPI_TransmitReceive are called. 


and what else happens? It's a 4-wire interface!

As @mƎALLEm said, check your scope traces against the specifications in the EEPROM's datasheet.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
mƎALLEm
ST Technical Moderator
February 19, 2025

Hello,

93AA46 is a Microchip EEPROM.

Need to read the datasheet especially the electrical characteristics: SPI frequency, Clock polarity etc .. and configure the SPI accordingly. You need also to probe MOSI/MISO/CLK to debug and understand what is going on to know which part of the communication is not working correctly.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
mƎALLEm
ST Technical Moderator
February 19, 2025

Start by checking your SPI CLK frequency according the the max clock mentioned in the memory datasheet:

SofLit_0-1739969557047.png

+ You're using F1 family. Some IOs are not Five volt Tolerant (FT). As your memory is powered by 5V, are you sure your are not connecting EEPROM_DO output to one of the non-FT IOs?

 

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
Siva21Author
Associate
February 19, 2025

The eeprom is powered by 3.3V now. It was a mistake which it is fixed now. 

mƎALLEm
ST Technical Moderator
February 19, 2025

You still not answered the question: what is the GPIO used for EEPROM DO? If it was not FT it could be damaged.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
bmckenneyBest answer
Explorer II
February 19, 2025

The datasheet I see for the 93AA46A says it's a Microwire device. Microwire is kind of a first-cousin to SPI.

In particular, the request [Ref Table 1-4] is 10 bits, not 8: {1-bit Start, 2-bits Op-code, 7-bits Address}. The Read/Write data is in units of 8-bits. Microwire has no objection to this, but the STM32F105 [Ref RM0008] only supports 8/16-bits, and I don't think I've seen an STM32 where the Rx and Tx frame sizes can be different. (RM0008 also doesn't mention Microwire.)

You may want to consider bit-banging. (There are only 128 bytes, so speed probably isn't a big deal.)

Also: In

> HAL_SPI_Receive(&hspi1, rxData, 1, HAL_MAX_DELAY);

 I expect you meant

> HAL_SPI_Receive(&hspi1, &rxData, 1, HAL_MAX_DELAY);

I'm a bit surprised the compiler didn't object.

[Edit: Fixed some minor specifics. The principle is the same.]

 

Siva21Author
Associate
February 20, 2025

Thank you @bmckenney 

I have implemented bit-banging for SPI, and it works fine now. 

Andrew Neil
Super User
February 24, 2025

@Siva21 wrote:

I have implemented bit-banging for SPI (sic) 


But @bmckenney's point was that it's not SPI - it's Microwire:

AndrewNeil_0-1740388544059.pngAndrewNeil_1-1740388633571.png

 

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
mƎALLEm
ST Technical Moderator
February 19, 2025

Unfortunately and according to your schematics, EEPROM DO is connected to PA6 which is not FT IO:

SofLit_0-1739977328993.png

Most probably it was broken while you powered your EEPROM with 5V!

 

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.