Hi Steve or Ben
I have a problem with the eeprom component it dose NOT work with pic18f425
I checked the data sheet it has 256 bytes of EEporm memory in location ( F00000H TO F000Fh ).
NOTE : when simulating the hex file with ISIS PROTEUS works fine
but when downloaded to the microcontroller it does not work .
same programm works fine on pic16f devices so the problem is with pic18f devices only .
Any help will be greatly appreciated
Thanks in advance :
Regards , Alan cilia
EEPROM PROBLEM
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Hello Alan
Do you mean 18F452 because there isn't a 425 in the list. I have had a look at the C code generated by the EEPROM component in regards to this device but I cannot see any problem. The error will probably lie in the FCD file for the chip so I will have a dig through it if I get chance. Steve is away until monday but he will probably know a way to fix it.
Do you mean 18F452 because there isn't a 425 in the list. I have had a look at the C code generated by the EEPROM component in regards to this device but I cannot see any problem. The error will probably lie in the FCD file for the chip so I will have a dig through it if I get chance. Steve is away until monday but he will probably know a way to fix it.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
HI BEN
I don’t know much about C programming but since I desperately need this function to work I tried to find the problem my self and I think (hopefully) I found something .
This is an example from the datasheet of the PIC18f452 that sets the EECON1 REGISTER BEFORE READING FROM EEPROM MEMORY.
MOVLW DATA_EE_ADDR ;
MOVWF EEADR ; Data Memory Address to read
BCF EECON1, EEPGD ; Point to DATA memory
BCF EECON1, CFGS ; Access program FLASH or Data EEPROM memory
BSF EECON1, RD ; EEPROM Read
MOVF EEDATA, W ; W = EEDATA
And this is an example of c code from flowcode .
char FCD_EEPROM0_EEPROMRead(char addr)
{
//GetEEPROMReadCode
char data = 0;
#ifdef MX_EE
eeadr = addr;
#ifdef MX_EE_TYPE2
clear_bit(eecon1, EEPGD);
#endif
set_bit(eecon1, RD);
data = eedata;
#else
The BCF EECON1, CFGS OR clear_bit(eecon1,CFGS); is missing in the the bitsetting of eecon1 REGISTER .
bit 6 CFGS: FLASH Program/Data EE or Configuration Select bit
1 = Access Configuration or Calibration registers
0 = Access FLASH Program or Data EEPROM memory
BEN CAN THIS BE THE PROBLEM ????
I don’t know much about C programming but since I desperately need this function to work I tried to find the problem my self and I think (hopefully) I found something .
This is an example from the datasheet of the PIC18f452 that sets the EECON1 REGISTER BEFORE READING FROM EEPROM MEMORY.
MOVLW DATA_EE_ADDR ;
MOVWF EEADR ; Data Memory Address to read
BCF EECON1, EEPGD ; Point to DATA memory
BCF EECON1, CFGS ; Access program FLASH or Data EEPROM memory
BSF EECON1, RD ; EEPROM Read
MOVF EEDATA, W ; W = EEDATA
And this is an example of c code from flowcode .
char FCD_EEPROM0_EEPROMRead(char addr)
{
//GetEEPROMReadCode
char data = 0;
#ifdef MX_EE
eeadr = addr;
#ifdef MX_EE_TYPE2
clear_bit(eecon1, EEPGD);
#endif
set_bit(eecon1, RD);
data = eedata;
#else
The BCF EECON1, CFGS OR clear_bit(eecon1,CFGS); is missing in the the bitsetting of eecon1 REGISTER .
bit 6 CFGS: FLASH Program/Data EE or Configuration Select bit
1 = Access Configuration or Calibration registers
0 = Access FLASH Program or Data EEPROM memory
BEN CAN THIS BE THE PROBLEM ????

Last edited by ALAN_26 on Sun Jan 14, 2007 6:39 pm, edited 2 times in total.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Hello Alan
I think you may well have something there. If you just put your code into a C code block then you can stick it into a macro and call it whenever you need it. I will see what we can do this end to get the actual component code corrected.
Thanks for spotting the bug and hopefully providing the fix.
I think you may well have something there. If you just put your code into a C code block then you can stick it into a macro and call it whenever you need it. I will see what we can do this end to get the actual component code corrected.
Thanks for spotting the bug and hopefully providing the fix.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Hi Ben
I can confirm my last post , I managed to read from the eeprom by writing the c-code below , FCV_ROM_LOC is the location of the eeprom to acsess , and FCV_UPLOAD is where the data is going to output . .
eeadr = FCV_ROM_LOC ;
clear_bit(eecon1, EEPGD);
clear_bit(eecon1, CFGS);
set_bit(eecon1, RD);
FCV_UPLOAD = eedata ;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
There is also a problem in Writing to eeprom for the 18f devices in flowcode
According to the datasheet of pic18f452 page 69 example 6-2 the following code must be executed to write data to eeprom
MOVLW DATA_EE_ADDR ;
MOVWF EEADR ; Data Memory Address to read
MOVLW DATA_EE_DATA ;
MOVWF EEDATA ; Data Memory Value to write
BCF EECON1, EEPGD ; Point to DATA memory
BCF EECON1, CFGS ; Access program FLASH or Data EEPROM memory
BSF EECON1, WREN ; Enable writes
BCF INTCON, GIE ; Disable interrupts
MOVLW 55h ; Required Sequence
MOVWF EECON2 ; Write 55h
MOVLW AAh ; Required Sequence
MOVWF EECON2 ; Write AAh
BSF EECON1, WR ; Set WR bit to begin write
BSF INTCON, GIE ; Enable interrupts
BCF EECON1, WREN ; Disable writes on write complete (EEIF set)
So in c code I think it has to look something like this
eeadr = FCV_ROM_LOC ;
eedata = FCV_DOWNLOAD ;
clear_bit(eecon1,EEPGD);
clear_bit(eecon1,CFGS);
set_bit(eecon1,WREN);
clear_bit(intcon,GIE);
eecon2 = 0x55;
eecon2 = 0xaa;
set_bit(eecon1,WR);
set_bit(intcon,GIE);
clear_bit(eecon1,WREN);
AND A DELAY OF 50mS VERY IMPORTANT .
NOW I CONFIRM THIS WORKS 100% FOR PIC18F452 ( ie work perfectly when downloaded to the microcontroller )
NOTE: variables ROM_LOC & DOWNLOAD SHOULD BE ADDED BEFORE COMPILING .
HOPE THIS HELPS FOR THE FIX TOO
REGARDS ,
Alan cilia .
I can confirm my last post , I managed to read from the eeprom by writing the c-code below , FCV_ROM_LOC is the location of the eeprom to acsess , and FCV_UPLOAD is where the data is going to output . .
eeadr = FCV_ROM_LOC ;
clear_bit(eecon1, EEPGD);
clear_bit(eecon1, CFGS);
set_bit(eecon1, RD);
FCV_UPLOAD = eedata ;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
There is also a problem in Writing to eeprom for the 18f devices in flowcode
According to the datasheet of pic18f452 page 69 example 6-2 the following code must be executed to write data to eeprom
MOVLW DATA_EE_ADDR ;
MOVWF EEADR ; Data Memory Address to read
MOVLW DATA_EE_DATA ;
MOVWF EEDATA ; Data Memory Value to write
BCF EECON1, EEPGD ; Point to DATA memory
BCF EECON1, CFGS ; Access program FLASH or Data EEPROM memory
BSF EECON1, WREN ; Enable writes
BCF INTCON, GIE ; Disable interrupts
MOVLW 55h ; Required Sequence
MOVWF EECON2 ; Write 55h
MOVLW AAh ; Required Sequence
MOVWF EECON2 ; Write AAh
BSF EECON1, WR ; Set WR bit to begin write
BSF INTCON, GIE ; Enable interrupts
BCF EECON1, WREN ; Disable writes on write complete (EEIF set)
So in c code I think it has to look something like this
eeadr = FCV_ROM_LOC ;
eedata = FCV_DOWNLOAD ;
clear_bit(eecon1,EEPGD);
clear_bit(eecon1,CFGS);
set_bit(eecon1,WREN);
clear_bit(intcon,GIE);
eecon2 = 0x55;
eecon2 = 0xaa;
set_bit(eecon1,WR);
set_bit(intcon,GIE);
clear_bit(eecon1,WREN);
AND A DELAY OF 50mS VERY IMPORTANT .
NOW I CONFIRM THIS WORKS 100% FOR PIC18F452 ( ie work perfectly when downloaded to the microcontroller )
NOTE: variables ROM_LOC & DOWNLOAD SHOULD BE ADDED BEFORE COMPILING .
HOPE THIS HELPS FOR THE FIX TOO
REGARDS ,
Alan cilia .
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Thanks for your input Alan. I will look at the EEPROM code generation for Flowcode and modify the errors.
Cheers for your help.
Cheers for your help.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel