Reading from Parallel Ports using Dynamic C?
Started by ●January 31, 2005
Hello Everyone,
I'm new to the group and fairly new to using the Rabbit
Microprocessor and Microprocessors in general. I am using the
RabbitCore RCM3100 with a prototyping board. I am having difficulty
reading from the ports. I tried to see if they had a simple example
in the examples that came with the Dynamic C environment, but there
isn't anything with any real explanation. I also checked several
manuals that are available through their website.
These are my questions regarding Reading/Writing I/O...
In the Dynamic C library they have some functions: RdPortE and
RdPortI. I cannot find an explanation for what the Internal and
External Ports are. I am assuming that the external Ports (for port
A for example) are pins PA(0-7). Am I correct in this assumption?
(keep in mind, I'm still fairly new to Microprocessors in general)
What is the relationship between internal and external ports?
Is there anything I need to do to initialize the port I'm trying to
read? I know it's different for each port, but should I have to
initialize port A, since it only has one function.
I got some random numbers with the following code, but I should be
seeing "0" since I don't have anything connected to those pins on the
Prototyping board. I also attempted using
BitRdPortI(PBDR, RECEIVER);
But it didn't matter what kind of input I had at pin 0 on port B, I
always saw logic '0'.
Here is my code:
#define SYSIO
#define RECEIVER 0 //Laser Receiver, Port A bit 0
void main()
{
int laserInput;
WrPortI(PBDDR, &PBDDRShadow, 0x00);
laserInput = 0;
while (1)
{
laserInput = RdPortI(PBDR);
printf("laser input = %d\n", laserInput);
}
}
If anybody can help me out, I would be greatly appreciated!
Brad
Reply by ●February 1, 20052005-02-01
Internal I/O ports are the ports on/in the Rabbit
itself. For example, port A, B, C, D, etc. The
external ports are additional latches that you connect
to the Rabbit. This is called Auxillary IO. WHen you
enable that feature, then port becomes the 8-bit data
bus the you use to read and write these external
ports.
So unless you're using auxillary IO, you should always
use the internal IO procedures.
Steve
--- bradrekk <bradrekk@brad...> wrote:
>
> Hello Everyone,
>
> I'm new to the group and fairly new to using the
> Rabbit
> Microprocessor and Microprocessors in general. I am
> using the
> RabbitCore RCM3100 with a prototyping board. I am
> having difficulty
> reading from the ports. I tried to see if they had
> a simple example
> in the examples that came with the Dynamic C
> environment, but there
> isn't anything with any real explanation. I also
> checked several
> manuals that are available through their website.
>
> These are my questions regarding Reading/Writing
> I/O...
>
> In the Dynamic C library they have some functions:
> RdPortE and
> RdPortI. I cannot find an explanation for what the
> Internal and
> External Ports are. I am assuming that the external
> Ports (for port
> A for example) are pins PA(0-7). Am I correct in
> this assumption?
> (keep in mind, I'm still fairly new to
> Microprocessors in general)
>
> What is the relationship between internal and
> external ports?
>
> Is there anything I need to do to initialize the
> port I'm trying to
> read? I know it's different for each port, but
> should I have to
> initialize port A, since it only has one function.
>
> I got some random numbers with the following code,
> but I should be
> seeing "0" since I don't have anything connected to
> those pins on the
> Prototyping board. I also attempted using
>
> BitRdPortI(PBDR, RECEIVER);
>
> But it didn't matter what kind of input I had at pin
> 0 on port B, I
> always saw logic '0'.
>
> Here is my code:
>
> #define SYSIO
> #define RECEIVER 0 //Laser Receiver, Port A bit 0
>
> void main()
> {
> int laserInput;
>
> WrPortI(PBDDR, &PBDDRShadow, 0x00);
>
> laserInput = 0;
>
> while (1)
> {
> laserInput = RdPortI(PBDR);
>
> printf("laser input = %d\n", laserInput);
> }
> }
>
> If anybody can help me out, I would be greatly
> appreciated!
>
> Brad >
>
itself. For example, port A, B, C, D, etc. The
external ports are additional latches that you connect
to the Rabbit. This is called Auxillary IO. WHen you
enable that feature, then port becomes the 8-bit data
bus the you use to read and write these external
ports.
So unless you're using auxillary IO, you should always
use the internal IO procedures.
Steve
--- bradrekk <bradrekk@brad...> wrote:
>
> Hello Everyone,
>
> I'm new to the group and fairly new to using the
> Rabbit
> Microprocessor and Microprocessors in general. I am
> using the
> RabbitCore RCM3100 with a prototyping board. I am
> having difficulty
> reading from the ports. I tried to see if they had
> a simple example
> in the examples that came with the Dynamic C
> environment, but there
> isn't anything with any real explanation. I also
> checked several
> manuals that are available through their website.
>
> These are my questions regarding Reading/Writing
> I/O...
>
> In the Dynamic C library they have some functions:
> RdPortE and
> RdPortI. I cannot find an explanation for what the
> Internal and
> External Ports are. I am assuming that the external
> Ports (for port
> A for example) are pins PA(0-7). Am I correct in
> this assumption?
> (keep in mind, I'm still fairly new to
> Microprocessors in general)
>
> What is the relationship between internal and
> external ports?
>
> Is there anything I need to do to initialize the
> port I'm trying to
> read? I know it's different for each port, but
> should I have to
> initialize port A, since it only has one function.
>
> I got some random numbers with the following code,
> but I should be
> seeing "0" since I don't have anything connected to
> those pins on the
> Prototyping board. I also attempted using
>
> BitRdPortI(PBDR, RECEIVER);
>
> But it didn't matter what kind of input I had at pin
> 0 on port B, I
> always saw logic '0'.
>
> Here is my code:
>
> #define SYSIO
> #define RECEIVER 0 //Laser Receiver, Port A bit 0
>
> void main()
> {
> int laserInput;
>
> WrPortI(PBDDR, &PBDDRShadow, 0x00);
>
> laserInput = 0;
>
> while (1)
> {
> laserInput = RdPortI(PBDR);
>
> printf("laser input = %d\n", laserInput);
> }
> }
>
> If anybody can help me out, I would be greatly
> appreciated!
>
> Brad >
>
Reply by ●February 1, 20052005-02-01
Thank you for clearing up the internal and external ports question
Steve.
I was wondering if anyone could tell me if the following code should
work to read Port A, or do I need to initialize the ports in any way.
#define SYSIO
#define RECEIVER 0 //Laser Receiver, Port A bit 0
void main()
{
int laserInput;
laserInput = 0;
while (1)
{
laserInput = RdPortI(PADR);
printf("laser input = %d\n", laserInput);
}
}
From my understanding of RdPortI(int port), this code should work,
but this code does not show what is on the port.
Brad
Reply by ●February 1, 20052005-02-01
Yes, what you have should work. I don't recall, but
you may need pull-ups on that port.
Steve --- bradrekk <bradrekk@brad...> wrote:
>
> Thank you for clearing up the internal and external
> ports question
> Steve.
>
> I was wondering if anyone could tell me if the
> following code should
> work to read Port A, or do I need to initialize the
> ports in any way.
>
> #define SYSIO
> #define RECEIVER 0 //Laser Receiver, Port A bit 0
>
> void main()
> {
> int laserInput;
>
> laserInput = 0;
>
> while (1)
> {
> laserInput = RdPortI(PADR);
>
> printf("laser input = %d\n", laserInput);
> }
> }
>
> From my understanding of RdPortI(int port), this
> code should work,
> but this code does not show what is on the port.
>
> Brad >
>
you may need pull-ups on that port.
Steve --- bradrekk <bradrekk@brad...> wrote:
>
> Thank you for clearing up the internal and external
> ports question
> Steve.
>
> I was wondering if anyone could tell me if the
> following code should
> work to read Port A, or do I need to initialize the
> ports in any way.
>
> #define SYSIO
> #define RECEIVER 0 //Laser Receiver, Port A bit 0
>
> void main()
> {
> int laserInput;
>
> laserInput = 0;
>
> while (1)
> {
> laserInput = RdPortI(PADR);
>
> printf("laser input = %d\n", laserInput);
> }
> }
>
> From my understanding of RdPortI(int port), this
> code should work,
> but this code does not show what is on the port.
>
> Brad >
>
Reply by ●February 6, 20052005-02-06
I tested the code below and all I see on port A are
high inputs on all the pins. It's not reading logic
zero, which is what should be read since I am not
supplying high voltages to any of the pins initially.
I've attempted to look in the documentation to see if
I need to initialize the port before using it, but I
didn't see anything explicit.
Has anyone encountered problems like this before?
This is for a RCM3100 Module with a prototyping board.
Thank you for your help!
Brad --- Steve Trigero <seecwriter@seec...> wrote:
> Yes, what you have should work. I don't recall, but
> you may need pull-ups on that port.
>
> Steve > --- bradrekk <bradrekk@brad...> wrote:
>
> >
> > Thank you for clearing up the internal and
> external
> > ports question
> > Steve.
> >
> > I was wondering if anyone could tell me if the
> > following code should
> > work to read Port A, or do I need to initialize
> the
> > ports in any way.
> >
> > #define SYSIO
> > #define RECEIVER 0 //Laser Receiver, Port A bit
> 0
> >
> > void main()
> > {
> > int laserInput;
> >
> > laserInput = 0;
> >
> > while (1)
> > {
> > laserInput = RdPortI(PADR);
> >
> > printf("laser input = %d\n", laserInput);
> > }
> > }
> >
> > From my understanding of RdPortI(int port), this
> > code should work,
> > but this code does not show what is on the port.
> >
> > Brad
> >
> >
> >
>
__________________________________
high inputs on all the pins. It's not reading logic
zero, which is what should be read since I am not
supplying high voltages to any of the pins initially.
I've attempted to look in the documentation to see if
I need to initialize the port before using it, but I
didn't see anything explicit.
Has anyone encountered problems like this before?
This is for a RCM3100 Module with a prototyping board.
Thank you for your help!
Brad --- Steve Trigero <seecwriter@seec...> wrote:
> Yes, what you have should work. I don't recall, but
> you may need pull-ups on that port.
>
> Steve > --- bradrekk <bradrekk@brad...> wrote:
>
> >
> > Thank you for clearing up the internal and
> external
> > ports question
> > Steve.
> >
> > I was wondering if anyone could tell me if the
> > following code should
> > work to read Port A, or do I need to initialize
> the
> > ports in any way.
> >
> > #define SYSIO
> > #define RECEIVER 0 //Laser Receiver, Port A bit
> 0
> >
> > void main()
> > {
> > int laserInput;
> >
> > laserInput = 0;
> >
> > while (1)
> > {
> > laserInput = RdPortI(PADR);
> >
> > printf("laser input = %d\n", laserInput);
> > }
> > }
> >
> > From my understanding of RdPortI(int port), this
> > code should work,
> > but this code does not show what is on the port.
> >
> > Brad
> >
> >
> >
>
__________________________________
Reply by ●February 6, 20052005-02-06
At 08:39 PM 2/5/2005 -0800, you wrote:
>I tested the code below and all I see on port A are
>high inputs on all the pins. It's not reading logic
>zero, which is what should be read since I am not
>supplying high voltages to any of the pins initially.
>I've attempted to look in the documentation to see if
>I need to initialize the port before using it, but I
>didn't see anything explicit.
First, select the port to be a regular port. The A port can function as a
slave port, so use the slave control register to disable this function:
WrPortI(SPCR,&SPCRShadow,0x80);
Next, pull it high internally. This step is NOT required on the Rabbit,
but some processors do require it, so it's good coding habits:
WrPortI(PADR,&PADRShadow,0xFF);
Now read the port into a value:
B = RdPortI(PADR);
All should be high.
Do that again while grounding a pin, and that pin should change when you
read it. Port A is pulled high on the core I believe (might be because of
the output electronics design on the chip) so it is correct to read high
unless you ground the pin.
-Mike
--
Mike vanMeeteren fast351@fast... FASTechnologies Corp.
Track Hauler: 2001 F150 Track toy: 89 Mustang LX 351W 10.93 @ 122.5 MPH
>I tested the code below and all I see on port A are
>high inputs on all the pins. It's not reading logic
>zero, which is what should be read since I am not
>supplying high voltages to any of the pins initially.
>I've attempted to look in the documentation to see if
>I need to initialize the port before using it, but I
>didn't see anything explicit.
First, select the port to be a regular port. The A port can function as a
slave port, so use the slave control register to disable this function:
WrPortI(SPCR,&SPCRShadow,0x80);
Next, pull it high internally. This step is NOT required on the Rabbit,
but some processors do require it, so it's good coding habits:
WrPortI(PADR,&PADRShadow,0xFF);
Now read the port into a value:
B = RdPortI(PADR);
All should be high.
Do that again while grounding a pin, and that pin should change when you
read it. Port A is pulled high on the core I believe (might be because of
the output electronics design on the chip) so it is correct to read high
unless you ground the pin.
-Mike
--
Mike vanMeeteren fast351@fast... FASTechnologies Corp.
Track Hauler: 2001 F150 Track toy: 89 Mustang LX 351W 10.93 @ 122.5 MPH
Reply by ●February 7, 20052005-02-07
Thanks to everyone who helped with this question. It
turns out that I was doing everything right. My
problem was that I assumed the problem to be more
difficult that in actually was.
I was grounding my pins from a seperate power supply
and this did not drive the pins to zero voltage.
Since this was so trivial I didn't think it was a
problem to use a seperate ground (ground from one of
the other pins on the prototyping board worked just
fine). As dumb as this made me feel, I can reassure
myself in that I'm only a beginner to the field of
electrical engineering.
Thought everyone would get a good chuckle out of this.
Brad
__________________________________
turns out that I was doing everything right. My
problem was that I assumed the problem to be more
difficult that in actually was.
I was grounding my pins from a seperate power supply
and this did not drive the pins to zero voltage.
Since this was so trivial I didn't think it was a
problem to use a seperate ground (ground from one of
the other pins on the prototyping board worked just
fine). As dumb as this made me feel, I can reassure
myself in that I'm only a beginner to the field of
electrical engineering.
Thought everyone would get a good chuckle out of this.
Brad
__________________________________