Storing and comparing SRAM memory address

//below is my code for reading an SRAM memory location. i want to set condition to the HEX output of the address but my loop is being ignored

/* 
 CS: pin 12  
 MOSI: pin 8
 MISO: pin 10
 SCK: pin 9
 
*/

#include <SPI.h>

//SRAM opcodes
#define RDSRAM        5  //00000101 
#define WRSRAM        1  //00000001
#define READ          3  //00000011
#define WRITE         2  //00000010
int CS = 12;
int CSS = 8;

 
uint8_t Spi23K640Rd8(uint32_t address){ 
uint8_t read_byte;

digitalWrite(CS,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);
digitalWrite(CS,HIGH);
return read_byte;
  }


void setup() {
  
 //int *ptr;        
// int myvar[1] = {545};                   //assigning the pointer to locaction
// ptr = &myvar[0];
// ptr = ptr + 0;
 //int dataIn = Serial.parseInt();
  uint64_t i; 
  uint8_t value;
 /* all pins on the Port B set to output-low */
  pinMode(CSS, OUTPUT);
  digitalWrite(CSS, HIGH);
  pinMode(CS, OUTPUT);
  Serial.begin(9600);
  delay(2500);
  SPI.begin();


     //for (i=0; i<=1; i) {  // check exact location memory locations, 64 Kbit SRAM = 65536 / 8 = 8192 i=545 
    //Spi23K640Wr8(i, (uint8_t)i);
     value = Spi23K640Rd8(i);
    Serial.println(Spi23K640Rd8(545), HEX);
    delay(100);
      
   // if ( int dataIn  = (91) )  { 
     // Serial.println(Spi23K640Rd8(545), DEC);
    //} else {     
     // Serial.print("wrong response pair");
   // }
    
  
}



void loop() {

  
  while(Serial.available() > 0)
  {
    unsigned long val = 0x5C;
    uint8_t value = (val, Serial.read());
    val = Serial.read();
    if (val == (0x5C))
    {
       Serial.print("Right CRP");
    }
   else if (val != (0x5C))
    {
      Serial.print("Wrong CRP");
    }
delay(500);


}
}
type or paste code here

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

thanks for your correction. I just applied it

Thank you

Can you explain what you are doing in the loop()?
As I see - reading a byte from a serial port and comparing it to a constant 0x5C?
What is the meaning of this and what does it have to do with reading SRAM memory?

HI, thanks for your reply.
my loop has been ignored totally.

i am accessing an empty 23k640 SRAM chip using adafruit feather M0 and the code below

Serial.println(Spi23K640Rd8(545), HEX);

prints out the memory location 545 on the serial monitor which gives an output of 5C in HEX.

what I am trying to achieve is a comparison to the output 5C in such a way that if the output of memory address 545 changes from 5C it recognises it as wrong output.
and I also want 5C so be a constant so that if the location i try to access changes such as to 544 it recognises as well.
the whole concept is to achieve a challenge response pairs for that memory address to create function to mitigate bit flips due to power reset.

Do you understand that with your current code, you can’t check memory 545 in the loop(), since you don’t read memory at all?

do you send anything to arduino by serial port? Without this, your loop will be ignored, this is the code you wrote

yes, I know.
the void setup () reads out the output without the loop.
how do I get the output stored and set up for comparison with the right data type

     value = Spi23K640Rd8(i);
    Serial.println(Spi23K640Rd8(545), HEX);
    char val2 = (Spi23K640Rd8(545), HEX);
     CRP(); 
    delay(100);
      
   // if ( int dataIn  = (91) )  { 
     // Serial.println(Spi23K640Rd8(545), DEC);
    //} else {     
     // Serial.print("wrong response pair");
   // }
    
  
}



void loop() {

  
  while(Serial.available() > 0)
  {
   
    //CRP(); 
}
}


void CRP() {
  char *ptr = (char*)0x5C;
  char val = *ptr;
  char val1 = ptr[0];
  char val2 = ptr[1];
  ptr = &val2;
  //ptr = ptr + 0;
  
  if ((val2)== ptr){
       Serial.print("Right CRP");
    }
   else
    {
      Serial.print("Wrong CRP");
    }
delay(500);
  }
  

Sorry, but your code looks nonsense almost in each line...

first line is weird, because value i is indefined
third line is erroneous and useless, because result of operation, val2, not used further

Next piece of code, see the comments:

It looks like you lack basic knowledge about variables and pointers, I would advise you to read something for beginners about the C language for a start.

thanks for the feedback. it seems i sent you the wrong jumbles.
been revisiting the basics
but i cant seem to save the value of this location

  Serial.print("challenge = Ox");
    Serial.println(Spi23K640Rd8(545), HEX);

fin below the full code

/* 
 CS: pin 12  
 MOSI: pin 8
 MISO: pin 10
 SCK: pin 9
 
*/

#include <SPI.h>

//SRAM opcodes
#define RDSRAM        5  //00000101 
#define WRSRAM        1  //00000001
#define READ          3  //00000011
#define WRITE         2  //00000010
int CS = 12;
int CSS = 8;

 
uint8_t Spi23K640Rd8(uint32_t address){ 
uint8_t read_byte;

digitalWrite(CS,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);
digitalWrite(CS,HIGH);
return read_byte;
  }


void setup() {
  
  uint64_t i; 
  uint8_t value;
  byte *ptr;
 /* all pins on the Port B set to output-low */
  pinMode(CSS, OUTPUT);
  digitalWrite(CSS, HIGH);
  pinMode(CS, OUTPUT);
  Serial.begin(9600);
  delay(2500);
  SPI.begin();


  //for (i=0; i<=1; i) {  // check exact location memory locations, 64 Kbit SRAM = 65536 / 8 = 8192 i=545 
  //Spi23K640Wr8(i, (uint8_t)i);
  
    value = Spi23K640Rd8(545);
    //ptr = (byte*)&value;
    Serial.print("challenge = Ox");
    Serial.println(Spi23K640Rd8(545), HEX);
    delay(100);
    
 
  
}



void loop() {
  

  
}

I don't see any attempts to save it in the code. Please point me the line

 value = Spi23K640Rd8(i);
    Serial.print("challenge = Ox");
    Serial.println(Spi23K640Rd8(545), DEC);
    uint8_t nval = 92; 
    nval = sizeof(int);

    if (value == nval) 
  {
    Serial.print("challenge accepted");
   // Serial.println(Spi23K640Rd8(545), DEC);
    
  }
else 
{
   Serial.print("challenge wrong");
}
    delay(100);
      
}
still attempting it. that's my result
![Screenshot (199)|690x387](upload://xXt4BXzB3nrsEFh5nknkQ6ldAXV.jpeg)

Again

where is value of i defined?

What's the mess.. Do you know what the function sizeof() doing? Why do you use it here?
What do you try to achieve in this lines?

@astroman1
I don't think I can help you.
Reread the last sentence in post 10

Hi,
for some reason you think there is a part that addresses my issue somewhere. but i have looked around and this mess is what i keep seeing. i very much understand variable, pointers and array. but it's so much easier to implement if i was creating an array. but for a raw SRAM value. its proving difficult to do. if you have an example i can look at that relates. please a link will help. because everyone keeps criticizing my code without telling what i am doing wrong or what i should do write.

Can you explain what are you doing in this lines?

What will be equal nval after the second line?

I still don't understand what exactly you are trying to do.

Hi,
thanks for your feedback. let me explain as much as i can.
i am trying to store a printed value from the serial monitor for comparison.
but the output of the serial monitor is the raw data of an SRAM memory address 545.
i want to set a read condition for the memory address because it changes with power reset.
currently the output in DEC on the serial monitor is 92, and it has remained the same through multiple power cycle but what if after the power reset it's no longer 92 on that memory address. how do I save the previous value and create condition because in BIN the change across the raw SRAM usually output a bit flip.

You haven't answered this question:

hi, disregard that i have just been copying random stuff as nothing seems to work
find below my current code

/* 
 CS: pin 12  
 MOSI: pin 8
 MISO: pin 10
 SCK: pin 9
 
*/

#include <SPI.h>

//SRAM opcodes
#define RDSRAM        5  //00000101 
#define WRSRAM        1  //00000001
#define READ          3  //00000011
#define WRITE         2  //00000010
int CS = 12;
int CSS = 8;
uint8_t value;
uint8_t Spi23K640Rd8(uint32_t address){ 
uint8_t read_byte;

int nval;
digitalWrite(CS,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);
digitalWrite(CS,HIGH);
return read_byte;
  }


void setup() {
  char data[100]; 
  short pos=-1;
  uint64_t i; 
  uint8_t value;
  byte *ptr;
 /* all pins on the Port B set to output-low */
  pinMode(CSS, OUTPUT);
  digitalWrite(CSS, HIGH);
  pinMode(CS, OUTPUT);
  Serial.begin(9600);
  delay(2500);
  SPI.begin();

 while(Serial.available()&&pos<100) data[++pos]=Serial.read(); 
  //for (i=0; i<=92; i) {  // check exact location memory locations, 64 Kbit SRAM = 65536 / 8 = 8192 i=545 
  //Spi23K640Wr8(i, (uint8_t)i);
    value = Spi23K640Rd8(i);
    //Serial.print("challenge = Ox");
    int nval=Serial.read();
 if (Serial.available() > 0, && i == "92") 
 { 
     Serial.print("challenge = Ox");
     Serial.println(Spi23K640Rd8(545), DEC);
    } 
    else {
     Serial.print("challenge wrong"); 
    } 
  }