This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

problem of writing a long int in the SDRAM with a pointer

Hi,

I work with an LPC3250 board. i try to write a "long int" value into the SDRAM at address X through a "long int *" pointer. but the value will be written at address (X-2). if I write into the RAM in the same way or if write the value Byte by Byte into the SDRAM there are no problems detected.
Any help would be extremely appreciated

Parents
  • In all likelihood the address X is not aligned to a four-byte boundary. This is called unaligned access. The behaviour you are seeing is to be expected.
    Depending on what you are trying to do, there different ways of dealing with the problem:
    a) Do not create unaligned data.
    b) If a) can't be avoided, access the data in smaller chunks (bytes, half-words).
    c) If a) can't be avoided, use compiler extensions to access unaligned data (the packed keyword). Naturally, this will limit portability.

Reply
  • In all likelihood the address X is not aligned to a four-byte boundary. This is called unaligned access. The behaviour you are seeing is to be expected.
    Depending on what you are trying to do, there different ways of dealing with the problem:
    a) Do not create unaligned data.
    b) If a) can't be avoided, access the data in smaller chunks (bytes, half-words).
    c) If a) can't be avoided, use compiler extensions to access unaligned data (the packed keyword). Naturally, this will limit portability.

Children