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.

16 REPLIES 16

I think you mean oscilloscope - not oscillator?

Doesn't your 'scope have a means to capture screenshots?

 

As @mƎALLEm said earlier, have you checked this against the EEPROM specs - particular for frequency & SPI Mode?

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

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

Do you make fun of me? Just forget my post. 

Very bad support. 

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

 

mƎALLEm
ST Employee

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 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 @bmckenney 

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