element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
FPGA
  • Technologies
  • More
FPGA
Blog Arty: talk to SPI EEPROM - part 2b: EEPROM Read
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join FPGA to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 26 Jun 2022 11:32 AM Date Created
  • Views 1516 views
  • Likes 8 likes
  • Comments 4 comments
  • summer of fpga
  • Spartan_Migration
Related
Recommended

Arty: talk to SPI EEPROM - part 2b: EEPROM Read

Jan Cumps
Jan Cumps
26 Jun 2022
Arty: talk to SPI EEPROM - part 2b: EEPROM Read

Follow up of 2a: EEPROM State Machine and Initialise. In this post, I read a value from an address in the EEPROM. The slide switches on the Arty define what address to read. The state machine from the previous post already reserved a state for this activity. I just have to implement it.

image

SPI READ conversation

The sentence takes 32 clock ticks:

  • CS low
  • send 8 bits read instruction 0000 0011
  • send 16 bits address
  • read the 8 bits that appear on SO
  • CS high

image
image source: 25LC256 datasheet

Implement read state in my eeprom state machine

This isn't very different from the init_noprot state in the previous post. Just 4 bytes instead of 2. The 16 bits address is all '0', except the 4 least significant bits. Those are the values set by the slide switches (see step 3 to 8 in the code).

        when read =>
          -- read command 8 bits
          if (step = 0) then -- write read command (0b00000011)
            bitbang_cs_n <= '0';
            step <= 1; -- next step
            data_out <= "00000011"; -- read command
            start <= '1';
          elsif (step = 1) then -- wait for ack from spi
            if (busy = '1') then  -- wait for spi buzy
              step <= 2;
            end if;
          elsif (step = 2) then -- finalise read command
            if not (busy = '1') then  -- wait until spi no longer buzy
              -- finished					 
              start <= '0';
              step <= 3; 
            end if;
          -- address 16 bits
          elsif (step = 3) then -- MSBs
              step <= 4; -- next step
              data_out <= "00000000"; -- address MSB
              start <= '1';
          elsif (step = 4) then -- wait for ack from spi
            if (busy = '1') then  -- wait for spi buzy
              step <= 5;
            end if;
          elsif (step = 5) then -- finalise address MSB
            if not (busy = '1') then  -- wait until spi no longer buzy
              -- finished					 
              start <= '0';
              step <= 6; 
            end if;
          elsif (step = 6) then -- LSBs
              step <= 7; -- next step
              data_out (3 downto 0) <= addr(3 downto 0); -- address LB
              start <= '1';
          elsif (step = 7) then -- wait for ack from spi
            if (busy = '1') then  -- wait for spi buzy
              step <= 8;
            end if;
          elsif (step = 8) then -- finalise address LSB
            if not (busy = '1') then  -- wait until spi no longer buzy
              -- finished					 
              start <= '0';
              step <= 9; 
            end if;
          -- read data
          elsif (step = 9) then -- read from address
              step <= 10; -- next step
              data_out <= "00000000"; -- address MSB
              start <= '1';
          elsif (step = 10) then -- wait for ack from spi
            if (busy = '1') then  -- wait for spi buzy
              step <= 11;
            end if;
          elsif (step = 11) then -- finalise read from address
            if not (busy = '1') then  -- wait until spi no longer buzy
              -- finished					 
              start <= '0';
              state <= accept;        
              step <= 0; 
              bitbang_cs_n <= '1';
            end if;
          end if;

Test

It works. The protocol analyser shows the init sequence from the previous post, then from row 10 on, the read sequence. The returned data is 0x00. The 16 bits address value is 0x0007. That's because I had set the slide switches to off -on-on-on. Confirmation that that part works too.
The EEPROM I use has never been written too (wait for the next post). I don't know if a new EEPROM has all values set to 0 fresh-from-factory, or if my design isn't correct yet. The next blog, where I'll write to the EEPROM, will learn ...

image

Side note: this project will not be easy on the eeprom. It has a limited number of write cycles per address, and I'm not going to implement a strategy to deal with that. The exercise is to see if I can get a non-trivial SPI conversation going.

  • Sign in to reply

Top Comments

  • Jan Cumps
    Jan Cumps over 3 years ago +1
    Success: The IC was defect. I tested it with an Arduino example , and that failed too. Putting in another IC fixed it. At that time, my code started to work too.
  • Jan Cumps
    Jan Cumps over 3 years ago

    Success:

    image

    The IC was defect. I tested it with an Arduino example, and that failed too. Putting in another IC fixed it.
    At that time, my code started to work too.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 3 years ago in reply to Jan Cumps

    current status: not working.

    • I run the init, and execute a read

    image

    Init enables write mode, and removes write protection. The read reads what's on address 0x07. No expectations yet

    • I write value 0x08 to address 0x07:

    image

    there's a 5 ms wait after write operation and CS goes up. Because writing is the last state of my state machine, this time is definitely guaranteed.
    image

    • then I reset the device. This initialises the IC again, then executes a read from address 0x07 (same scenario as in the first step). The SO line is expected to give the value I had written in the previous step (0x08), but it's not sending anything. I checked connections and wiring.

    image

    I'm not sure how to progress. maybe I'll program a microcontroller with a similar process, to see if the IC is OK. If I'm sure the protocol works, it 'll be easier to troubleshoot.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 3 years ago in reply to genebren

    The write logic shouldn't take me long to do. Identical to the read one, with a different command. Maybe after diner tonight ...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • genebren
    genebren over 3 years ago

    Interesting that the factory state of the memory is not specified.  I have seen some devices that are specified and others that are not.  Having been in a similar place, it is somewhat disconcerting not knowing if your read is working or not, until you complete the write logic and begin to modify the memory.

    Great work so far.  Keep up the good work!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube