Ecriture flash R8C/1B

Postby gatsby94 » Tue Aug 28, 2007 12:00 am

voici une nouvelle discussion sur l'ecriture en flash sur le R8C/1B.
j'ai codé ceci par rapport à la datasheet du R8C/1B. Or lorsque je regarde grace à MAP memory dans HEW je ne vois pas à l'adresse identiquée le message voulu.
voici le code.
qqun peutil y jeter un oeil.

static unsigned char data_read( unsigned char *,unsigned char);
static unsigned char lit_flash(unsigned char *,unsigned char);
static unsigned char block_erase(unsigned char *);
static unsigned char data_write( unsigned char *,unsigned char);
static unsigned char flash_write(unsigned char *,unsigned char);

#define COMPLETE 0x00 /* FLASH write/erase complete */
#define PROGRAM_ERR 0x01 /* FLASH data write error */
#define ERASE_ERR 0x02 /* FLASH erase error */
#define BLOCK_A_SELECT 0 /* Use BLOCK A */
#define BLOCK_B_SELECT 1 /* Use BLOCK B */
#define ADRESSE_MAC ((unsigned char*)0x2000) /* address Adresse_MAC*/
#define AD_CODE_CLIENT ((unsigned char*)0x2010) /* address code_client*/
#define ADRESSE_N_SERIE ((unsigned char*)0x2014) /* address code_client*/
#define BLOCK_A_END ((unsigned char *)0x27FF) /* BLOCK A last address */

unsigned char *write_addr;
unsigned char mess[10];
/**********************************************************************************
Function Name : main
Description : Main function
Parameters : none
Return value : none
***********************************************************************************/
void main(void)
{
unsigned char result, result2;
mess[0] = 'H';
mess[1] = 'E';
mess[2] = 'L';
mess[3] = 'L';
mess[4] = 'O';
write_addr = ADRESSE_MAC;


result2 = block_erase(ADRESSE_MAC);

result = flash_write(mess,5);
}
/**********************************************************************************
End of function main
***********************************************************************************/
/*------------------------------------------------------------------*/
/*-----------------Flash-write--------------------------------------*/
/*------------------------------------------------------------------*/

unsigned char flash_write(unsigned char *data,unsigned char nmbre_octet)
{

unsigned char result = COMPLETE;

if( data_write( data ,nmbre_octet) != COMPLETE )
{

result = result | PROGRAM_ERR;
}
return result;
}

/*-----------------------------------------------------------------------*/
/*--------------ecriture-dans-la-flash-----------------------------------*/
/*-----------------------------------------------------------------------*/

unsigned char data_write( unsigned char *write_data,unsigned char RECORD_SIZE )
{
unsigned char program_result = COMPLETE;
int i;
/* If use interrupt then clear i flag... */
asm("fclr i ");
/* flash control register set */
fmr0 = 0x01;
asm(""); /* Description for preventing the abbreviation by optimization */
fmr0 = 0x03; /* CPU rewrite enable */
fmr1 = 0x00;
asm(""); /* Description for preventing the abbreviation by optimization */
fmr1 = 0x02; /* EW1 mode */
for( i = 0; i < RECORD_SIZE; i++ ){
write_addr = 0x40;
write_addr = write_data;
while( fmr00 != 1 ); /* Ready check */
/* Program status check */
if( fmr06 == 1 ){
/* Program error */
*write_addr = 0x50; /* Clear status register */
program_result = PROGRAM_ERR;
break;
}
}
/* flash control register reset */
fmr0 = 0x01; /* CPU rewrite disable */
/* If use interrupt then set i flag...*/
asm("fset i ");
return program_result;
}

/*-------------------------------------------------------------------*/
/*--------------------efface-flash-----------------------------------*/
/*-------------------------------------------------------------------*/


unsigned char block_erase(unsigned char *ers_addr)
{
unsigned char erase_result;
// If use interrupt then clear i flag...
asm("fclr i ");
// flash control register set
fmr0 = 0x01;
asm(""); // Description for preventing the abbreviation by optimization
fmr0 = 0x03; // CPU rewrite enable
fmr1 = 0x00;
asm(""); // Description for preventing the abbreviation by optimization
fmr1 = 0x02; // EW1 mode
*ers_addr = 0x20; // Block erase command write
*ers_addr = 0xd0; // Block erase command write
while( fmr00 != 1 ); // Ready check
// Erase status check
if( fmr07 == 1 ){
*ers_addr = 0x50; // Clear status register
erase_result = ERASE_ERR;
}else{
erase_result = COMPLETE;
}
// flash control register reset
fmr0 = 0x01; // CPU rewrite disable
// If use interrupt then set i flag...
asm("fset i ");
return erase_result;
}
/*------------------------------------------------------------------*/
/*-----------------Flash-read--------------------------------------*/
/*------------------------------------------------------------------*/

unsigned char lit_flash(unsigned char *data,unsigned char nmbre_octet)
{

unsigned char result = COMPLETE;

if( data_read( data ,nmbre_octet) != COMPLETE ){
// Program error occurence
result = result | PROGRAM_ERR; // if program error
}
return result;
}

/*--------------------------------------------------------------*/
/*---------------------Lecture-dans-flash------------------------------*/
/*--------------------------------------------------------------*/

unsigned char data_read( unsigned char *read_data,unsigned char RECORD_SIZE )
{
unsigned char program_result = COMPLETE;
int i; // loop counter
// If use interrupt then clear i flag...
asm("fclr i ");
// flash control register set
fmr0 = 0x01;
asm(""); // Description for preventing the abbreviation by optimization
fmr0 = 0x03; // CPU rewrite enable
fmr1 = 0x00;
asm(""); // Description for preventing the abbreviation by optimization
fmr1 = 0x02; // EW1 mode //
for( i = 0; i < RECORD_SIZE; i++ ){
write_addr = 0xFF;
write_addr= read_data;
while( fmr00 != 1 ); // Ready check
// Program status check //
if( fmr06 == 1 ){
// Program error
*write_addr = 0x50; // Clear status register
program_result = PROGRAM_ERR;
break;
}
}
// flash control register reset
fmr0 = 0x01; // CPU rewrite disable
// If use interrupt then set i flag...
asm("fset i ");
return program_result;
}
gatsby94
 
Posts: 29
Joined: Fri Jan 17, 2014 4:38 pm

Return to R8C/13 (01-2006)

Who is online

Users browsing this forum: No registered users and 1 guest