• AVR Freaks

Hot!problem with PIC18F45K80 Flash Write

Author
rajeesh_rarankurissi
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2020/02/04 03:27:05
  • Location: 0
  • Status: offline
2020/02/25 23:59:38 (permalink)
0

problem with PIC18F45K80 Flash Write

Hi 
I am working with PIC18F45K80 . I am facing an issue while data write in to program memory using flash write function 
The function that i am using is below 
 

int8_t FLASH_WriteBlock(uint32_t writeAddr, uint8_t *flashWrBufPtr)
{
uint32_t blockStartAddr = (uint32_t )(writeAddr & ((END_FLASH-1) ^ (ERASE_FLASH_BLOCKSIZE-1)));
uint8_t GIEBitValue = INTCONbits.GIE; // Save interrupt enable
uint8_t i, j, numberOfWriteBlocks;
uint16_t WriteBlkOffset = 0;

// Flash write must start at the beginning of a row
if( writeAddr != blockStartAddr )
{
return -1;
}

// Total number of write blocks present in one erase block
numberOfWriteBlocks = ERASE_FLASH_BLOCKSIZE/WRITE_FLASH_BLOCKSIZE;
// Block erase sequence
FLASH_EraseBlock(writeAddr);

for(j=0; j<numberOfWriteBlocks; j++)
{
// Calculate starting offset of Write Block
WriteBlkOffset = (uint16_t)j * WRITE_FLASH_BLOCKSIZE;

// Block write sequence
TBLPTRU = (uint8_t)(((writeAddr + WriteBlkOffset) & 0x00FF0000) >> 16); // Load Table point register
TBLPTRH = (uint8_t)(((writeAddr + WriteBlkOffset) & 0x0000FF00) >> 8);
TBLPTRL = (uint8_t)((writeAddr + WriteBlkOffset) & 0x000000FF);

// Write block of data
for (i=0; i<WRITE_FLASH_BLOCKSIZE; i++)
{
TABLAT = flashWrBufPtr[WriteBlkOffset+i]; // Load data byte
if (i == (WRITE_FLASH_BLOCKSIZE-1))
{
asm("TBLWT");
}
else
{
asm("TBLWTPOSTINC");
}
}
EECON1bits.EEPGD = 1;
EECON1bits.CFGS = 0;
EECON1bits.WREN = 1;
INTCONbits.GIE = 0; // Disable interrupts
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1bits.WR = 1; // Start program
EECON1bits.WREN = 0; // Disable writes to memory
INTCONbits.GIE = GIEBitValue; // Restore interrupt enable
}
return 0;
}
void FLASH_EraseBlock(uint32_t baseAddr)
{
uint8_t GIEBitValue = INTCONbits.GIE; // Save interrupt enable
TBLPTRU = (uint8_t)((baseAddr & 0x00FF0000) >> 16);
TBLPTRH = (uint8_t)((baseAddr & 0x0000FF00)>> 8);
TBLPTRL = (uint8_t)(baseAddr & 0x000000FF);
EECON1bits.EEPGD = 1;
EECON1bits.CFGS = 0;
EECON1bits.WREN = 1;
EECON1bits.FREE = 1;
INTCONbits.GIE = 0; // Disable interrupts
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1bits.WR = 1;
INTCONbits.GIE = GIEBitValue; // Restore interrupt enable
}
 
It will be realy great if any body can help me to fix this issue 
#1

4 Replies Related Threads

    katela
    Super Member
    • Total Posts : 1757
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: online
    Re: problem with PIC18F45K80 Flash Write 2020/02/26 08:10:34 (permalink)
    +1 (1)
    Seems like a duplicate of this: https://www.microchip.com/forums/m1129630.aspx
     

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #2
    katela
    Super Member
    • Total Posts : 1757
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: online
    Re: problem with PIC18F45K80 Flash Write 2020/02/26 08:10:34 (permalink)
    0
    .

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #3
    jswanson
    Super Member
    • Total Posts : 367
    • Reward points : 0
    • Joined: 2003/11/07 12:44:05
    • Status: offline
    Re: problem with PIC18F45K80 Flash Write 2020/02/26 10:15:32 (permalink)
    0
    That looks like MCC code.   Perhaps you could show how you are calling the function?
    #4
    pcbbc
    Super Member
    • Total Posts : 1691
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: problem with PIC18F45K80 Flash Write 2020/02/27 03:25:42 (permalink)
    +2 (2)
    It would help if you described what "not working" means:
    1. What did you try? (e.g. how did you call the function)
    2. What did you expect to see?
    3. What test did you perform and with what equipment?
    4. What did you actually see?
    In fact, along with posting your complete code, these are basic rules of posting any "it's not working question"...
     
    Also please use [​code]//code tags[​/code] around your code when:
    //code tags

    #5
    Jump to:
    © 2020 APG vNext Commercial Version 4.5