How do you force byte writes to memory using CW?

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you force byte writes to memory using CW?

3,413 Views
nanoGeek
Contributor I
I am using the following code segment to write a data byte to an absolute memory location, held in "address" :
 
*(uint8 *)(address) = (uint8)data;
 
uint8 is defined as follows:
 
typedef unsigned short int uint8;
 
The problem is, the code is doing word (16 bit) memory accesses.  What am I doing wrong?
 
Thanks,
 
Joe

Message Edited by nanoGeek on 02-23-200609:59 AM

Message Edited by nanoGeek on 02-23-200610:00 AM

Labels (1)
0 Kudos
2 Replies

84 Views
bigmac
Specialist III

Hello Joe,

It seems that a short is actually 16 bit size.  I had no problem with the following code:

typedef unsigned char byte;

byte data = 0x41;
byte *address;
byte dest;

address = &temp;
*address = data;

Regards,
Mac

 

0 Kudos

84 Views
desroc01
Contributor II
You can write in RAM like this :

//SOLUTION 1 :

//All pointer size depends of the machine.. (i.e 2 bytes)
char *memPtr;
char theContent;
unsigned short int memItr;

//Initialize ram (write) //0x1000 to 0x1010
//... We write to 16 locations
memPtr = (signed char*) 0x1000;
for (memItr = 0 ; memItr 16 ; memItr++)
{
(*memPtr) = 0x55; //Write an acsii char..
memPtr = memPtr + 1;
}


//Init the ptr and itr
memPtr = (signed char*) 0x1000; //Memory ptr
memItr = 0;

//Display
printf("Memory display (Ram 0x1000 to 0x1010)... ");
for (memItr;memItr16:smileywink:
{
memItr++; theContent = (*memPtr); //display the content.(HEX_TO_ASCII?)
memPtr = memPtr + 1;
}


//SOLUTION 2 :
char lFillRam[ARR_DIM]; //Array of character
for (memItr=0 ; memItr
{
lFillRam[memItr] = 'U';
}


If you want to write in Flash or Eeprom, you have to follow some special algorithm (procedure). See the AN for you MCU
0 Kudos