• AVR Freaks

Helpful ReplyHot!Problem with EEPROM reading via EUSART

Author
dirfys
Super Member
  • Total Posts : 258
  • Reward points : 0
  • Joined: 2013/12/15 16:16:04
  • Location: Greece
  • Status: offline
2020/01/12 03:39:59 (permalink)
0

Problem with EEPROM reading via EUSART

I have connected the PIC16F1789 with the 25AA256 EEPROM. I'm measuring via ADC the temperature from a K-type thermocouple and I want to store its value (from 0 - 250 °C) at the EEPROM.
The last 2 bytes of the EEPROM (32.765 & 32.766) are used for the storage of the first free byte (from 0x0000 - 0x7FFB) after the last successful writing at the EEPROM and the output of EEPROM reading is stored via EUSART to a file (a PC is connected with the Serial interface at the PIC and I'm using the Realterm application to store the data in a file).
 
It's clear to me and obvious that a number from 0 to 250 can be written or read as it is (I mean without any conversion) at the EEPROM but what I haven't understood is how I can store the output of the EEPROM with EUSART as a raw number (from 0 to 250) and not as an ASCII.
What I have seen is the numbers 0 - 250 are interpreted as ASCII characters (by the Realterm or EUSART peripheral of PIC? I don't know) and the data are not stored as I would expect.
But the most weird behavior that I've seen when I read the EEPROM is that nothing is displayed at the EUSART when:
  1. either the last 2 bytes of the EEPROM (32.765 & 32.766) have stored a value (memory address) < 512 (0x00, 0x00 - 0x01, 0xFF). What I mean is that if any data are stored at the first 512 bytes of the EEPROM, they aren't displayed at the EUSART, unless only when stored value is > 512 where in this case all the bytes are displayed.
  2. or I read any other byte of the EEPROM where the data that are stored have some specific values in the range 0x00 - 0x1F (like 0x00, 0x01, 0x11, 0x13, etc.).
In other words, it seems that the EUSART interprets the values from 0x00 - 0x1F (the first 32 bytes which are the ASCII control characters) and it doesn't store them as raw numbers.
In the attached file each line contains the output of the last 18 bytes of EEPROM (32.750 - 32768). The square symbols  are the 0xFF and the last 2 bytes of the EEPROM (32.765 & 32.766) that have stored the memory address are the ones after the symbols [].
As you can see even if you toggle the HEX mode, the value is missing.
 
Do I miss something in the way that I should read the EEPROM and store it via EUSART?
#1
ric
Super Member
  • Total Posts : 25244
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: Problem with EEPROM reading via EUSART 2020/01/12 04:11:01 (permalink)
0
The USART doesn't care anything about the data values you send.
All your symptoms are probably due to Realterm. Try another terminal app.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#2
Mysil
Super Member
  • Total Posts : 3578
  • Reward points : 0
  • Joined: 2012/07/01 04:19:50
  • Location: Norway
  • Status: offline
Re: Problem with EEPROM reading via EUSART 2020/01/12 05:15:06 (permalink)
0
Hi,
You cannot give Raw integer values from EEPROM  to UART, and expect it to appear as ASCII text on PuTTY.
To make raw integer values be readable on PuTTY,
you should translate from integer variables that are binary values, into decimal ASCII digits,
before sending by UART to PuTTY.
 
You may do this in own code, by using division by 10, and modulus operator   %10, to calculate remainder from division, to calculate each decimal digit. Something like:
    uint8_t   units, tens, hund, temperature = 123;
 
    units = temperature % 10u;
    tens  = (temperature / 10u) % 10u;
    hund = temperature / 100u;  
 
/* Then convert from decimal digit to character by adding the ASCII value of digit character '0'  */
    char  character[4];
 
    character[0] = hund | '0';
    character[1] = tens  | '0';
    character[2] = units | '0';
    character[3] = 0;  

Then you may send each character thru UART to PuTTY.
 
Or you may use sprintf(...)  or  printf(...)  library functions to convert from integer value to printable text.
 
    Mysil
post edited by Mysil - 2020/01/12 05:23:25
#3
dirfys
Super Member
  • Total Posts : 258
  • Reward points : 0
  • Joined: 2013/12/15 16:16:04
  • Location: Greece
  • Status: offline
Re: Problem with EEPROM reading via EUSART 2020/01/13 02:03:27 (permalink)
0
Mysil
Hi,
You cannot give Raw integer values from EEPROM  to UART, and expect it to appear as ASCII text on PuTTY.

 
You are right for this, but what I want to do is to read the raw (HEX) format of the values on Putty (e.g. 0x00 --> 0 °C, 0x08 --> 8 °C, 0xC8 --> 200 °C, etc.). I don't want to display them directly in a readable format.
But as I have mentioned, the problem is that I cannot even see the values, for instance 0x00 or 0x08 and I think that they are interpreted (by Putty or UART) on what they supposed to do.
#4
Kabak
Starting Member
  • Total Posts : 71
  • Reward points : 0
  • Joined: 2014/07/30 03:47:55
  • Location: 0
  • Status: offline
Re: Problem with EEPROM reading via EUSART 2020/01/13 02:13:03 (permalink)
0
Hi
 
25AA256 working via USART ?
 
May be you should use MSSP module in SPI mode ?
post edited by Kabak - 2020/01/13 02:14:53
#5
ric
Super Member
  • Total Posts : 25244
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: Problem with EEPROM reading via EUSART 2020/01/13 02:13:47 (permalink)
0
Kabak
25AA256 working via USART ?
 
May be you should use MSSP module in SPI mode ?

You have not understood the question.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#6
ric
Super Member
  • Total Posts : 25244
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: Problem with EEPROM reading via EUSART 2020/01/13 02:15:49 (permalink)
0
dirfys
...
But as I have mentioned, the problem is that I cannot even see the values, for instance 0x00 or 0x08 and I think that they are interpreted (by Putty or UART) on what they supposed to do.

I already told you why.
Try https://sites.google.com/site/terminalbpp/
with the "hex" checkbox ticked.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#7
dirfys
Super Member
  • Total Posts : 258
  • Reward points : 0
  • Joined: 2013/12/15 16:16:04
  • Location: Greece
  • Status: offline
Re: Problem with EEPROM reading via EUSART 2020/01/14 16:56:12 (permalink)
0
I've used this terminal application and the result is the same like Putty or Realterm.
In the following photos, you can see the content of the EEPROM (in HEX format) for the following cases:
  • Empty EEPROM
  • A sequence of numbers starting from 0x01 - 0xFF is stored at the EEPROM.
  • A sequence of numbers starting from 0x00 - 0xFF is stored at the EEPROM. 
    The last two bytes have the memory address of the first free byte of the EEPROM.
     
    What I have noticed is that when the sequence of stored numbers doesn't contain the value 0x00 then the display of EUSART output is OK but in case that the value 0x00 is read by the EEPROM then the EUSART output isn't displayed correctly.
    When I read the EEPROM, I store all the values in a 16-element arrays and I send it via the EUSART as a string (and not as numbers). Could it be related with this strange behavior?
     



  • #8
    ric
    Super Member
    • Total Posts : 25244
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Problem with EEPROM reading via EUSART 2020/01/14 17:15:23 (permalink) ☄ Helpfulby dirfys 2020/01/16 04:52:58
    0
    dirfys
    When I read the EEPROM, I store all the values in a 16-element arrays and I send it via the EUSART as a string (and not as numbers). Could it be related with this strange behavior?

    A "string" in C is terminated by a NULL (0x00) character.
    You can't use string functions to handle raw data which can contain the value 0x00.
     
    Please show the actual code you are using if you don't know how to fix it.
     
    post edited by ric - 2020/01/14 17:30:56

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #9
    1and0
    Access is Denied
    • Total Posts : 10225
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Problem with EEPROM reading via EUSART 2020/01/14 18:05:39 (permalink)
    0
    dirfys
    When I read the EEPROM, I store all the values in a 16-element arrays and I send it via the EUSART as a string (and not as numbers). Could it be related with this strange behavior?

    As Ric said, a character string is terminated by a null character, which has a numeric value of 0. Also, a character string is typically consisted of ASCII characters. It will be lot funny when there is no 0 value in that array. LOL
     
    That being said, if you stored the values as an array, why the heck you did not send it out as an array?!!!
     
     
    post edited by 1and0 - 2020/01/14 18:06:43
    #10
    dirfys
    Super Member
    • Total Posts : 258
    • Reward points : 0
    • Joined: 2013/12/15 16:16:04
    • Location: Greece
    • Status: offline
    Re: Problem with EEPROM reading via EUSART 2020/01/16 01:45:47 (permalink)
    0
    At last, I found the "stupid" root cause of this behavior. I was using a routine which sends a string via EUSART and I hadn't noticed the "escape" condition.
    void EUSART_WriteString(const char *string_character)
    {
        while (*string_character)
        {
            EUSART_WriteByte(*string_character++);
        }
    }

     
    I replaced it with a 'for' loop and all the HEX values are displayed correctly now.
    Thank you all for your support.
    post edited by dirfys - 2020/01/16 12:42:10
    #11
    ric
    Super Member
    • Total Posts : 25244
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Problem with EEPROM reading via EUSART 2020/01/16 03:18:31 (permalink)
    0
    Indeed. That is how strings work in C.
    You should keep that function (for sending strings), and make a EUSART_WriteBuf" function that accepts a length count parameter.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #12
    dirfys
    Super Member
    • Total Posts : 258
    • Reward points : 0
    • Joined: 2013/12/15 16:16:04
    • Location: Greece
    • Status: offline
    Re: Problem with EEPROM reading via EUSART 2020/01/16 04:54:08 (permalink)
    0
    This is what I've done with a new function.
    #13
    Jump to:
    © 2020 APG vNext Commercial Version 4.5