1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

EEPROM storage of Single variable

Discussion in 'Oshonsoft' started by Roger Harrold, Oct 20, 2016.

  1. Roger Harrold

    Roger Harrold New Member

    Joined:
    Dec 11, 2013
    Messages:
    15
    Likes:
    1
    I'm using a Single (floating point) value as a calibration constant.
    Does anyone know how to store the 4-byte value in EEPROM and
    how to read it back?
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    8,776
    Likes:
    848
    Location:
    Rochdale UK
    In C I use a union... I should imagine you could use the pointer function to traverse the 4 bytes..

    Vladimir MUST have given this functionality surely!!

    I'll have a go at it now..
     
  3. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    8,776
    Likes:
    848
    Location:
    Rochdale UK
    It worked

    Using the pointer like so..
    Code (basic):

    Dim eep As Byte  'eeprom address
    Dim data As Byte
    Dim floater As Single @ 0x30
    Dim addr As Word  'ram address
    addr  = 0x30
    floater = 123.456
    main:
       For eep = 0 To 3
         data = Pointer(addr)
         Write eep, data
         addr =addr + 1
       Next eep
       floater = 0
       addr = 0x30
       For eep = 0 To 3
         Read eep, data
         Pointer(addr) = data
         addr = addr + 1
       Next eep    
         
    Goto main  'go again
     
    You have to declare the single in ram specifically so you can set the address..
     

Share This Page