No internal EEProm with use of bootloader

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
patrick schoon
Posts: 74
Joined: Mon Aug 23, 2010 7:07 pm
Location: Amsterdam
Has thanked: 7 times
Been thanked: 13 times
Contact:

No internal EEProm with use of bootloader

Post by patrick schoon »

Hi,

In my project (PIC16F18857) i use the internal eeprom for storing parameters.
All is working fine.

Now I added a bootloader, starting 0x00-0x6FF.
I shifted the application starting from 0x700.

This is working except for the internal eeprom.
I did some tests but all results are "0" when readout the eeprom.

All other functions do work like I2C, PWM, ADC.

Any one have an idee?

User avatar
tiny
Posts: 200
Joined: Wed Jul 08, 2009 8:29 am
Has thanked: 51 times
Been thanked: 93 times
Contact:

Re: No internal EEProm with use of bootloader

Post by tiny »

Hello Patrik,
according to the data sheet, the MCU has 256 bytes EEProm, so the addressing should go 0x00 to 0x6F and 0x70 to 0xFF.

Regards
Christina

User avatar
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:

Re: No internal EEProm with use of bootloader

Post by Benj »

Hello,
I shifted the application starting from 0x700.
Can you detail how you did this, if done incorrectly it may have also shifted the access to the EE memory.

patrick schoon
Posts: 74
Joined: Mon Aug 23, 2010 7:07 pm
Location: Amsterdam
Has thanked: 7 times
Been thanked: 13 times
Contact:

Re: No internal EEProm with use of bootloader

Post by patrick schoon »

Hi Christina,

Thanks for your input.
I'm aware of these data's.

Hi Ben,

I think this is the case.

I compiled my project with compiler offset parameter "--codeoffset=0x700".

Then i load my project with use of the bootloader into the project.

Configuration bits are the same for bootloader and application.
Bootloader uses no interrupts.

So from your words i understand i also need to set an offset for the eeprom....

I did some tests with monitoring the MPLAB IPE. No alterations are seen in the eeprom data. Totaly dead.

User avatar
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:

Re: No internal EEProm with use of bootloader

Post by Benj »

Hello,

The CODEOFFSET option should be enought to do everything correctly from memory. I've also done a bit of Googling but can't seem to find any documented issues with this.

Are you expecting the default EEPROM data to be programmed onto the device via the Bootloader? If so the bootloader code probably has to specifically look for this in your .hex file and perform this for you.

If you write a value to an EEPROM location in your program then can that be read back ok? You may have to create a first run type section of code in your program. i.e. check the first EEPROM location and if it is 0 then manually write the initial values to the EEPROM. Annoying but probably easier then editing the bootloader and loader application.

patrick schoon
Posts: 74
Joined: Mon Aug 23, 2010 7:07 pm
Location: Amsterdam
Has thanked: 7 times
Been thanked: 13 times
Contact:

Re: No internal EEProm with use of bootloader

Post by patrick schoon »

Hi Ben,

I also checked the Microchip datasheets and Googled to find answers, but did not find satisfying answers.

I programmed the eeprom for a few bytes with use of the MPlab IPE.
Also these values are not read by the program.

I made a LUT with the initial values for the eeprom.
The eeprom is checked for FF value at the last byte. If new the lut wil be programmed into the eeprom and the last byte wil be set.

All read, write and initiate eeprom mechanisms are working perfect if programmed from start address 0x00.

So at the moment we are looking into the bootloader firmware.

Should it help if i bypass the eeprom macro and use C- code?

Thanks for now.

User avatar
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:

Re: No internal EEProm with use of bootloader

Post by Benj »

Hello,

Hmm this is strange, looking at the code for the 16F18857 device we do use the NVM type code to access the EEPROM. This could potentially be being effected by the code shift which to me would possibly be a compiler bug.

Specifically these lines.

Code: Select all

NVMADRL = Address & 0xff;
NVMADRH |= 0xF0;
The code is located here.

C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\PIC\PIC_CAL_EEPROM.c

Functions below starting at line 140.

Code: Select all

		MX_UINT16 FC_CAL_EE_Read (MX_UINT16 Address)
		{
			MX_UINT16 data = 0;

			#ifdef MX_EE

				#if defined _NVMCON1_NVMREG_POSN
					NVMCON1bits.NVMREG = 0;					//EEPROM Access
				#elif defined _NVMCON1_NVMREGS_POSN
					NVMCON1bits.NVMREGS = 1;				//EEPROM Access
				#endif

				NVMADRL = Address & 0xff;

				#if (MX_EE_SIZE > 256)
					NVMADRH = (Address & 0xff00) >> 8;
				#endif

				#if defined (MX_EE_TYPE4)					//EE Memory starts at address 0xF000
					NVMADRH |= 0xF0;
				#endif

				NVMCON1bits.RD = 1;
				#if defined _NVMDAT_NVMDAT0_POSN
					data = NVMDAT;
				#elif defined _NVMDATL_NVMDAT0_POSN
					data = NVMDATL;
				#endif

				#if defined _NVMCON1_NVMREG_POSN
					NVMCON1bits.NVMREG = 2;					//FLASH Access
				#elif defined _NVMCON1_NVMREGS_POSN
					NVMCON1bits.NVMREGS = 0;				//FLASH Access
				#endif

			#else
				#error "Chip does not have EEPROM memory"
			#endif
			return (data);
		}

Code: Select all

		void FC_CAL_EE_Write (MX_UINT16 Address, MX_UINT16 Data)
		{
			#ifdef MX_EE

				char bInterruptsEnabled;

				//wait for previous EE writes to complete...
				while (ts_bit(NVMCON1, WR));

				#if defined _NVMCON1_NVMREG_POSN
					NVMCON1bits.NVMREG = 0;					//EEPROM Access
				#elif defined _NVMCON1_NVMREGS_POSN
					NVMCON1bits.NVMREGS = 1;				//EEPROM Access
				#endif

				NVMADRL = Address & 0xff;

				#if (MX_EE_SIZE > 256)
					NVMADRH = (Address & 0xff00) >> 8;
				#endif

				#if defined (MX_EE_TYPE4)					//EE Memory starts at address 0xF000
					NVMADRH |= 0xF0;
				#endif

				#if defined _NVMDAT_NVMDAT0_POSN
					NVMDAT = Data;
				#elif defined _NVMDATL_NVMDAT0_POSN
					NVMDATL = Data;
				#endif

				NVMCON1bits.WREN = 1;

				bInterruptsEnabled = ts_bit(INTCON, GIE);
				cr_bit(INTCON, GIE);			//Disable Interrupts

				NVMCON2 = 0x55;
				NVMCON2 = 0xAA;

				NVMCON1bits.WR = 1;

				while (ts_bit(NVMCON1, WR));		//wait for EE write to complete...

				if (bInterruptsEnabled)
					st_bit(INTCON, GIE);		//Re-enable Interrupts

				NVMCON1bits.WREN = 0;

				#if defined _NVMCON1_NVMREG_POSN
					NVMCON1bits.NVMREG = 2;					//FLASH Access
				#elif defined _NVMCON1_NVMREGS_POSN
					NVMCON1bits.NVMREGS = 0;				//FLASH Access
				#endif

			#else
				#error "Chip does not have EEPROM memory"
			#endif
		}

patrick schoon
Posts: 74
Joined: Mon Aug 23, 2010 7:07 pm
Location: Amsterdam
Has thanked: 7 times
Been thanked: 13 times
Contact:

Re: No internal EEProm with use of bootloader

Post by patrick schoon »

Hi Ben,

For now I did a read test by adding an address read commando in C.
Test.jpg
Test.jpg (44.84 KiB) Viewed 3861 times
This works and to my suprise all values read by the eeprom macro are read as well.

To check why, i only put the "NVMADRH = 0x70" in the C-code at the beginning of the sequence and the eeprom read function does work.
There must be something going wrong with the address high byte in the macro..

Regards,

PS

patrick schoon
Posts: 74
Joined: Mon Aug 23, 2010 7:07 pm
Location: Amsterdam
Has thanked: 7 times
Been thanked: 13 times
Contact:

Re: No internal EEProm with use of bootloader

Post by patrick schoon »

Hi,

I solved my issues with the epprom by using replacing the eeprom macro by two C- macro's.

A read macro named NVMRead and a write macro named NVMWrite.
NVMRead.fcm
(778 Bytes) Downloaded 162 times
NVMWrite.fcm
(1.23 KiB) Downloaded 156 times
Both macro's do use the Address Hi byte (0xF0 for eeprom) as well.
Advantage to this is that also the User, Revision and Device ID can be read and writen (0x80).
PIC16F18857_NVM.png
(96.97 KiB) Downloaded 400 times

Post Reply