Page 1 of 1

How to use large SPI-EEprom with component macro?

Posted: Thu Jul 03, 2014 3:29 pm
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

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

Posted: Fri Jul 04, 2014 10:36 am
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.

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

Posted: Sun Jul 06, 2014 11:51 am
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

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

Posted: Thu Jul 10, 2014 4:55 pm
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 430 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.

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

Posted: Mon Jul 21, 2014 2:53 pm
by Niro
Dear Benj,

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

Best regards,
Niro

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

Posted: Thu Aug 28, 2014 2:55 pm
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

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

Posted: Fri Aug 29, 2014 4:20 pm
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