Go Down

Topic: ArduinoADK AT45DB161d reading status 0x5B ?! (Read 393 times) previous topic - next topic

Sep 18, 2013, 05:17 am Last Edit: Sep 20, 2013, 04:13 pm by Rahul2047 Reason: 1
Hi,

I have worked on MEGA+FLASH earlier with UART3 as SPI which worked great using AVR Studio 5/6 without Arduino. I want to try it with Arduino.  :)
I am accessing flash using ADK via SPI ( Arduino SPI library ).

I also tried other libraries for the flash.
I started with my own.  :smiley-mr-green:

It reads status as 0xAD, the good one each time I read the status register only.
When start with read write. The status becomes 0x2D for a while as it is bg.
Now sometimes it gets stuck while read write and gives status as 0x5B  :smiley-eek-blue: which seems like a rotated right bit shifted value of 0xAD.

I couldn't find the problem yet. I am still working on it. Any pointer will be also do. If above info is not enough I will post the complete code here. Which I'll have to clean.  :P  :smiley-red:

Thanks.

Edit:

Code below:
Code: [Select]

// calling from loop
void ProblemNarrowDownTest()
{

  unsigned long address = (unsigned long)TrueRandom.random(0x1FFF0); // 0x00;//0x1DFFFE;
 
 
//////////////////////////////////////////////
  // Tx memory to Buffer
  digitalWrite(slaveSelectPin,LOW);
  NOP4CYCLES

   SPI.transfer(0x53);
 
  SPI.transfer(address>>16);
  SPI.transfer(address>>8);
  SPI.transfer(address);
  //SPI.transfer(0x00); // dummy
  //SPI.transfer(0x00);
  digitalWrite(slaveSelectPin,HIGH); 
  NOP4CYCLES
unsigned long now = millis();
  while(!(ReadStatus() & 0x80) && ((millis()-now)<1000));            //monitor the status register, wait until busy-flag is high
 
  Serial.println(ReadStatus(),HEX);



//////////////////////////////////////////////
  // Compare

  digitalWrite(slaveSelectPin,LOW);
  NOP4CYCLES
  SPI.transfer(0x60);
  SPI.transfer(address>>16);
  SPI.transfer(address>>8);
  SPI.transfer(address);
  NOP4CYCLES
    digitalWrite(slaveSelectPin,HIGH); 
  NOP4CYCLES

    now = millis();
  while(!(ReadStatus() & 0x80) && ((millis()-now)<1000));            //monitor the status register, wait until busy-flag is high

  unsigned char statusReg = (ReadStatus() & 0x40);

  Serial.println(ReadStatus(),HEX);


//////////////////////////////////////////////
  // Write

  digitalWrite(slaveSelectPin,LOW);
  NOP4CYCLES

    SPI.transfer(0x84);
  SPI.transfer(address>>16);
  SPI.transfer(address>>8);
  SPI.transfer(address);
  SPI.transfer('t');
  SPI.transfer('e');
  SPI.transfer('s');
  SPI.transfer('t');

  NOP4CYCLES

    digitalWrite(slaveSelectPin,HIGH); 
  NOP4CYCLES

 
   
//////////////////////////////////////////////
//Buffer to main
  digitalWrite(slaveSelectPin,LOW);
  NOP4CYCLES

   SPI.transfer(0x83);//(0x88);//(0x83); // Buffer1
   
  SPI.transfer(address>>16);
  SPI.transfer(address>>8);
  SPI.transfer(address);
  SPI.transfer(0x00); // dummy
  //SPI.transfer(0x00);

  NOP4CYCLES
    digitalWrite(slaveSelectPin,HIGH); 
  NOP4CYCLES

     now = millis();
  while(!(ReadStatus() & 0x80) && ((millis()-now)<1000));            //monitor the status register, wait until busy-flag is high
  DEBUG_LINE
    Serial.println(ReadStatus(),HEX);

   
//////////////////////////////////////////////
  // Put compare here:

  digitalWrite(slaveSelectPin,LOW);
  NOP4CYCLES
   SPI.transfer(0x60);
 
  SPI.transfer(address>>16);
  SPI.transfer(address>>8);
  SPI.transfer(address);
  NOP4CYCLES
    digitalWrite(slaveSelectPin,HIGH); 
  NOP4CYCLES

    now = millis();
  while(!(ReadStatus() & 0x80) && ((millis()-now)<1000));            //monitor the status register, wait until busy-flag is high

  statusReg = (ReadStatus() & 0x40);

  Serial.println(ReadStatus(),HEX);

  // transfer main to buffer
  digitalWrite(slaveSelectPin,LOW);
  NOP4CYCLES

   SPI.transfer(0x53);
   
  SPI.transfer(address>>16);
  SPI.transfer(address>>8);
  SPI.transfer(address);
  //SPI.transfer(0x00); // dummy
  //SPI.transfer(0x00);
  digitalWrite(slaveSelectPin,HIGH); 
  NOP4CYCLES

  now = millis();
  while(!(ReadStatus() & 0x80) && ((millis()-now)<1000));            //monitor the status register, wait until busy-flag is high
 
  Serial.println(ReadStatus(),HEX);


//////////////////////////////////////////////
/////////////////////For read

  // transfer memory to Buffer
  digitalWrite(slaveSelectPin,LOW);
  NOP4CYCLES
 
  SPI.transfer(0x53);
  SPI.transfer(address>>16);
  SPI.transfer(address>>8);
  SPI.transfer(address);
  //SPI.transfer(0x00); // dummy
  //SPI.transfer(0x00);
  digitalWrite(slaveSelectPin,HIGH); 
  NOP4CYCLES

   now = millis();
  while(!(ReadStatus() & 0x80) && ((millis()-now)<1000));            //monitor the status register, wait until busy-flag is high
 
  Serial.println(ReadStatus(),HEX);



//////////////////////////////////////////////
  // Compare

  digitalWrite(slaveSelectPin,LOW);
  NOP4CYCLES
  SPI.transfer(0x60);
  SPI.transfer(address>>16);
  SPI.transfer(address>>8);
  SPI.transfer(address);
  NOP4CYCLES
    digitalWrite(slaveSelectPin,HIGH); 
  NOP4CYCLES

    now = millis();
  while(!(ReadStatus() & 0x80) && ((millis()-now)<1000));            //monitor the status register, wait until busy-flag is high

   statusReg = (ReadStatus() & 0x40);

  Serial.println(ReadStatus(),HEX);


//////////////////////////////////////////////
  // Read back

  digitalWrite(slaveSelectPin,LOW);
  NOP4CYCLES

  PI.transfer(0xD4);
 
  SPI.transfer(address>>16);
  SPI.transfer(address>>8);
  SPI.transfer(address);
  SPI.transfer(0x00); // dummy test
  int len =  0;//datasetLen;
   
  while(len<4)
  {
   char dataSet = SPI.transfer(0x00);      //read byte and put it in AVR buffer pointed to by *BufferPt
    Serial.print(" ");
    Serial.print(dataSet);
    len++; 
  }
 
  digitalWrite(slaveSelectPin,HIGH); 
  NOP4CYCLES
 
}


With random addresses.
Am I making mistake in addressing?

Thanks
Everything keeps me (learning) teaching new things depending upon my perception at that time, giving infinite ways to think about only one t

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