DSPRelated.com
Forums

Basic Read and Write operation for DR register of GPIO port!

Started by abdulrazaqali October 16, 2006
Any thoughts for getting the value from GPIO_B_DR register? I want to
increment the GPIO_B_DR value after every iteration but no luck so
far;-) I'm getting the '0' value every time.

///////////////////////////////
register po;

asm(move #$0002 , X:GPIO_B_DR);
po = 0;

while(1)
{
asm(move X:GPIO_B_DR , X0); //Get DR register value in X0
asm(move X0 , po); // move it to po variable

po = po + 2; //increment the value

asm(move X0 , po); // move the po to X0
asm(move X:GPIO_B_DR , X0); // and write it back to DR register

}
But it is not working , every time i'm having 0 value from DR register.
//////////////////////
Let me elaborate my question again. I want to write some value to GPIO
b port and then i want to read that value do something (say increment
or decrement) before updating (writing back) to the B port again.

i'm using DSP56F801 (freescale) chip with CodeWorrior compiler.
Frankly i'm not new to programming, do have MCU , system programming
knowledge but at the same time i'm new to DSP world and the worst
thing is new to this specific tool set (freescale , CW , PE).

And last but not least , where can i find C reference manual for
freescale products?

Thanks for your time.
ali
Hi,

The C reference manual regarding DSP products you can find in the CW help directory. There are many useful pdf files. Regarding your example, the best way for you seems to be using ProcessorExpert and it's bean ByteIO. This bean has the set of methods that you can use in you application. Also this bean provides a configuration of the given GPIO port.

Your example bellow can be also written only in the C language:

while(1) {
setReg16(GPIO_B_DR, getReg16(GPIO_B_DR) + 2);
}

setReg() and getReg() are PE macros for low level register access.
abdulrazaqali wrote:

> Any thoughts for getting the value from GPIO_B_DR register? I want to
> increment the GPIO_B_DR value after every iteration but no luck so
> far;-) I'm getting the '0' value every time.

Did you set the data direction register (should be GPIO_B_DDR or
something like that) to all outputs?

Regards,
Carlo.
Hi,

swap the arguments in moving instructions after incrementation :o)

Petr

Any thoughts for getting the value from GPIO_B_DR register? I want to
>increment the GPIO_B_DR value after every iteration but no luck so
>far;-) I'm getting the '0' value every time.
>
>///////////////////////////////
>register po;
>
>asm(move #$0002 , X:GPIO_B_DR);
>po = 0;
>
>while(1)
>{
>asm(move X:GPIO_B_DR , X0); //Get DR register value in X0
>asm(move X0 , po); // move it to po variable
>
>po = po + 2; //increment the value
>
>asm(move X0 , po); // move the po to X0
>asm(move X:GPIO_B_DR , X0); // and write it back to DR register
>
>}
>But it is not working , every time i'm having 0 value from DR register.
>//////////////////////
>Let me elaborate my question again. I want to write some value to GPIO
>b port and then i want to read that value do something (say increment
>or decrement) before updating (writing back) to the B port again.
>
>i'm using DSP56F801 (freescale) chip with CodeWorrior compiler.
>Frankly i'm not new to programming, do have MCU , system programming
>knowledge but at the same time i'm new to DSP world and the worst
>thing is new to this specific tool set (freescale , CW , PE).
>
>And last but not least , where can i find C reference manual for
>freescale products?
>
>Thanks for your time.
>ali
--- In m..., pkraus@... wrote:
>
> Hi,
>
> swap the arguments in moving instructions after incrementation :o)
>
> Petr
>
> Any thoughts for getting the value from GPIO_B_DR register? I want to
> >increment the GPIO_B_DR value after every iteration but no luck so
> >far;-) I'm getting the '0' value every time.
> >
> >///////////////////////////////
> >register po;
> >
> >asm(move #$0002 , X:GPIO_B_DR);
> >po = 0;
> >
> >while(1)
> >{
> >asm(move X:GPIO_B_DR , X0); //Get DR register value in X0
> >asm(move X0 , po); // move it to po variable
> >
> >po = po + 2; //increment the value
> >
> >asm(move X0 , po); // move the po to X0
> >asm(move X:GPIO_B_DR , X0); // and write it back to DR register
> >
> >}
> >But it is not working , every time i'm having 0 value from DR register.
> >//////////////////////
> >Let me elaborate my question again. I want to write some value to GPIO
> >b port and then i want to read that value do something (say increment
> >or decrement) before updating (writing back) to the B port again.
> >
> >i'm using DSP56F801 (freescale) chip with CodeWorrior compiler.
> >Frankly i'm not new to programming, do have MCU , system programming
> >knowledge but at the same time i'm new to DSP world and the worst
> >thing is new to this specific tool set (freescale , CW , PE).
> >
> >And last but not least , where can i find C reference manual for
> >freescale products?
> >
> >Thanks for your time.
> >ali
> >
>

Folks!

Thank you very much for your kind followup, yeah i've already
fixed the problem with the help of PE which is indeed quite handy.
Yeah it is damn easy thing todo. Anyway now i want to decode incoming
signal (i.e. frequency_counter). I did try to use 'capture' or
'ExtInt' beans but no luck guess something still missing. Any thoughts
for that?

For the sake of reference , Well as the matter of fact i was trying to
do in following manner :
0) Enable the peripheral in PER register while setting those bits to high
1) Enabling the DDR for output (1;high for output , 0;for input).
2) And DR is ready to cook.

I was doing every thing right but didn't figure out that my logic in
main routine was't accurate. Yeah , if you look my original post then
you can notice a blunder there. And i didn't notice by my self unless
a soul from Sweden pointed out the wrong sequence of instructions.
Petr also pointed the same mistake.

///////////////////////////////
register po; asm(move #$0002 , X:GPIO_B_DR);
po = 0;
while(1) {
/* 1) */ asm(move X:GPIO_B_DR , X0);
/* 2) */ asm(move X0 , po); po = po + 2;
/* 3) */asm(move X0 , po);
/* 4) */asm(move X:GPIO_B_DR , X0); }
//////////////////////
The problem was with line 3 and 4. Oh yeah it should be something like
/* 3) */asm(move po , X0); // move new value of po to X0
/* 4) */asm(move X0 , X:GPIO_B_DR ); // write X0 to GOIP DR

ali