Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 161053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:08:40+00:00 2026-05-11T11:08:40+00:00

On an embedded system we have a setup that allows us to read arbitrary

  • 0

On an embedded system we have a setup that allows us to read arbitrary data over a command-line interface for diagnostic purposes. For most data, this works fine, we use memcpy() to copy data at the requested address and send it back across a serial connection.

However, for 16-bit hardware registers, memcpy() causes some problems. If I try to access a 16-bit hardware register using two 8-bit accesses, the high-order byte doesn’t read correctly.

Has anyone encountered this issue? I’m a ‘high-level’ (C#/Java/Python/Ruby) guy that’s moving closer to the hardware and this is alien territory.

What’s the best way to deal with this? I see some info, specifically, a somewhat confusing [to me] post here. The author of this post has exactly the same issue I do but I hate to implement a solution without fully understanding what I’m doing.

Any light you can shed on this issue is much appreciated. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:08:41+00:00Added an answer on May 11, 2026 at 11:08 am

    In addition to what Eddie said, you typically need to use a volatile pointer to read a hardware register (assuming a memory mapped register, which is not the case for all systems, but it sounds like is true for yours). Something like:

    // using types from stdint.h to ensure particular size values // most systems that access hardware registers will have typedefs // for something similar (for 16-bit values might be uint16_t, INT16U, // or something)  uint16_t volatile* pReg = (int16_t volatile*) 0x1234abcd;  // whatever the reg address is  uint16_t val = *pReg;  // read the 16-bit wide register 

    Here’s a series of articles by Dan Saks that should give you pretty much everything you need to know to be able to effectively use memory mapped registers in C/C++:

    • ‘Mapping memory’
    • ‘Mapping memory efficiently’
    • ‘More ways to map memory’
    • ‘Sizing and aligning device registers’

    • ‘Use volatile judiciously’

    • ‘Place volatile accurately’
    • ‘Volatile as a promise’
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 69k
  • Answers 69k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer stager's answer is correct. Though it should be noted that… May 11, 2026 at 12:26 pm
  • added an answer You could try your luck on the Visual Basic Decompilers… May 11, 2026 at 12:26 pm
  • added an answer There are a few options here. One is to redirect… May 11, 2026 at 12:26 pm

Related Questions

I worked on an embedded system this summer written in straight C. It was
I'm developing an embedded system which currently boots linux with console output on serial
I am working on a project that involves an embedded system which runs a
We have a number of embedded systems requiring r/w access to the filesystem which
On a small embedded system project we have some code which we would like
We are making a lab instrument using an ARM9/RTOS system. The client has asked

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.