|
|
View previous topic :: View next topic |
Author |
Message |
schmez
Joined: 14 Jun 2011 Posts: 24 Location: St. Louis
|
Write to EEPROM, program stops |
Posted: Tue Sep 20, 2011 9:16 am |
|
|
I am trying to read an address from RS232 and write the information to EEPROM. Everything works great until I do the write routine. The program calls the BT_WRITE routine and the routine returns correctly and processes the last statement - ouput_low(PIN_C2) and then seems to hang. I power cylce the CPU and all works fine again until I execute the BT_WRITE() routine.
I think I must be doing something wrong in string handling - but the routine writes the correct data to EEPROM as expected.
Appreciate any comments or thoughts.
Thank you,
Jeff
Last edited by schmez on Wed Sep 21, 2011 7:00 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Tue Sep 20, 2011 2:36 pm |
|
|
There are several things that could be causing problems.
First, use the UART. Pin B5, is the UART RX pin, and B7 the UART TX pin. Several of the settings in your RS232, only apply with the hardware UART, and with the software UART, unless you 'poll' the serial line at least every 0.05mSec, data _will_ be lost (0.5 bit time or faster).
Now, writing the EEPROM, takes a long time. Typically 5mSec/byte. Your 20 bytes will take typically 0.1second to write. Unless you stop the incoming serial while this is happening, or use an interrupt driven serial buffer and the hardware UART, data _will_ be lost. With the software UART, unless there are significant gaps in the incoming data, it'll not then resynchronise, and you will never then see 'good' data again.
It actually takes five times as long to write a sequence of bytes to the EEPROM, as receive them over the RS232 at 9600bps. Is there a gap in the data to allow for this?.
Then have you looked at the EEPROM life?. If this sequence is happening at all frequently, 'think again'....
Best Wishes
Best Wishes |
|
|
schmez
Joined: 14 Jun 2011 Posts: 24 Location: St. Louis
|
Response |
Posted: Tue Sep 20, 2011 3:15 pm |
|
|
Thank you for your reply. I will try B5 and B7 and see if that helps. This happens infrequently - once the address is received and written it is a long time if ever that it has to be done again. There is significant time after the message comes in - matter of fact there is nothing after the message once it arrives.
It is just weird as the software appears to work but once I do the write routine the software returns to the main properly and turns off the pin but the While (TRUE) statement just seems to end - it does not go back to the top of the program. |
|
|
schmez
Joined: 14 Jun 2011 Posts: 24 Location: St. Louis
|
Still having issues writing strings to EEPROM |
Posted: Thu Sep 22, 2011 8:00 am |
|
|
Anyone have an example of how to successfully write a string of characters to eeprom? This snippet does but it seems to trash memory - have to power cycle after doing it.
Any examples would be appreciated.
void BT_WRITE()
{
output_high(PIN_C2); //Turn on WRITE LED
gets(BTPAIR_ADR); //Get string
if (RS232_ERRORS == 0) //Timeout (10sec) occurs - no string
{
return;} //exit write mode
BTPAIR_ADR[29] = '\0'; //add null to end of string
strncpy (BTPAIR_MEM_STC_BW, BTPAIR_ADR, 24); //copy first 24 characters
for(i = 4; i < 23; i++)
{
write_eeprom(i,BTPAIR_MEM_STC_BW[i]);
}
i++;
*i = '\0'; //add null to end of string
}
return; |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|