How to use large SPI-EEprom with component macro?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
Niro
Posts: 77
Joined: Mon Jan 03, 2011 8:58 pm
Has thanked: 29 times
Been thanked: 10 times
Contact:

How to use large SPI-EEprom with component macro?

Post by Niro »

Hi guys,

I have a large SPI-EEprom for logging data and I'm trying to get it work with an ATmega328P with FC5.
The EEprom is a Microchip 25AA1024, I think that's 1024 kbits (x8) = 1.024.000 byte.
The component macro command NVM_Send_Char has only hi and lo_addr, but I think I need to have at least 3 byte for addressing the complete eeprom.

I'm totally new at using SPI- components, so maybe someone could help.

Many thanks!
Niro

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: How to use large SPI-EEprom with component macro?

Post by Benj »

Hello Niro,

1024Kbit = 128KByte.

The NVM functions are specifically for the NVM used on the EB013 SPI E-block.

To access this chip you will have to toggle the CS line manually using an output icon in pin mode and follow the protocol laid out by the device datasheet using the SPI send and receive component macros.

If you get stuck then post what you have so far and we will try and help.

Note that AVRs have an issue with the hardware SPI and the SS pin (pin B2 on the ATmega328P). Be sure to either use this as your CS pin or to at least set it as an output before initialising the hardware SPI component. If the pin is allowed to float as an input then it has the potential to lock the SPI peripheral and therefore the processor.

Niro
Posts: 77
Joined: Mon Jan 03, 2011 8:58 pm
Has thanked: 29 times
Been thanked: 10 times
Contact:

Re: How to use large SPI-EEprom with component macro?

Post by Niro »

Dear Benj,

many thanks for your response!
Of course you are right, this is a 128k eeprom.
As I'm not very familiar with the FC AVR C-Compiler and C-programming I'ver been looking for simple examples.
I found this page: http://jaxcoder.com/Projects.aspx?id=1597727146
Could you please have a look, and tell me if this is usable for FC5 and my eeprom (25AA1024, programming sequence attached).
Especially what about #include "eeprom.h" . Is this already included or do I have to add something to my flowcode project (...supplemantary code?).

Many thanks for your help!
Niro
Attachments
25AA1024_ProgramminsSequences.jpg
25AA1024_ProgramminsSequences.jpg (30.9 KiB) Viewed 6729 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: How to use large SPI-EEprom with component macro?

Post by Benj »

Hello,

Here is a v5 for AVR example with macros to read and write data to the EEPROM, no external files or supp code is required.
25AA1024.fcf_avr
(15 KiB) Downloaded 359 times
If you have problems then you might need a small delay at the end of the WriteByte macro, 1ms might do it but the datasheet should say what size of delay is needed.

Niro
Posts: 77
Joined: Mon Jan 03, 2011 8:58 pm
Has thanked: 29 times
Been thanked: 10 times
Contact:

Re: How to use large SPI-EEprom with component macro?

Post by Niro »

Dear Benj,

many many thanks!! This is really a big help!!

Best regards,
Niro

Niro
Posts: 77
Joined: Mon Jan 03, 2011 8:58 pm
Has thanked: 29 times
Been thanked: 10 times
Contact:

Re: How to use large SPI-EEprom with component macro?

Post by Niro »

Dear Ben,

just now I got ready with my hardware an tried your example. Unfortunately Flowcode gave me an error not having the 'DAC enable Pin' and the 'NVM enable Pin' connected.
Having a look at your code it seems you manage the CS (SS, PB2) pin by yourself and not get it handled by the FC SPI component macro.
If I skip the connection error from FC having both pins not connected, now the compiler stops with some declaration errors of the SPI component macro.
Connecting both pins to some not used pins of the controller, I could avoid the compiler error, but it doesn't work either.
Now starting the read or write command of your example the controller alway hangs up and could only get started again with a hardware reset.

Could you please give me some help to get it work?

Many thanks!
Niro

Niro
Posts: 77
Joined: Mon Jan 03, 2011 8:58 pm
Has thanked: 29 times
Been thanked: 10 times
Contact:

Re: How to use large SPI-EEprom with component macro?

Post by Niro »

Hi to all

Now it's working!!
This is how it could be done:

1. connect the 'DAC enable Pin' and the 'NVM enable Pin' of the SPI component in the panel to the same pin your CS/SS pin is located ( ATMEGA328: Pin14 : SS /PB29)
2. don't forget to initialize the SPI at the beginning of your code -> Component macro: SPI_Init() (...that was my biggest fault)
3. for writing to the EEPROM you always first need to set the write enable latch with a special command (in this case: 6)
4. now write your address and data
5. after this you should reset the write enable latch (my command: 4)
6. at last you need to add a delay between two write cycles depending aon your EEPROM (in my case the Twc = Internal Write Cycle Time >= 6ms )

Attached you'll see the complete procedure.
Hope this will save time to all others...

Best regards,
Niro
Attachments
SPI_WriteProcess01.jpg
(42.48 KiB) Downloaded 1558 times

Post Reply