element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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
Experts, Learning and Guidance
  • Technologies
  • More
Experts, Learning and Guidance
Ask an Expert Forum SRAM and Arduino
  • Blog
  • Forum
  • Documents
  • Leaderboard
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Experts, Learning and Guidance to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 2 replies
  • Subscribers 278 subscribers
  • Views 680 views
  • Users 0 members are here
  • arduino uno
  • sram
Related
See a helpful answer?

Be sure to click 'more' and select 'suggest as answer'!

If you're the thread creator, be sure to click 'more' then 'Verify as Answer'!

SRAM and Arduino

splatkillwill
splatkillwill over 4 years ago

I'm trying to interact with SRAM (MB8416A-15) with my Arduino.

This is my schematic:


And my code:image

#define WRITE 14
#define RAM_G 15
#define ENABLE 16


void write(uint8_t address, uint8_t data) {
  DDRD = B11111111;
  PORTB = address;
  digitalWrite(WRITE, LOW);
  digitalWrite(ENABLE, LOW);
  PORTD = data;
  delayMicroseconds(1);
  digitalWrite(ENABLE, HIGH);
  digitalWrite(WRITE, HIGH);
}


uint8_t read(uint8_t address) {
  uint8_t data;
  DDRD = B00000000;
  PORTB = address;
  digitalWrite(WRITE, HIGH);
  digitalWrite(ENABLE, LOW);
  delayMicroseconds(1);
  data = PORTD;
  digitalWrite(ENABLE, HIGH);
  digitalWrite(WRITE, HIGH);
  return data;
}


void setup() {


  // init


  Serial.begin(9600);


  // control
  pinMode(WRITE, OUTPUT);
  pinMode(RAM_G, OUTPUT);
  pinMode(ENABLE, OUTPUT);
  digitalWrite(WRITE, HIGH);
  digitalWrite(RAM_G, LOW);
  digitalWrite(ENABLE, HIGH);
  // address
  DDRB  = DDRB  | B00111111;
  PORTB = B00000000;
  // data
  DDRD = B00000000;


  // test


  write(B00000000, 10);
  Serial.println(read(B00000000));
  
  write(B00000001, 20);
  Serial.println(read(B00000000));
  Serial.println(read(B00000001));
  
  write(B00000010, 30);
  Serial.println(read(B00000000));
  Serial.println(read(B00000001));
  Serial.println(read(B00000010));
  
  write(B00000010, 40);
  Serial.println(read(B00000000));
  Serial.println(read(B00000001));
  Serial.println(read(B00000010));
  Serial.println(read(B00000011));


}

 

I'd expect an output of

10
10
20
10
20
30
10
20
30
40

 

but I get

10
20
20
30
30
30
40
40
40
40

  • Sign in to reply
  • Cancel

Top Replies

  • ajcc
    ajcc over 4 years ago +3
    There are three issues I see with your circuit and code: 1) The input data is in the PIND register , you're just reading back what you wrote to the PORTD output register (this is why your last output is…
  • ralphjy
    ralphjy over 4 years ago +1
    From the output that you get it appears that your address isn't working so that you are always writing and reading the same address. You should probably just do a static check to see if you are actually…
  • ralphjy
    ralphjy over 4 years ago

    From the output that you get it appears that your address isn't working so that you are always writing and reading the same address.  You should probably just do a static check to see if you are actually writing the correct address values.  Seems like you have lots of setup time and you can write and read data.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • ajcc
    ajcc over 4 years ago

    There are three issues I see with your circuit and code:

    1) The input data is in the PIND register, you're just reading back what you wrote to the PORTD output register (this is why your last output is repeating).

    2) When you set the pins to be inputs the data register (PORTD) will be controlling the internal pull-up resistors (I didn't find a good Arduino page on this, but the behavior is described in the Atmega328p datasheet), so you have to write all zeros to PORTD before reading PIND.

    3) You're using PORTD for the databus while also using the serial ports (for monitoring your program), which is using two of the pins for RX and TX. You can't have both at the same time. When the serial port is enabled those two pins are no longer connected to the PORTD register.

     

    I'd suggest that you write a nibble (4-bits) to the SRAM and see if that works first, you can safely use the upper half of PORTD. You can also write to the SRAM in slow motion as ralphjy is suggesting. I'd probably go further and hook up LEDs to really see that the pins are actually doing what I'm expecting them too.

     

    For future improvements: If you're just reading the SRAM sequentially you can use a counter IC for the address lines.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • 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