I don't believe the ARM has bit access instructions. So when the
compiler reads the ioset register (or a byte of it?) according to
the datasheet you will read what was previously written. So you
risk setting unwanted pins (likely).
James
--- In lpc2000@yahoogroups.com, Leonardo Santos <lsantos@p...> wrote:
> Hello All:
> I'm working with a LPC2106 using the GCC 3.4.4 toolchain
(GCC + binutils 2.15
> + newlib 1.13). I wrote a union and a structure to access
the P0 pins
> individually, like this:
>
> typedef struct {
> int p0 : 1;
> int p1 : 1;
> int p2 : 1;
> (...)
> int p30 : 1;
> int p31 : 1;
> }port_t;
>
> typedef union {
> port_t pins;
> unsigned int reg;
> } ioreg;
>
> typedef struct {
> ioreg iopin;
> ioreg ioset;
> ioreg iodir;
> ioreg ioclr;
> }gpio_t;
>
> So I declare a pinter like
>
> volatile gpio_t *gpio = 0xE0028000;
>
> If I access the registers using
>
> if( gpio->iopin.reg & 0x01 )
>
> or
>
> gpio->ioset.reg |= 0x00008000;
>
> Everithing works fine! But if I try a code like this:
>
> gpio->ioset.pins.p15 = 1;
>
> To set P0.15, P0.23 and P0.31 are set too! I had tried this code
in my Linux
> workstaion and it works just fine. The compiles setting I'm using
are
>
> arm-elf-gcc -c -Wall -D GCC_ARM7 -mcpu=arm7tdmi -Tlpc2106-rom.ld -
Wcast-align
> -O3
>
> So I'm compiling it in ARM mode. Any clues? Is this a compiler
issue ( I'm not
> using the right parameters)?
>
> Thanks a lot!
>
> --
> This is Linux country.
> On a quiet night, you can hear Windows reboot.
>
> Leonardo Pereira Santos
> Engenheiro de Projetos
> PD3 Tecnologia
> av. ParĂ¡ 330/202
> (51) 3337 1237
>
> Today Fortune tells us:
> The most important service rendered by the press is that of
educating
> people to approach printed matter with distrust.Message
Re: C union not working
2005-03-19 by jamesasteres
Attachments
- No local attachments were found for this message.