2025-02-19 02:24 AM
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.
Solved! Go to Solution.
2025-02-19 06:27 AM
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?
2025-02-19 06:29 AM
The eeprom is powered by 3.3V now. It was a mistake which it is fixed now.
2025-02-19 06:55 AM
You still not answered the question: what is the GPIO used for EEPROM DO? If it was not FT it could be damaged.
2025-02-19 07:01 AM
Do you make fun of me? Just forget my post.
Very bad support.
2025-02-19 07:01 AM - edited 2025-02-19 07:23 AM
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.]
2025-02-19 07:03 AM
Unfortunately and according to your schematics, EEPROM DO is connected to PA6 which is not FT IO:
Most probably it was broken while you powered your EEPROM with 5V!
2025-02-20 02:00 AM
Thank you @bmckenney
I have implemented bit-banging for SPI, and it works fine now.