Hot!Internal EEPROM and EUSART

Page: < 12 Showing page 2 of 2
Author
Kdt
New Member
  • Total Posts : 23
  • Reward points : 0
  • Joined: 2018/04/04 07:13:26
  • Location: 0
  • Status: offline
Re: Internal EEPROM and EUSART 2018/10/09 02:49:45 (permalink)
0
why unknown? 
number_count is declared and initialized to 0
 
#21
qhb
Superb Member
  • Total Posts : 7097
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: Internal EEPROM and EUSART 2018/10/09 02:53:05 (permalink)
+1 (1)
Kdt
why unknown? 
number_count is declared and initialized to 0

Presumably in some code that you have not shown us.
 

Worst forum problems are now fixed, but the damn firewall is still there.
#22
Kdt
New Member
  • Total Posts : 23
  • Reward points : 0
  • Joined: 2018/04/04 07:13:26
  • Location: 0
  • Status: offline
Re: Internal EEPROM and EUSART 2018/10/09 03:00:19 (permalink)
0
it is in the first code i posted :
 
#include "mcc_generated_files/mcc.h"
 
unsigned char temp;
uint16_t eeprom_address, write_char;
unsigned long read_char ;
unsigned long number_count = 0;
#23
qhb
Superb Member
  • Total Posts : 7097
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: Internal EEPROM and EUSART 2018/10/09 03:05:09 (permalink)
0
Which post contains that code?
 

Worst forum problems are now fixed, but the damn firewall is still there.
#24
Gerald1
Super Member
  • Total Posts : 320
  • Reward points : 0
  • Joined: 2009/05/12 06:50:37
  • Location: Wien, Austria
  • Status: offline
Re: Internal EEPROM and EUSART 2018/10/09 03:36:07 (permalink)
0
Kdt
Hi all,
 
I am having some trouble to keep my internal eeprom memory. i am using :
 
       - PIC18f47k40 , and
       - MCP2200 (UART to USB converter) 
       - XC8 compiler v2.00
       - MCC for memory and eusart configuration .
 
I am switching on/off a Led on my system by pressing a touch of my keyboard and i create a counter which will be incremented when the Led is ON (1) and i want the value of the counter to be kept in the internal eeprom and i want to display this value on my terminal (CoolTerm) wherever i want by touching another keyboard touch
This works but when i cut off  the supply voltage my counter value is not kept, the value of the counter restarts to 1 ... so my question is : is there a way to keep my value in the internal eeprom even if my system is not supplied? 
 
here is my code :
 
void EUSART_Demo_Command_INT(void) 
{
    if(eusart1RxCount!=0)
    {
       
        temp=EUSART1_Read(); // read a byte for RX
        EUSART1_Write(temp); // send a byte to TX (from Rx)
       

    switch(temp) // check command
    {
     case 'H':
     case 'h':
        {
            LED_SetHigh();
            printf(" -> LED On!! \r");
            number_count++;
            DATAEE_WriteByte(eeprom_address,number_count);
            
            break;
        }
     case 'L':
     case 'l':
        {
            LED_SetLow();
            printf(" -> LED Off!! \r");
            break;
        }
     
     case 'A':
     case 'a':
        {
            printf("\r\nCompiled on %s at %s UTC by XC8 version %u\r\n",
            __DATE__, __TIME__, __XC8_VERSION);
            printf("UART Communications 8-bit Rx and Tx\r\n\n");
            printf("Keyboard Type H : LED ON Type E : EEPROM Type L: LED OFF \r\n\n\n");
            
            break;
        }
     
     case 'e':
     case 'E':
        {
            read_char = DATAEE_ReadByte(eeprom_address);
            printf("\rEeprom read : %i ", read_char);
            
            break;
        }
     
     default:
        {
            printf(" -> Fail Command!! \r");
            break;
        }
    }
    }
    }
    
/**
 End of File
 */

 
Thanks everyone for your help! 


How do you cut off the supply voltage? via hardware, power switch, or via software?
Do you check the content in the EEPROM before shut down?
Also after restarting the system, do you check the content of the EEPROM, also if empty or full?
I think, you need to store also the counter values in the EEPROM, because just storing in the RAM it will be lost of all, except you use a battery.
 

SG
---
Daily the PC greets:
"Press Enter!"; "Coward!"
---

#25
Kdt
New Member
  • Total Posts : 23
  • Reward points : 0
  • Joined: 2018/04/04 07:13:26
  • Location: 0
  • Status: offline
Re: Internal EEPROM and EUSART 2018/10/09 03:48:38 (permalink)
0
How do you cut off the supply voltage? via hardware, power switch, or via software?
 via hardware, i just take off the usb cable which supply the system.
Do you check the content in the EEPROM before shut down?
 Yes, the value in numb_counter is incremented
Also after restarting the system, do you check the content of the EEPROM, also if empty or full?
the eeprom is empty
I think, you need to store also the counter values in the EEPROM, <--- that's what my code is suppose to do... 
#26
1and0
Access is Denied
  • Total Posts : 8391
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Internal EEPROM and EUSART 2018/10/09 04:31:08 (permalink)
+2 (2)

uint16_t eeprom_address, write_char;
 
unsigned long read_char ;
unsigned long number_count = 0;
 
number_count++;
DATAEE_WriteByte(eeprom_address,number_count);

read_char = DATAEE_ReadByte(eeprom_address);
printf("\rEeprom read : %i ", read_char);

void DATAEE_WriteByte(uint16_t bAdd, uint8_t bData)
 
uint8_t DATAEE_ReadByte(uint16_t bAdd)


  • Has variable eeprom_address been given the same value for both write and read?
  • The variable number_count is unsigned long type, but the write function writes only uint8_t.
  • The variable read_char is unsigned long type, but the read function returns only uint8_t and the format specifier %i is for a signed int.
  • What value is your configuration bit WRTD?
#27
Kdt
New Member
  • Total Posts : 23
  • Reward points : 0
  • Joined: 2018/04/04 07:13:26
  • Location: 0
  • Status: offline
Re: Internal EEPROM and EUSART 2018/10/09 04:51:14 (permalink)
0
  • Has variable eeprom_address been given the same value for both write and read?
         ---> Yes
  • The variable number_count is unsigned long type, but the write function writes only uint8_t.
         ---> my mistake, i changed "number_count" to uint8_t
  • The variable read_char is unsigned long type, but the read function returns only uint8_t and the format specifier %i is for a signed int.
        --->I updated my code since the first post... i changed read_char to uint8_t and the format is now %u
  • What value is your configuration bit CPD? 
       --> // CONFIG5L
       #pragma config CP = OFF // UserNVM Program Memory Code Protection bit->UserNVM code protection disabled
        #pragma config CPD = OFF // DataNVM Memory Code Protection bit->DataNVM code protection disabled
#28
1and0
Access is Denied
  • Total Posts : 8391
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Internal EEPROM and EUSART 2018/10/09 05:01:14 (permalink)
0
I edited my previous post to inquire about the config bit WRTD. ;)
 
#29
Kdt
New Member
  • Total Posts : 23
  • Reward points : 0
  • Joined: 2018/04/04 07:13:26
  • Location: 0
  • Status: offline
Re: Internal EEPROM and EUSART 2018/10/09 05:04:40 (permalink)
0
I edited my previous post to inquire about the config bit WRTD. ;)
 
#pragma config WRTD = OFF    // Data EEPROM Write Protection bit->Data EEPROM not write-protected
 
Here it is, not write protected... by defaults i did not put any protection write... 
post edited by Kdt - 2018/10/09 05:07:01
#30
jtemples
Super Member
  • Total Posts : 10938
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: Internal EEPROM and EUSART 2018/10/09 10:00:23 (permalink)
+2 (2)
Going back to post #8:
 
i cut off the supply voltage with a value in "number_count"( different of 0) and when i put on the supply voltage again the value in "number_count" is 0

 
The OP still has not addressed the fact that no value is ever assigned to number_count in any of the posts on this thread.
 
#31
qhb
Superb Member
  • Total Posts : 7097
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: Internal EEPROM and EUSART 2018/10/09 12:11:26 (permalink)
+1 (1)
jtemples
...
The OP still has not addressed the fact that no value is ever assigned to number_count in any of the posts on this thread.

Except post#23, where he claims it was in the "first code he posted", but it's not.

Worst forum problems are now fixed, but the damn firewall is still there.
#32
Kdt
New Member
  • Total Posts : 23
  • Reward points : 0
  • Joined: 2018/04/04 07:13:26
  • Location: 0
  • Status: offline
Re: Internal EEPROM and EUSART 2018/10/09 23:41:03 (permalink)
0
Hello everyone,
 
Here is my full code, may be you'll notice something i didn't notice,  for a reminder, all i want to do is to increment the value of "number_count" everytime the led gets high and i want to keep the value of number_count in the internal eeprom of the microcontroller -->PIC8F47K40( cfr EUSART_DEMO.c) am using the  MCP2200 for serial communication and coolterm terminal  to display my values.
 
thanks for your help
post edited by Kdt - 2018/10/09 23:47:34
#33
jtemples
Super Member
  • Total Posts : 10938
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: Internal EEPROM and EUSART 2018/10/10 10:34:28 (permalink)
+1 (1)
So you do read EEPROM into number_count, but only when a certain byte is received on the UART.  Are you sure that byte is being received?
#34
jtemples
Super Member
  • Total Posts : 10938
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: Internal EEPROM and EUSART 2018/10/10 10:39:20 (permalink)
+1 (1)
 
uint16_t eeprom_address = 0x310000

 
This doesn't do what you're expecting, but it happens to work by chance.
#35
CDS
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2018/09/27 22:20:44
  • Location: 0
  • Status: offline
Re: Internal EEPROM and EUSART 2018/10/10 12:00:24 (permalink)
+1 (1)
Keeping values without power is the deeper sense of EEPROM cells, otherwise they where RAM.
As a hint, i'm pretty sure that your eeprom perfectly holds it's content just until the moment
when you apply power again.
 
update..
 
At a second glimpse,
1st: At startup, i don't see any code where you update counter from eeprom before you further increment it.
2nd: You declare your counter as a variable located in eeprom. Are you aware that C by convention initialize
        any variables to zero before your code executes? No matter where they are located.
 
post edited by CDS - 2018/10/10 12:25:35
#36
davekw7x
Entropy++
  • Total Posts : 1529
  • Reward points : 0
  • Joined: 2012/01/16 12:01:07
  • Location: Left Coast, USA
  • Status: offline
Re: Internal EEPROM and EUSART 2018/10/10 18:26:00 (permalink)
+1 (1)
CDS
...,
1st: At startup, i don't see any code where you update counter from eeprom before you further increment it.

Spot on!
 
CDS
2nd: You declare your counter as a variable located in eeprom.

 
Huh? I see this
uint8_t number_count;

It's in RAM.
As you alluded to, the C standard requires file scope variables that are declared/defined without an initializer list to be initialized to zero. 
 
To the OP: The number_count variable will be initialized to zero every time the MPU is reset  (with a Hardware reset, a software reset or a power cycle or brownout reset).  Every time.  If that's what you want, OK.  If you want to use the previous value written to EEPROM, put a statement in the initialization function to read EEPROM into number_count.
 
Finally, to the OP: What's up with this?
            number_count = DATAEE_ReadByte(eeprom_address);
            printf("Eeprom read : %u \r", read_char);

 
I don't see any place in the program where you show the contents of EEPROM.
 
Regards,
 
Dave
post edited by davekw7x - 2018/10/10 18:27:56

Sometimes I just can't help myself...
#37
Kdt
New Member
  • Total Posts : 23
  • Reward points : 0
  • Joined: 2018/04/04 07:13:26
  • Location: 0
  • Status: offline
Re: Internal EEPROM and EUSART 2018/10/15 00:14:59 (permalink)
0
Hello, 
 
Thanks everyone for your help, finally i found out what i was doing wrong,i wrote the adress of the eeprom memory with more bytes than it can handle... (0x310000), after several temptation the starting  adress will be 0x0000 and with this modification my value is kept in the eeprom evenif i cut the power supply.
 
But i have another issue, i can only write from 0 to 255 i think it comes from the NVMDAT register which holds the data only on 8 bits : 
 
Here is a part from the datasheet : 
"The data EEPROM allows byte read and write. When interfacing to the data memory block, 11.5.4
NVMDAT holds the 8-bit data for read/write and the 11.5.3 NVMADR register holds the address of the
EEPROM location being accessed."
 
i was wondering if someone can give me an advice on how to holds my value on 32 bits if possible... because i want to write from 0 to 5000000...
 
 
P.S : @ Dave
Finally, to the OP: What's up with this?
            number_count = DATAEE_ReadByte(eeprom_address);
            printf("Eeprom read : %u \r", read_char);
 
I don't see any place in the program where you show the contents of EEPROM. 
 
it was a  mistake ,  actually in my program it is :
 
            number_count = DATAEE_ReadByte(eeprom_address);
            printf("Eeprom read : %u \r", number_count);



Thanks everyone for your help
#38
qhb
Superb Member
  • Total Posts : 7097
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: Internal EEPROM and EUSART 2018/10/15 00:57:36 (permalink)
+1 (1)
32 bits is four bytes, so you will have to use four sequential locations to store each 32 bit value.
 

Worst forum problems are now fixed, but the damn firewall is still there.
#39
Kdt
New Member
  • Total Posts : 23
  • Reward points : 0
  • Joined: 2018/04/04 07:13:26
  • Location: 0
  • Status: offline
Re: Internal EEPROM and EUSART 2018/10/15 01:01:21 (permalink)
0
thanks qhb,
 
"32 bits is four bytes, so you will have to use four sequential locations to store each 32 bit value. "
 
I am not sure to know how to do that, may i ask for an exemple??
#40
Page: < 12 Showing page 2 of 2
Jump to:
© 2018 APG vNext Commercial Version 4.5