[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Variables in external SRAM

From: Larry Barello
Subject: Re: [avr-gcc-list] Variables in external SRAM
Date: Mon, 12 Feb 2001 20:51:38 -0800

You were trying to change the address of an already declared
variable, test.  Instead, Test should be a *pointer* to the
variable you want to change:

    char *test;  // Declare a pointer to a char
    test = (char *)0xFFFF; // Set that pointer to 0xFFFF;
    *test = 0xEE;        // Now set the char pointed to by
the pointer to 0xEE

However, the way you did do it
    *(char*)0xFFFF = 0xEE;
would be the prefered way to deal with memory mapped i/o,
unless you i/o device has several registers and accessing it
via a pointer to a structure would be more efficient.  The
GCC compiler is *very* good when dealing with pointers to
things.  It is hard to hand write better code.  E.g.

typedef struct
    char data;
    char control;    // Control register
    char foo;    // i/o device internal buffer

myIOdevice *dev = 0x345E;    // declare a pointer to base of
io device
dev->control = 0x34;        // Set control register
dev->data = 0x00        // Clear data register
if (dev->foo)            // Read/test foo register ...



----- Original Message -----
From: "Peter" <address@hidden>
To: <address@hidden>
Sent: Monday, February 12, 2001 10:48 AM
Subject: [avr-gcc-list] Variables in external SRAM

> Hi,
> i have an external device that i can treat a sram, and i
want to write to
> it via a variable. But my compiler complains when i try
something like
> this:
> char test;
> &test = 0xFFFF;
> i know i can do
> *(char*)(0xFFFF) = 0xAB;
> but i want to write to a variable.
> I'm not good in programming  c code, but the code above
> "value of the char pointer with the address 0xFFFF", is
this right?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]