cancel
Showing results for 
Search instead for 
Did you mean: 

how to read/write eeprom microwire 93c66

No_Name
Associate III

Hi all.
I want to do read/write on eeprom microwire 93c66 but there is no open source HAL library that I can find. how can I do it? I am new to stm32.

Thanks

8 REPLIES 8
AScha.3
Super User

Hi,

>how can I do it?

As with every other cpu ...

- read ds of 93c66

- decide, how you want to do it, SPI, bit bang, ...

- or use a chip with standard  I2C interface and connect to the I2C (and the HAL lib)

If you feel a post has answered your question, please click "Accept as Solution".
Pavel A.
Super User

Here you can find help with this part.

I don't really understand how to read the datasheet and apply it like a timing diagram, because I was previously in arduino which is mostly an open source library.


@No_Name wrote:

I don't really understand how to read the datasheet and apply it like a timing diagram,


That is a basic skill - nothing specific to STM32.

As @Pavel A. suggests, if you don't have the time or inclination to do it yourself, then you'll need to pay someone to do it for you.

 


@No_Name wrote:

because I was previously in arduino which is mostly an open source library.


That's the downside of relying on 3rd-party libraries - you're stuck until someone else provides a library!

If you're relying on the availability of 3rd-party libraries, then you have to just confine yourself to parts for which libraries are available. 

 

As you say, the Arduino libraries are open-source - so you could get the source, and port that to your STM32.

 

Or, perhaps, load STM32Duino onto your STM32:

https://www.stm32duino.com/

https://github.com/stm32duino

https://docs.arduino.cc/libraries/stm32duino-examples/ 

 


@No_Name wrote:

 I am new to stm32.


Start here:

https://community.st.com/t5/stm32-mcus-products/for-better-learning-stm32-programming-and-debugging/m-p/719485/highlight/true#M260696

https://community.st.com/t5/stm32-mcus-products/for-better-learning-stm32-programming-and-debugging/m-p/719468/highlight/true#M260690

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.

@Andrew Neil wrote:

@No_Name wrote:

I don't really understand how to read the datasheet and apply it like a timing diagram,


That is a basic skill


Where can I learn to read the datasheet properly? Is there a source for that?

Enrol on an electronics course?

 

https://www.egr.msu.edu/classes/ece480/capstone/read_datasheet.pdf

https://www.digikey.com/en/maker/tutorials/2024/how-to-read-and-understand-technical-datasheets

and many more via: https://www.google.com/search?q=how+to+read+a+datasheet

(other search engines are available)

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.
bmckenney
Associate III

Microwire is a "cousin" to SPI, but it's rather different. Its main advantage is that -- while billed as a 4-wire protocol -- it's designed such that it can run over a 3-wire (shared MISO/MOSI) bus.

I'm not aware of any STM32 that supports Microwire, and I didn't see any tricks to make the SPI talk to this device. If your requirement is to use this particular device I expect you'll have to bit-bang it based on datasheet (Microchip document DS21795B) Tables 1-3/4 and Figures 2-7/8. 

----

ST sells a few Microwire EEPROMs (https://www.st.com/en/memories/standard-microwire-eeprom/documentation.html), but I don't see any sample code.

----

"Five minutes with Google" turned up this, though I suspect you'll have to add the GPIO part (I suppose it's in asm/ic/ssi.h):

https://github.com/themadinventor/u-boot-stm32/blob/master/drivers/mtd/mw_eeprom.c

Microwire implementations can vary quite a bit, so you should check the code against the datasheet Tables.

stevef
Associate

The 93C66 will accept any number of leading zeros before the start bit, so pad with 4 zeros then the SPI can send 16 bits for the 12 bit writes and 24 bits for the 20 bit reads.  For the writes the phase is 1EDGE and for reads the SPI phase is 2EDGE.  The read code must send the command and address bytes, change the phase, the read the data byte.  Looks like this: 

 

txdata[0] = CMD_READ | (addr + i) >> 8;

txdata[1] = (addr + i) & 0xFF; // address to read

txdata[2] = 0xFF; // dummy byte for read

HAL_GPIO_WritePin(EE_CS_GPIO_Port, EE_CS_Pin, GPIO_PIN_SET); // chip select

// don't care about the rx bytes

HAL_SPI_TransmitReceive(&hspi2, &txdata[0], &rxdata[0], 2, 100);

// need to change the edge to read correctly....

SPI2_Init(SPI_PHASE_2EDGE);

// address is set, now read the byte into rxdata[2]

HAL_SPI_TransmitReceive(&hspi2, &txdata[2], &rxdata[2], 1, 100);

HAL_GPIO_WritePin(EE_CS_GPIO_Port, EE_CS_Pin, GPIO_PIN_RESET); // chip select off

SPI2_Init(SPI_PHASE_1EDGE); // reset SPI for next read

 

void SPI2_Init(uint32_t phase)

{

/* SPI2 parameter configuration*/

hspi2.Instance = SPI2;

hspi2.Init.Mode = SPI_MODE_MASTER;

hspi2.Init.Direction = SPI_DIRECTION_2LINES;

hspi2.Init.DataSize = SPI_DATASIZE_8BIT;

hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;

hspi2.Init.CLKPhase = phase;

hspi2.Init.NSS = SPI_NSS_SOFT;

hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;

hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;

hspi2.Init.TIMode = SPI_TIMODE_DISABLE;

hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;

hspi2.Init.CRCPolynomial = 7;

hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;

hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;

HAL_SPI_Init(&hspi2);

}