Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

writing to flash program memory in pic18f66k22

Status
Not open for further replies.

shreyas_patel21

Full Member level 3
Joined
Jan 4, 2011
Messages
181
Helped
15
Reputation
30
Reaction score
14
Trophy points
1,298
Activity points
2,325
Hi all,

I am using PIC18f66k22 with our custom board.
I want to write flash program memory for our use.
I tried to use library function WriteBytesFlash but when I read the program memory there was no change, it is not bwing written.

I used following example code.:

Code:
void main(void)
{
unsigned char i;

    //Initialize Data to be written to flash
    for(i=0;i<250;i++)
    {
        Write_Data[i]=i+1;
        Read_Data[i]=0;
    }

    //Write data into flash from the specified location
    WriteBytesFlash((UINT32)0x6000,(UINT16)250,Write_Data);

    //Read the data to verify the writted data
    ReadFlash((UINT32)0x6000,(UINT16)250,Read_Data);

    //Erase Flash
    EraseFlash((UINT32)0x6000,(UINT32)0x7000);

    //Read the data to verify the erased data
    ReadFlash((UINT32)0x6000,(UINT16)128,Read_Data);

    //Write data into flash from the specified location
    WriteBlockFlash((UINT32)0x6000,4,Write_Data);

    //Read the data to verify the writted data
    ReadFlash((UINT32)0x6000,(UINT16)128,Read_Data);

    while(1);            //End of Program

}


thank you,
 

shreyas_patel21

Full Member level 3
Joined
Jan 4, 2011
Messages
181
Helped
15
Reputation
30
Reaction score
14
Trophy points
1,298
Activity points
2,325
I dotn know this is solution or not but I could write in Flash memory using following code:

Code:
LoadFlashAddr(startaddr);
	 	i=0;
	 	while(counter--)
	 	{
		 	_asm	TBLRDPOSTINC _endasm
		 	Read_Data[i] = TABLAT;
		 	i++;
		}		
	 	
	 	for(i=0;i<128;i++)
	    {
	        Write_Data[i]= a;
	        Read_Data[i]=0;
	    }
		
		LoadFlashAddr(startaddr);
		EECON1bits.EEPGD = 1;
		EECON1bits.CFGS = 0;
		EECON1bits.WREN = 1;
		EECON1bits.FREE = 1;
		//INTCON1.GIE = 0;
		EECON2 = 0x55;
		EECON2 = 0xAA;
		EECON1bits.WR =1;
		//INTCONbits.GIE = 1;
		_asm  TBLRDPOSTDEC 	_endasm
		counter = SIZE_OF_BLOCK;
		i=0;
		while(counter--)
		{
			TABLAT = Write_Data[i];
			_asm  TBLWTPOSTINC 	_endasm
			i++;
		}	
		EECON1bits.EEPGD = 1;
		EECON1bits.CFGS = 0;
		EECON1bits.WREN = 1;
		EECON2 = 0x55;
		EECON2 = 0xAA;
		EECON1bits.WR =1;
		EECON1bits.WREN = 0;

thank you,

I am trying to find why the example code(in 1st post in this thread) given in library did not work..
 

yuvko

Member level 4
Joined
Sep 5, 2007
Messages
74
Helped
19
Reputation
38
Reaction score
17
Trophy points
1,288
Activity points
1,596
i think you should init the flash for writing before trying to write to it. i.e:
EECON1bits.EEPGD = 1;
EECON1bits.CFGS = 0;
EECON1bits.WREN = 1;
EECON1bits.FREE = 1;
//INTCON1.GIE = 0;
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1bits.WR =1;
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top