Pages: [1] 2   Go Down
Author Topic: spi 9bit eeprom address can only see addr 0x00?  (Read 1043 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

greetings all,
im having trouble getting this eeprom to work correctly - x5045 http://www.intersil.com/content/dam/Intersil/documents/fn81/fn8126.pdf - it takes a 9 bit address i think "datasheet - page 8, table 1 instruction set. i was able to write a value to addr 0 and read it, but thats the only address i can see, i used the following sketch because of the 9 bits, but this is the only way it works for that one address, cant see any others, obviously i have no idea what im doing wrong, any advice please?



Code:
#include <SPI.h>
#define WRITE 2
#define READ  3
#define WREN  6
#define RDSR  5
#define WRSR  1



unsigned int address = 0x00;
byte outval = 243;
byte invalue;

void setup(){
  Serial.begin(9600);


 
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV4); // max clock is 20MHz, so can set high speed
  SPI.begin(); // sets up pin modes etc.
  // Enable writing

  digitalWrite(SS, LOW);
  SPI.transfer(WREN);
  digitalWrite(SS, HIGH);
 
  digitalWrite(SS, LOW);
  SPI.transfer(READ); // read instruction

  SPI.transfer(address >> 16) ;
  SPI.transfer(address >> 8 );
  SPI.transfer(address );
  invalue = SPI.transfer(0);        // Clock out the data
  digitalWrite(SS, HIGH);
  Serial.print(F("Read Data = "));
  Serial.println(invalue,DEC);

}

void loop(){}


* x5045.png (26.59 KB, 706x175 - viewed 12 times.)
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In my interpretation of the datasheet, your write operation should look like this:

Code:
digitalWrite(SS,LOW);
SPI.transfer(WRITE | (address & 0x0100) ? 8 : 0);
SPI.transfer(address & 0xFF);
SPI.transfer(outval);
digitalWrite(SS, HIGH);

while the read operation should look like this:

Code:
digitalWrite(SS,LOW);
SPI.transfer(READ | (address & 0x0100) ? 8 : 0);
SPI.transfer(address & 0xFF);
inval = SPI.transfer(0x00);
digitalWrite(SS,HIGH);
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thank you for your reply pylon, im still not getting anything, any reads/writes still shows up as '0'.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Post the code your using for this.
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
//4k e2prom and cpu supervisor

#include <SPI.h>
#define WRITE 2
#define READ  3
#define WREN  6
#define RDSR  5
#define WRSR  1

unsigned int address = 0x01;
byte outval = 250;
byte invalue;

void setup(){
  Serial.begin(9600);

  // set up to match device datasheet
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV2); // max clock is 20MHz, so can set high speed
  SPI.begin(); // sets up pin modes etc.
  // Enable writing

  digitalWrite(SS, LOW);
  SPI.transfer(WREN);
  digitalWrite(SS, HIGH);
  
  digitalWrite(SS, LOW);
  SPI.transfer(WRITE); // write instruction
  SPI.transfer((address >> 16) & 255);
  SPI.transfer(address >> 8 & 255);
  SPI.transfer(address & 255);
  SPI.transfer(outval);
  digitalWrite(SS, HIGH);
  delay(5);
  digitalWrite(SS, LOW);
  SPI.transfer(READ); // read instruction

  SPI.transfer((address >> 16) & 255);
  SPI.transfer(address >> 8 & 255);
  SPI.transfer(address & 255);
  invalue = SPI.transfer(0);        // Clock out the data
  digitalWrite(SS, HIGH);
  Serial.print("Read Data = "));
  Serial.println(invalue,DEC);

}

void loop(){
 
}


i am able to write to one address, im assuming its 0, no matter what i make it. ive also tried your code.

Code:
//4k e2prom and cpu supervisor

#include <SPI.h>
#define WRITE 2
#define READ  3
#define WREN  6
#define RDSR  5
#define WRSR  1

unsigned int address = 0x01;
byte outval = 250;
byte invalue;

void setup(){
  Serial.begin(9600);
Serial.println("RESET");

  // set up to match device datasheet
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV2); // max clock is 20MHz, so can set high speed
  SPI.begin(); // sets up pin modes etc.
  // Enable writing

  digitalWrite(SS, LOW);
  SPI.transfer(WREN);
  digitalWrite(SS, HIGH);

digitalWrite(SS,LOW);
SPI.transfer(WRITE | (address & 0x0100) ? 8 : 0);
SPI.transfer(address & 0xFF);
SPI.transfer(outval);
digitalWrite(SS, HIGH);


digitalWrite(SS,LOW);
SPI.transfer(READ | (address & 0x0100) ? 8 : 0);
SPI.transfer(address & 0xFF);
invalue = SPI.transfer(0x00);
digitalWrite(SS,HIGH);


« Last Edit: May 07, 2013, 02:59:59 pm by grendle » Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

this is what interil told me to look at, i cannot however translate this to arduino, any help appreciated.

http://www.intersil.com/content/dam/Intersil/documents/an21/an21.pdf
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
this is what interil told me to look at, i cannot however translate this to arduino

Looks like the chip has to be initialized a bit further before being ready:

Code:
//4k e2prom and cpu supervisor

#include <SPI.h>
#define WRITE 2
#define READ  3
#define WREN  6
#define RDSR  5
#define WRSR  1

unsigned int address = 0x01;
byte outval = 250;
byte invalue;

void setup(){
  Serial.begin(9600);
  Serial.println("RESET");

  // set up to match device datasheet
  SPI.begin(); // sets up pin modes etc.
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV2); // max clock is 20MHz, so can set high speed

  // Enable writing
  digitalWrite(SS, LOW);
  SPI.transfer(WREN);
  digitalWrite(SS, HIGH);

  // Initialize status register
  digitalWrite(SS, LOW);
  SPI.transfer(WRSR);
  SPI.transfer(0x00);
  digitalWrite(SS, HIGH);

  // Latch enable write again (don't know why this is necessary)
  digitalWrite(SS, LOW);
  SPI.transfer(WREN);
  digitalWrite(SS, HIGH);

  // write a value to address 0x01
  digitalWrite(SS,LOW);
  SPI.transfer(WRITE | (address & 0x0100) ? 8 : 0);
  SPI.transfer(address & 0xFF);
  SPI.transfer(outval);
  digitalWrite(SS, HIGH);

  // read a value from address 0x01
  digitalWrite(SS,LOW);
  SPI.transfer(READ | (address & 0x0100) ? 8 : 0);
  SPI.transfer(address & 0xFF);
  invalue = SPI.transfer(0x00);
  digitalWrite(SS,HIGH);
  Serial.print("Read Data = ");
  Serial.println(invalue,DEC);
}

void loop() {
}

What's the output of this sketch?
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi pylon,
heres results

im also working on this, i would have just thrown the chip aside by now usually, but i soldered it (soic8) on an adapter board (5 for $5.95 adafruit) so its kind of a challenge, ill never be able to figure this out on my own though, but im trying  smiley-grin


* 5045results.png (67.32 KB, 943x614 - viewed 9 times.)
« Last Edit: May 08, 2013, 04:09:27 am by grendle » Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just to be sure we don't get problems from operator priority, please try this version too:

Code:
//4k e2prom and cpu supervisor

#include <SPI.h>
#define WRITE 2
#define READ  3
#define WREN  6
#define RDSR  5
#define WRSR  1

unsigned int address = 0x01;
byte outval = 250;
byte invalue;

void setup(){
  Serial.begin(9600);
  Serial.println("RESET");

  // set up to match device datasheet
  SPI.begin(); // sets up pin modes etc.
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV2); // max clock is 20MHz, so can set high speed

  // Enable writing
  digitalWrite(SS, LOW);
  SPI.transfer(WREN);
  digitalWrite(SS, HIGH);

  // Initialize status register
  digitalWrite(SS, LOW);
  SPI.transfer(WRSR);
  SPI.transfer(0x00);
  digitalWrite(SS, HIGH);

  // Latch enable write again (don't know why this is necessary)
  digitalWrite(SS, LOW);
  SPI.transfer(WREN);
  digitalWrite(SS, HIGH);

  // write a value to address 0x01
  digitalWrite(SS,LOW);
  SPI.transfer(WRITE | ((address & 0x0100) ? 8 : 0));
  SPI.transfer(address & 0xFF);
  SPI.transfer(outval);
  digitalWrite(SS, HIGH);

  // read a value from address 0x01
  digitalWrite(SS,LOW);
  SPI.transfer(READ | ((address & 0x0100) ? 8 : 0));
  SPI.transfer(address & 0xFF);
  invalue = SPI.transfer(0x00);
  digitalWrite(SS,HIGH);
  Serial.print("Read Data = ");
  Serial.println(invalue,DEC);
}

void loop() {
}
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

same results. one thing, the chip speed is 3.3mhz, do i have that set correctly?

Code:
SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV2); // max clock is 20MHz, so can set high speed
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

how about this i found this but it was the only file i could grab, that site wanted $$ for me to download the rest

Code:
#include "spi.h"   
#include "serial.h"   
#include <intrins.h>   
#define NOP()  // _nop_();_nop_()   
   
//¿´ÃŹ·Ð´Ê¹ÄÜ×Ó³ÌÐò   
  void wren_dog(void)   
  {   
    SPI_SCK=0;   
    SPI_CS=0;   
    in_byte(WREN);   
    SPI_SCK=0;   
    SPI_CS=1;   
  }   
   
//¿´ÃŹ·Ð´½ûÖ¹×Ó³ÌÐò   
  void wrdi_dog(void)   
 {   
    SPI_SCK=0;   
    SPI_CS=0;   
    in_byte(WRDI);   
    SPI_SCK=0;   
    SPI_CS=1;   
  }   
   
   
   
//д״̬¼Ä´æÆ÷   
  void wrsr_dog(unsigned char status_reg)   
 {   
    SPI_SCK=0;   
    SPI_CS=0;   
    in_byte(WRSR);   
    in_byte(status_reg);   
    SPI_SCK=0;   
    SPI_CS=1;   
    wip_poll();   
  }   
   
   
//¶Á״̬¼Ä´æÆ÷   
 unsigned char rdsr_dog(void)   
 {   
    unsigned char reg1;   
    SPI_SCK=0;   
    SPI_CS=0;   
    in_byte(RDSR);   
    reg1=out_byte();   
    SPI_SCK=0;   
    SPI_CS=1;   
    return(reg1);   
 }   
   
//×Ö½Ú¶Á   
//H,µØÖ·¸ß×Ö½Ú£»LµØÖ·µÍ×Ö½Ú£»data_dog¶Á³öµÄÊý¾Ý   
  unsigned char byte_read(unsigned char H,unsigned char L)   
 {   
    unsigned char data_dog,add=0;   
    SPI_SCK=0;   
    SPI_CS=0;   
    add=H<<3;   
    add|=READ;//READ;   
    in_byte(add);   
    add=L;   
    in_byte(add);   
    data_dog=out_byte();   
    SPI_SCK=0;   
    SPI_CS=1;   
    return(data_dog);   
  }   
//×Ö½Úд   
//H,µØÖ·¸ß×Ö½Ú£»LµØÖ·µÍ×Ö½Ú£»DдÈëµÄÊý¾Ý   
  void byte_write(unsigned char H,unsigned char L,unsigned char D)   
 {   
    unsigned char data_dog,add=0;   
    SPI_SCK=0;   
    SPI_CS=0;   
    add=H<<3;   
    add|=WRTE;//WRTE;   
    in_byte(add);   
    add=L;   
    in_byte(add);   
    data_dog=D;   
    in_byte(data_dog);   
    SPI_SCK=0;   
    SPI_CS=1;   
    wip_poll();   
  }   
   
//¸´Î»¿´ÃŹ·×Ó³ÌÐò   
  void rest_dog(void)   
 {   
    SPI_CS=0;   
    SPI_CS=1;   
  }   
   
//¼ìÑéд²Ù×÷ÊÇ·ñ½áÊø¡£   
  unsigned char wip_poll(void)   
 {   
    unsigned char i;   
    unsigned char wip;   
    for(i=0xff;i>=1;i--)   
    {   
        wip=rdsr_dog();   
        wip&=0x01;   
        if(wip==0) break;   
    }   
   return(wip);   
 }   
   
//µ¥×Ö½ÚÖ¸Áî»òÊý¾ÝдÈëX25045   
//ÔÚSPI_SIÏßÉÏÊäÈëµÄÊý¾ÝÔÚSPI_SCKµÄÉÏÉýÑر»Ëø´æ¡£   
  void in_byte(unsigned char byt)   
  {   
    unsigned char i;   
    for(i=0;i<8;i++)   
    {   
        SPI_SCK=0;   
        SPI_SI=byt&0x80;   
        SPI_SCK=1;   
        byt<<=1;   
    }   
    SPI_SI=0;   
  }   
   
//µ¥×Ö½ÚÊý¾Ý´ÓX25045¶Áµ½µ¥Æ¬»ú   
//Êý¾ÝÓÉSPI_SCKµÄϽµÑØÊä³öµ½SPI_SOÏßÉÏ¡£   
  unsigned char out_byte(void)   
  {   
    unsigned char i;   
    unsigned char byt=0;   
    for(i=0;i<8;i++)   
    {   
        byt=byt<<1;   
        SPI_SCK=1;   
        SPI_SCK=0;   
        byt|=SPI_SO;   
    }   
    return (byt);   
  }     
   
   
/**************************************************/   
void main(void)   
{   
  unsigned char D;   
  unsigned char add_H=0x01,add_L=0x00;   
  unsigned char ucDATA=0x11;   
  init_serial();   
  while(1)   
    {   
        //wren_dog();   
        //wrsr_dog(0);   
        //wren_dog();     
        byte_write(add_H,(add_L++),(ucDATA++));   
        D=byte_read(add_H,add_L);   
        PutChar(D);     
     }   
}   
   
« Last Edit: May 08, 2013, 05:48:41 am by grendle » Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
same results. one thing, the chip speed is 3.3mhz, do i have that set correctly?

Where is this comment coming from then?
Code:
max clock is 20MHz, so can set high speed

You have to slow down the communication in this case then:

Code:
SPI.setClockDivider(SPI_CLOCK_DIV8); // max speed is 3MHz, we choose 2MHz

Does that change anything?
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Where is this comment coming from then?
sorry that comment left over from spi tutorial i just copy/paste it for my spi chips.

same results
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How did you connect the chip to the Arduino? Describe every connection made or draw a schematics or post a photo show all.
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

x5045                   Arduino Uno
pin 1                    pin10 cs/ss
pin2                     pin12
pin3                     5v
pin4                     gnd
pin5                     pin11
pin6                     pin13 sclk
pin7                     no connection
pin8                     5v
Logged

Pages: [1] 2   Go Up
Jump to: