cancel
Showing results for 
Search instead for 
Did you mean: 

EEPROM SPI Reading issue

Siva21
Associate

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.

1 ACCEPTED SOLUTION

Accepted Solutions
bmckenney
Associate

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.]

 

View solution in original post

16 REPLIES 16

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?

mƎALLEm
ST Employee

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 on "Accept as Solution" on the reply which solved your issue or answered your question.
PS:
1 - This is NOT an online support (https://ols.st.com) but a collaborative space.
2 - Please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help.

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. 

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.

mƎALLEm
ST Employee

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 on "Accept as Solution" on the reply which solved your issue or answered your question.
PS:
1 - This is NOT an online support (https://ols.st.com) but a collaborative space.
2 - Please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help.

Sorry about the images. 

eeprom.pngstm32.png

This is a custom board, eeprom and mcu on the same pcb. In my PCB, all pull-up resistors are removed, and eeprom is powered with 3.3V. At the first try, I powered the eeprom with 5V, and I don't know if the SPI pins are defected or not. But as I can see activity on MOSI line, I suppose the spi pins are ok. 

 

 


@Siva21 wrote:

At the first try, I powered the eeprom with 5V, 


You can't do that if you didn't check whether the EEPROM_DO is FT!

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
PS:
1 - This is NOT an online support (https://ols.st.com) but a collaborative space.
2 - Please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help.

Thanks for the legible images.

 


@Siva21 wrote:

all pull-up resistors are removed, and eeprom is powered with 3.3V.


You could have corrected that before posting the image!

 


@Siva21 wrote:

At the first try, I powered the eeprom with 5V, and I don't know if the SPI pins are defected


They might have been damaged.

Again, you need to use your oscilloscope to see what's happening on all four lines.

Thank you,

I have changed the MCU, didn't help. 

Here is results from oscillator when I use HAL_SPI_TransmitReceive to read from EEPROM.

The above signal is the clock, and below signal is DI, which it is 0b11000000 (from eeprom datasheet, to read from eeprom, has to be send 1100xx...). 

DI_CKL.jpeg

Here is image from oscillator, which the above signal is DO (0V), and the below signal is DI, as before image, it sends 0b11000000.

DO_DI.jpeg