Continue to Site

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.

[PIC] Store continuous string of data in EEPROM of pic16f887

Status
Not open for further replies.
I can provide the code. But for the beginer is will be unreadable. No point to help such way I suppose.
Only think I can propose is to use pointers and unions. For exaple, if you need to store signed int value as array of bytes you can declare it as the union. Save values as int and read as chars.
 

Suggestion:

I have a system here that talks data between several units spaced over a distance of several hundred metres. It carries variable length packets between one byte of data and 32 bytes maximum. I start each block with an ASCII 'STX' character (0x02 in hexadecimal) and end it with a 'CR' character (0x0D in hexadecimal) as both are not part of the normal numbers or letters used in text. It has carried over 32Gb of data so far with zero errors so it obviously works OK!

It links several PICs, ranging from a 16F628A to an 18F46J11 and doesn't use any EEPROM for storing the data while it is being processed. It does use EEPROM in several of the PICs for storing configuration settings but that only gets update very occasionally, maybe once a year.

Why not do it that way, it gives you extra flexibility of data length, avoids the clash of command and data bytes and it uses no EEPROM at all. The link runs at 38.4Kb/s along RS422 data lines using CAT-5 cable, the remaining wires in the cable carry power and ground to the PICs in the network so it can all be powered from one central point.

Brian.
 

Come on guys i have told you everything though you are telling me "First you just u need to decide your specifications.
Follow our recommendations. Answer our questions. Give precise and detailed informations." You just see my every post in this there is nothing remain to clarify.
You just say how can i store integer string in eeprom. After compliting internal eeprom how can i move on to external eeprom 24c08 and store remaining string over there.
 

Hi,

there is nothing remain to clarify.
You really think so?

Then I need to clarify my statement:
It should be: First you just u need to decide and tell us your specifications.

From my post#2:
* hardware:
You didn't show us. But microcontroller, Eeprom, signal lines are clear somehow, at least as long as you keep on standard connections.
* Uart communication protocol:
It is far away from beeing specified, at least you didn't show us. Start of frame, command(format, range) , parameters(format, range), end of frame...none is defined. (I recommend to read other communication protocol soecifications, to see how others do this, what to take care of, what has to be defined....and maybe you find a protocol that suits your needs. )
Sooner or later the receiver will receive an erroneous byte, a frame with missing start, a frame with missing end, a frame with missing data. If you want to avoid that your application hangs in such a case or if you want to avoid that all the Eeprom data become corrupt, then you need to decide how to handle these errors, how to make it immune against communication errors. I.e. how to process the incoming datastream.
Do you start to write data to the Eeprom immediately after the first data is received, or do you wait until the complete frame is received?
Maybe you need to add a checksum, maybe you need to define timeouts. It's on you to decide this...and for sure to tell us.

You want someone to help you write the code. Don't expect someone writes the complete code for you.
So you should show what you have done so far, show us your ideas. Show us that you recognize this is your job, not our job. At least a program flow, as simple pencil draw on a sheet of paper.

Maybe you recognize that all this is just about Uart protocol. I don't want to talk about all the other (folowing) tasks, because you should learn to finish one task first, before starting the next. Don't try to build the whole world at once, this will fail.

Klaus
 

Ok, glad to help then. Take and use :laugh:
Code:
char EEPROM_RW (EEPROM_StructTypeDef * EEPROM)
{
	char m_adrs[2], Result = 0, BytesToHandle;
	
	/* Calculate start address */
	m_adrs[1] = (char)EEPROM->Mem_adrs;
	m_adrs[0] = (char)(EEPROM->Mem_adrs >> 8);
	
	/* Calculate bit mask */
	BytesToHandle = m_adrs[0] & (EEPROM->PageSize - 1);
	
	/* Apply bit mask. If first part of page exist */
	if (BytesToHandle)
	{
		if (EEPROM->isWriting)
		{
			/* Perform writing */
			Result = EEPROM->WritePage(EEPROM->I2C_Adrs, m_adrs, 2, EEPROM->buf, BytesToHandle);
			EEPROM->delay_func(EEPROM->PageWriteTime);
		}
		else
			/* Perform reading */
			Result = EEPROM->ReadPage(EEPROM->I2C_Adrs, m_adrs, 2, EEPROM->buf, BytesToHandle);
		
		EEPROM->size -= BytesToHandle;
		EEPROM->Mem_adrs += BytesToHandle;
	}
	if (!EEPROM->size || Result) return Result; //nothing to write any more

	/* Reading or Writing full pages */
	do
	{
		if (EEPROM->isWriting)
		{
			/* Perform writing */
			Result = EEPROM->WritePage(EEPROM->I2C_Adrs, m_adrs, 2, EEPROM->buf, EEPROM->PageSize);
			EEPROM->delay_func(EEPROM->PageWriteTime);
		}
		else
			/* Perform reading */
			Result = EEPROM->ReadPage(EEPROM->I2C_Adrs, m_adrs, 2, EEPROM->buf, EEPROM->PageSize);
		
		/* Calculate new offset */
		EEPROM->buf += EEPROM->PageSize;
		EEPROM->size -= EEPROM->PageSize;
		EEPROM->Mem_adrs += EEPROM->PageSize;
		m_adrs[1] = (char)EEPROM->Mem_adrs;
		m_adrs[0] = (char)(EEPROM->Mem_adrs >> 8);		
		
	}while(EEPROM->size >= EEPROM->PageSize);
	
	if (!EEPROM->size) return Result; //nothing to write any more
	
	/* Read or write the rest of data */
	if (EEPROM->isWriting)
	{	
		/* Perform writing */
		Result = EEPROM->WritePage(EEPROM->I2C_Adrs, m_adrs, 2, EEPROM->buf, EEPROM->size);
		EEPROM->delay_func(EEPROM->PageWriteTime);
	}
	else
		/* Perform reading */
		Result = EEPROM->ReadPage(EEPROM->I2C_Adrs, m_adrs, 2, EEPROM->buf, EEPROM->size);
			
	return Result;
}
Code:
typedef struct
{
	/* Data */
	int Mem_adrs;
	char * buf;
	int size;
	
	/* Functions */
	char (*WritePage)(char I2C_Adrs, char * MemPos, char MemPosSize, char * buf, char size);
	char (*ReadPage) (char I2C_Adrs, char * MemPos, char MemPosSize, char * buf, char size);	
	void (*delay_func)(unsigned int ms);
	
	/* Settings */
	char I2C_Adrs;
	char PageSize;
	char PageWriteTime;
	char isWriting;
}EEPROM_StructTypeDef;
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top