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 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 02:52 AM
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:
Have you used an oscilloscope or logic analyser to see what's actually happening on the wires?
2025-02-19 03:55 AM
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.
2025-02-19 04:17 AM
Thank you for your reply.
Here is the diagram:
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.
2025-02-19 04:35 AM
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.
2025-02-19 04:53 AM - edited 2025-02-19 04:56 AM
Start by checking your SPI CLK frequency according the the max clock mentioned in the memory datasheet:
+ 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?
2025-02-19 04:56 AM
Sorry about the images.
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.
2025-02-19 04:59 AM
@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!
2025-02-19 06:01 AM
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.
2025-02-19 06:04 AM
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...).
Here is image from oscillator, which the above signal is DO (0V), and the below signal is DI, as before image, it sends 0b11000000.