View previous topic :: View next topic |
Author |
Message |
deonvds
Joined: 08 Sep 2003 Posts: 6
|
Save string to eeprom |
Posted: Wed Sep 17, 2014 3:48 am |
|
|
I am sending the following string from hyper terminal to PIC using rs232 port: 6709852345 and then write the data to an EEPROM. The process works but is very slow. I have to delay transmission by 40ms in order for all strings to be processed. Is there a faster method of writing the string data to EEPROM? The code I use is as follow
Code: |
#int_rda
void serial_isr()
{
buffer[next_in]=getc();
t=next_in;
next_in=(next_in+1) % BUFFER_SIZE;
if(next_in==BUFFER_SIZE)
next_in=0; // Buffer full !!
lead_in = 0xff;
var3 = 0xff;
var6 = 0xff;
if (t == 9)
{
var7 = chartohex(buffer[0]);
var8 = chartohex(buffer[1]);
lead_in = ((var7 << 4) + var8);
//BEGIN convert char waardes na hex waardes
//BEGIN EEPROM value
var1 = chartohex(buffer[2]);
var2 = chartohex(buffer[3]);
var3 = ((var1 << 4) + var2);
var4 = chartohex(buffer[4]);
var5 = chartohex(buffer[5]);
var6 = ((var4 << 4) + var5);
var9 = chartohex(buffer[6]);
var10 = chartohex(buffer[7]);
var11 = ((var9 << 4) + var10);
var12 = chartohex(buffer[8]);
var13 = chartohex(buffer[9]);
var14 = ((var12 << 4) + var13);
//END EEPROM value
//END convert char waardes na hex waardes
}
}
case 0x67: //write to chip j
{
address = make16(var3,var6); //address
write_ext_eeprom(address-1,var11);
write_ext_eeprom(address,var14);
putc(0x37);//7777777700
putc(0x37);
putc(0x37);
putc(0x37);
putc(0x37);
putc(0x37);
putc(0x37);
putc(0x37);
putc(0X30);
putc(0X30);
lead_in = 0xff;
break;
}
|
|
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed Sep 17, 2014 6:19 am |
|
|
don't write to EEPROM inside the ISR , you will lose characters!!
buffer the string to a VAR in the main program, and when idle, write to eeprom from MAIN.
go back to the original EX_SISR CCS examples folder,
which you have copied CODE wise
but damaged with the added EEPROM write attempt
just get the data in the ISR - do the rest in MAIN
PS: with the isolated CASE w/o SWITCH
this won't even compile!!!
such a mess you have here.....
how is this "the code you use " ???? |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Wed Sep 17, 2014 11:25 am |
|
|
Always keep interrupts as short as possible. This interrupt will be executed when a character is received. Grab that character and stuff it in a buffer. Exit the interrupt and THEN once all of the characters have been received and stuffed in that buffer process the string in main(). If you spend too much time doing 'things' while you're in the interrupt you will miss characters that will be coming.
Remember, grab one character and store it in a buffer so the interrupt can be ready to receive the next incoming character.
Ronald |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Sep 17, 2014 2:36 pm |
|
|
An additional note:
You didn't specify the PIC model you are using, but the typical erase+write time for a single byte in EEPROM is typical 3-4ms. See your datasheet for details.
Assuming 4ms, that equals about 250 characters/second or 2500baud. Most likely you are using faster baudrates and then some kind of buffering is required or you'll miss incoming data. |
|
|
|