Assign an unsigned char to a row of a 2D char array

Hi,

I am working on a program and I think i am have issues with memory management. I am doing the work to read a SRAM chip (each position per reading, each position has 8-bit information, read 1024 positions) and store the results into a 2D char array (each row stores one reading result). I would post the whole code but its well over 10k lines and my question is simple *even if its XY

unsigned char r_data = 0;
unsigned char dataStorge[1024][8];

unsigned char SRAM_Read(unsigned char SRAMaddr)

for(addr=0;addr<=0x03FF;addr++)//1024 Bytes Only //0x7FFF for whole chip, 32767 Bytes
{       
    r_data = SRAM_Read(addr);
    strcpy(dataStorge[addr], r_data);
    r_data = 0;
 }

When I try to compile it, the error message shows:

initializing argument 1 of ‘char* strcpy(char*, const char*)’ [-fpermissive]
extern char *strcpy(char , const char );
^
invalid conversion from 'unsigned char
’ to 'char

I do not know what is the meaning of such information. Could you please help me? Thanks!

Also, when I finish the 1024 readings, I want to send the data in dataStorge to PC.
Here is my displayInfo() function:

void displayInfo( unsigned char[] message){
 for(int index = 0; index<1024;index++)
 { 
   for(int b = 7;b>=0;b--)//data
   { 
     Serial.print(bitRead(message[index][b],b)); 
   }
   Serial.println();
 }    
}

I am not sure if it is correct because the program can not be compiled.
I use bitRead() because the most left-side bit may be 0,
if I use Serial.print(message[index]), it may loss data.
Could you please give me some advice?
Thank you!

unsigned char dataStorge[1024];

unsigned char SRAM_Read(unsigned char SRAMaddr)

for(addr=0;addr<=0x03FF;addr++)
{       
    dataStorge[addr] = SRAM_Read(addr);
}
void displayInfo( unsigned char[] message){
 for(int index = 0; index<1024;index++)
 {
   for(int b = 7;b>=0;b--)//data
   {
     Serial.print(bitRead(message[index],b));
   }
   Serial.println();
 }   
}

Why do you save a textual binary representation of the data?

Do you have a system where a 1k-byte buffer does not hurt?
Your old code even used a 8k-byte buffer…

Whandall:

unsigned char dataStorge[1024];

unsigned char SRAM_Read(unsigned char SRAMaddr)

for(addr=0;addr<=0x03FF;addr++)
{     
    dataStorge[addr] = SRAM_Read(addr);
}





void displayInfo( unsigned char message){
for(int index = 0; index<1024;index++)
{
  for(int b = 7;b>=0;b–)//data
  {
    Serial.print(bitRead(message[index],b));
  }
  Serial.println();

}




Why do you save a textual binary representation of the data?

Do you have a system where a 1k-byte buffer does not hurt?
Your old code even used a 8k-byte buffer...

The data is the initial state of a 32K x 8 SRAM, so the data needs to be stored as a textual binary representation file. Because each position has 8-bits data needs to be stored. If I read 1024 positions, I need 8k-bytes buffer. So I think the 2D char array is necessary. The ATMega 2560 has 8K SRAM, I will reduce the number of reading positions (such as 768 positions) to make sure the SRAM is enough. Thank you!

zhliao:
Because each position has 8-bits data needs to be stored. If I read 1024 positions, I need 8k-bytes buffer. So I think the 2D char array is necessary

Nope.

Each byte contains 8 bits, you only need 1024 byte for a copy and no second dimension.

But you do not have to believe me, I'm no preacher.

Whandall:
Nope.

Each byte contains 8 bits, you only need 1024 byte for a copy and no second dimension.

But you do not have to believe me, I'm no preacher.

Yes you are right, the space is 1K bytes. So if I define a char array as dataStorge[1024], can I store each 8-bits data as one of the element of this array? I will try it, thank you!

zhliao:
So if I define a char array as dataStorge[1024], can I store each 8-bits data as one of the element of this array? I will try it, thank you!

I already posted the code that does exactly that. :confused:

Whandall:
I already posted the code that does exactly that. :confused:

Yes, I have tried these two segments of code. The first one seems perfect but when I get such errors in the second void displayInfo( unsigned char message) function:

expected ',' or '...' before 'message'
void displayInfo( unsigned char message){

error: 'message' was not declared in this scope
Serial.print(bitRead(message[index],b));
^

We already defined 'message', why it error happens? Thank you!

void displayInfo(unsigned char message[]){

This is C++ not Java.

I did not look close enough to the function definition... sorry

Whandall:

void displayInfo(unsigned char message[]){

This is C++ not Java.

Thanks a lot! I just fainted!