avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] direct port access


From: Marlin Unruh
Subject: Re: [avr-gcc-list] direct port access
Date: Wed, 22 Jan 2003 16:32:40 -0700
User-agent: KMail/1.4.3

On Wednesday 22 January 2003 14:58, E. Weddington wrote:
> On 22 Jan 2003 at 10:57, Marlin Unruh wrote:
> > I have some code that was working with the old style io.h. I am tiring
> > to get the code working with the new style (#define
> > PORTD       _SFR_IO8(0x12))
> >
> > void Pdu1_In_Port(unsigned char* buff)
> > {
> >  unsigned char tmp;
> >  unsigned char * const iobase = (unsigned char*)0x20;
> >  unsigned char address;
> >  address = buff[10]; // get address of port
> >  if(address < SPL) { // exclude SREG and Stack Pointer Registers
> >   tmp = *(iobase + address); // read i/o space address
> >   tmp &= ~buff[6]; // inverted mask low byte AND
> >   tmp |= (buff[6] & buff[8]); // get data low byte
> >   *(iobase + address) = tmp; // write i/o space
> >  }
> > } // end of Pdu1_In_Port
>
> <snip>
>
> Well you didn't say what the above code is actually doing in it's
> error.
>
> But this could be a problem:
>
> if(address < SPL) { // exclude SREG and Stack Pointer Registers
>
> SPL is defined as a _SFR_IO8(..., which is not going to be the same
> thing as what your address is declared as. Rewrite as:
>
> if(address < &(SPL))
>
> That way you're comparing a memory address to a memory address.
>
> HTH,
> Eric
> avr-gcc-list at http://avr1.org

I got it working. The problem was that the master was to send a message to the 
slave unit via a CANBUS connection, and turn on PORTD pin 6 or 7. This  
controls a two-way hydraulic valve. The ports were not working. It worked on 
the old style io.h before the _SRF_IO8 stuff. In my old code I was defining 
the pointer as follows:

unsigned char * const iobase = (unsigned char*)0x20;

I changed to:

unsigned char * const iobase = (unsigned char*)0x00;

and it work like it used to. 

I was basicly was writing 0x20 to high.

Thanks you
Marlin

avr-gcc-list at http://avr1.org



reply via email to

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