Pages: [1]   Go Down
Author Topic: Uno + 23LC1024 SPI SRAM, yet another read error post  (Read 667 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have seen a couple of threads like this but so far I don't understand the problem so I'm hoping somebody can help me troubleshoot.  I'm following this article with an Uno breadboarded to a 23LC1024 SPI SRAM chip:
https://ucexperiment.wordpress.com/2013/02/26/more-memory-arduino-and-23lc1024/

This is my pinout:
Arduino -- 23LC1024 (PDIP pin)
D13 <------> SCK (6)
D12 <------> MISO (2)
D11 <------> MOSI (5)
D10 <------> CS (1)
5V  <------> VCC (8)
5V  <------> HOLD (7)
GND <------> VSS (4)

Notice I omitted the pullup resistor (5V  <-10KR-> CS) because 1) I don't have one at the moment, 2) he indicates in the comments that you don't need it unless you have multiple devices on the SPI bus. (As an aside, couldn't you just use the internal pullups?)

Anyway, I'm using the sketch on that page, modified only to print the number of times through the loop alongside the value, and I get this:
Code:
i: 0  read: 0
i: 1  read: 1
i: 2  read: 0
i: 3  read: 2
i: 4  read: 0
i: 5  read: 3
i: 6  read: 4
i: 7  read: 6
i: 8  read: 0
i: 9  read: 3
i: 10  read: 0
i: 11  read: 4
i: 12  read: 8
i: 13  read: 11
i: 14  read: 12
i: 15  read: 14
i: 16  read: 0
i: 17  read: 3
i: 18  read: 0
i: 19  read: 4
i: 20  read: 0
i: 21  read: 7
i: 22  read: 8
i: 23  read: 12
i: 24  read: 16
i: 25  read: 19
i: 26  read: 16
i: 27  read: 20
i: 28  read: 24
i: 29  read: 27
i: 30  read: 28
i: 31  read: 31


Though I've seen other posts or threads where users are having problems with read errors, I haven't been able to attribute it to anything. To troubleshoot, I tried another 23LC1024 and another SRAM library I found on github, with similar results. What gives? Any suggestions appreciated :D
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's worth noting that the incorrect values are the same on each run of the program...
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please post your sketch, mark it all in the post and hit the "#" button so it is shown as code. It's impossible to guess what's going wrong. The code could give some hints.
Logged

Norfolk UK
Offline Offline
Faraday Member
**
Karma: 70
Posts: 2575
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As you say your not the first to report problems with these chips but the two I have have worked flawlessly for me when connected into breadboard. Try slowing down the clock speed to see if the errors go away or maybe you need better decoupling.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some of those examples claim being for 23LC1024 but use 16 bit addressing - which results in weird to no results.
Make sure your address is uint32_t. Shift it out correctly, after sending WRITE / READ command to the ram first address >> 16, then address >>8 and then address.

But that is impossible to tell while there is no code to look at.
« Last Edit: March 27, 2014, 10:19:35 am by Koepi » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oops, I thought it was ok that the code was on that page I linked, here it is again:
Code:
/*
   Used the following components and wire routing:
   (1) Arduino Uno
   (2) Microchip 23LC1024
   (3) 10K Resistor
 */
#include <SPI.h>
 
//SRAM opcodes
#define RDSR        5
#define WRSR        1
#define READ        3
#define WRITE       2
 
//Byte transfer functions
uint8_t Spi23LC1024Read8(uint32_t address) {
  uint8_t read_byte;
 
  PORTB &= ~(1<<PORTB2);        //set SPI_SS low
  SPI.transfer(READ);
  SPI.transfer((uint8_t)(address >> 16) & 0xff);
  SPI.transfer((uint8_t)(address >> 8) & 0xff);
  SPI.transfer((uint8_t)address);
  read_byte = SPI.transfer(0x00);
  PORTB |= (1<<PORTB2);         //set SPI_SS high
  return read_byte;
}
 
void Spi23LC1024Write8(uint32_t address, uint8_t data_byte) {
  PORTB &= ~(1<<PORTB2);        //set SPI_SS low
  SPI.transfer(WRITE);
  SPI.transfer((uint8_t)(address >> 16) & 0xff);
  SPI.transfer((uint8_t)(address >> 8) & 0xff);
  SPI.transfer((uint8_t)address);
  SPI.transfer(data_byte);
  PORTB |= (1<<PORTB2);         //set SPI_SS high
}
 
void setup(void) {
  uint32_t i;
  uint8_t value;
 
  Serial.begin(9600);
  SPI.begin();
 
  for (i=0; i<32; i++) {
    Spi23LC1024Write8(i, (uint8_t)i);
    value = Spi23LC1024Read8(i);
    Serial.println((uint16_t)value);
  }
}
 
void loop() {
}

So the address argument appears to be uint32_t.  I'm not sure how to slow it down, would that be with the SPI library I guess?   I'll try to slow it down and report back, thanks smiley
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Try slowing down the clock speed to see if the errors go away or maybe you need better decoupling.

Riva, what do you mean by decoupling? Thanks.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok so I tried changing the SPI speed with SPI.setClockDivider(SPI_CLOCK_DIV4) and then tried the other speeds all the way down to 128 but they all yield the same results smiley-sad  Thanks for the suggestion though.
Logged

Norfolk UK
Offline Offline
Faraday Member
**
Karma: 70
Posts: 2575
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok so I tried changing the SPI speed with SPI.setClockDivider(SPI_CLOCK_DIV4) and then tried the other speeds all the way down to 128 but they all yield the same results smiley-sad  Thanks for the suggestion though.
Maybe try some different code http://forum.arduino.cc/index.php?topic=182918.0 though Grumpy Mike reported read errors with it and never said if the cause was found.
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, I installed your lib and ran the example sketch SpiRAM_Test, here were the results:
Code:
Ram Tests Begin.

Fill Memory with 0xFF.

0: FF FF FF FF FF FF FF FF FF FF
A: FF FF FF FF FF FF FF FF FF FF
14: FF FF FF FF FF FF FF FF FF FF
1E: FF FF FF FF FF FF FF FF FF FF
28: FF FF FF FF FF FF FF FF FF FF
32: FF FF FF FF FF FF FF FF FF FF
3C: FF FF FF FF FF FF FF FF FF FF
46: FF FF FF FF FF FF FF FF FF FF
50: FF FF FF FF FF FF FF FF FF FF
5A: FF FF FF FF FF FF FF FF FF FF

1FF9A: FF FF FF FF FF FF FF FF FF FF
1FFA4: FF FF FF FF FF FF FF FF FF FF
1FFAE: FF FF FF FF FF FF FF FF FF FF
1FFB8: FF FF FF FF FF FF FF FF FF FF
1FFC2: FF FF FF FF FF FF FF FF FF FF
1FFCC: FF FF FF FF FF FF FF FF FF FF
1FFD6: FF FF FF FF FF FF FF FF FF FF
1FFE0: FF FF FF FF FF FF FF FF FF FF
1FFEA: FF FF FF FF FF FF FF FF FF FF
1FFF4: FF FF FF FF FF FF FF FF FF FF

Fill Memory with 0xAA.

0: 0 0 0 0 0 0 0 0 0 C0
A: 0 0 0 0 0 0 0 C0 0 C0
14: 0 C0 0 0 0 C0 0 C0 0 C0
1E: 0 0 0 0 0 0 0 C0 0 0
28: 0 C0 0 C0 0 C0 0 C0 0 C0
32: 0 0 0 C0 0 0 0 0 0 C0
3C: 0 0 0 0 0 0 0 0 0 C0
46: 0 0 0 C0 0 C0 0 C0 0 0
50: 0 C0 0 C0 0 C0 0 C0 0 C0
5A: 0 C0 0 C0 0 C0 0 0 0 0

1FF9A: 0 C0 0 C0 0 0 0 C0 0 C0
1FFA4: 0 C0 0 C0 0 C0 0 C0 0 C0
1FFAE: 0 C0 0 C0 0 C0 0 C0 0 C0
1FFB8: 0 C0 0 C0 0 C0 0 0 0 0
1FFC2: 0 0 0 C0 0 0 0 C0 0 0
1FFCC: 0 C0 0 0 0 C0 0 0 0 C0
1FFD6: 0 C0 0 C0 0 C0 0 C0 0 0
1FFE0: 0 0 0 0 0 C0 0 0 0 C0
1FFEA: 0 C0 0 C0 0 0 0 0 0 0
1FFF4: 0 C0 0 0 0 0 0 0 0 0

Fill Memory with Buffer.

0: 3 0 4 0 7 8 C 0 7 0
A: 3 0 4 0 7 8 C 0 7 0
14: 3 0 4 0 7 8 C 0 7 0
1E: 3 0 4 0 7 8 C 0 7 0
28: 3 0 4 0 7 8 C 0 7 0
32: 3 0 4 0 7 8 C 0 7 0
3C: 3 0 4 0 7 8 C 0 7 0
46: 3 0 4 0 7 8 C 0 7 0
50: 3 0 4 0 7 8 C 0 7 0
5A: 3 0 4 0 7 8 C 0 7 0

1FF9A: 3 0 4 0 7 8 C 0 7 0
1FFA4: 3 0 4 0 7 8 C 0 7 0
1FFAE: 3 0 4 0 7 8 C 0 7 0
1FFB8: 3 0 4 0 7 8 C 0 7 0
1FFC2: 3 0 4 0 7 8 C 0 7 0
1FFCC: 3 0 4 0 7 8 C 0 7 0
1FFD6: 3 0 4 0 7 8 C 0 7 0
1FFE0: 3 0 4 0 7 8 C 0 7 0
1FFEA: 3 0 4 0 7 8 C 0 7 0
1FFF4: 3 0 4 0 7 8 C 0 7 0

Read Buffer.
ü
0þ

Write byte.

0: 0 0 0 0 0 0 0 0 0 0
A: 1 1 1 1 1 1 1 1 1 1
14: 0 0 0 0 0 0 0 0 0 0
1E: 2 2 2 2 2 2 2 2 2 2
28: 0 0 0 0 0 0 0 0 0 0
32: 3 3 3 3 3 3 3 3 3 3
3C: 4 4 4 4 4 4 4 4 4 4
46: 6 6 6 6 6 6 6 6 6 6
50: 0 0 0 0 0 0 0 0 0 0
5A: 3 3 3 3 3 3 3 3 3 3

1FF9A: E E E E E E 0 0 0 0
1FFA4: 0 0 0 0 0 0 3 3 3 3
1FFAE: 3 3 3 3 3 3 0 0 0 0
1FFB8: 0 0 0 0 0 0 4 4 4 4
1FFC2: 4 4 4 4 4 4 0 0 0 0
1FFCC: 0 0 0 0 0 0 7 7 7 7
1FFD6: 7 7 7 7 7 7 8 8 8 8
1FFE0: 8 8 8 8 8 8 C C C C
1FFEA: C C C C C C 10 10 10 10
1FFF4: 10 10 10 10 10 10 13 13 13 13

Ram Tests Finished.

Isn't that bizarre? I have used five different chips and 3 different libs, must it be something with my circuit?   Time to bust out the multimeter...
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try the address shift out this way, I'm not sure why it is bit-masked in your sketch:

Code:
 SPI.transfer((byte)(address >> 16));
  SPI.transfer((byte)(address >> 8));
  SPI.transfer((byte)address);

Else if the pins are correctly connected to the Arduino, it should work.

Code:
// Chip UNO MEGA  NAME
//  1   10  53     SS    (Hardware SS Pin (10 [Uno] or 53[Mega]) needs to remain output no matter what other pin you may for SS)
//  2   12  50    MISO
//  3   NC  NC
//  4   GND GND   Vss
//  5   11  51    MOSI
//  6   13  52    SCK
//  7   +5V +5V   ~HOLD
//  8   +5V +5V   Vcc

Edit: Did you setup SPI correctly? Most Significant Bit First, ...
Maybe try different, shorter wires. 8 MHz are already a bit fast and can lead to problems with "old used" and long cables.
« Last Edit: March 27, 2014, 12:34:48 pm by Koepi » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ugggggggh I just got my friend to solder a chip up to a Pro Mini and the sketches work just fine.  I guess this is just breadboard crappiness. I've definitely used these breadboards for many projects recently, including SD communication, but maybe if you're testing this RAM you're better off making solder connections.

Thanks to everybody for the help smiley-grin
Logged

Pages: [1]   Go Up
Jump to: