Go Down

Topic: spi 9bit eeprom address can only see addr 0x00? (Read 1 time) previous topic - next topic

grendle

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: [Select]
#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(){}

pylon

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

Code: [Select]

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: [Select]
digitalWrite(SS,LOW);
SPI.transfer(READ | (address & 0x0100) ? 8 : 0);
SPI.transfer(address & 0xFF);
inval = SPI.transfer(0x00);
digitalWrite(SS,HIGH);

grendle

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

pylon


grendle

#4
May 07, 2013, 09:19 pm Last Edit: May 07, 2013, 09:59 pm by grendle Reason: 1
Code: [Select]
//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: [Select]
//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);




grendle

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

pylon

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: [Select]
//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?

grendle

#7
May 08, 2013, 10:59 am Last Edit: May 08, 2013, 11:09 am by grendle Reason: 1
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  :D

pylon

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

Code: [Select]
//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() {
}

grendle

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

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

grendle

#10
May 08, 2013, 11:56 am Last Edit: May 08, 2013, 12:48 pm by grendle Reason: 1
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: [Select]
#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);     
     }   
}   
   

pylon

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: [Select]
max clock is 20MHz, so can set high speed

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

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

Does that change anything?

grendle

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

pylon

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

grendle

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

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy