Maker Pro
Maker Pro

I/O trouble

A

aerona

Jan 1, 1970
0
Hello guys,

I am having trouble with writing into an 8 bit register which has a RD,
WR and CS associated with it from a PIC18f452. The device I'm trying
to write to is called an Anybus-s device and I should mention that I am
a newbie to the world of micro-controllers.

I've tried 2 methods; 1st. I used the PSP device of the PIC, where the
8bits of portD is directly connected to the 8bits of my device. The WR,
RD and CS of the PIC connect to the RD, WR and CS of the device in the
order I've written. To read from the device I make WR and CS of the PIC
go low and read whts in PORTD (e.g. temp = PORTD).This works alright
however, when I want to write by making the RD and CS of the PIC go low
and PORTD = BINARYVALUE nothing happens.

2nd method. I don't use the PSP device but I still connect PORTD to the
8bit register and have RE0 connected to RD, RE1 to WR and RE2 connected
to CS of the device. When I want to read of the device I make PORTD
inputs and set RE0 and RE2 low (then high again), then temp = PORTD to
read. This also works fine, however when I want to write by making RE1
an RE2 low, PORTD outputs and PORTD = BINARYVALUE nothing happens
again.

The way I know the write isn't working is if the data was written
properly the device would send a response. When I write to the device I
keep the WR and CS low for approximately 40 micro seconds. I can't
seem to get the BINARYVALUE (which is e.g 11101100) to appear on the
PORTD pins for some reason.
If anyone has any suggestions I would be very grateful. For those who
might be interested the ANYbus device is used to interface a
micro-controller to the PLC so as to have something like a motor
controlled by the PLC.
 
R

Roger Hamlett

Jan 1, 1970
0
aerona said:
Hello guys,

I am having trouble with writing into an 8 bit register which has a RD,
WR and CS associated with it from a PIC18f452. The device I'm trying
to write to is called an Anybus-s device and I should mention that I am
a newbie to the world of micro-controllers.

I've tried 2 methods; 1st. I used the PSP device of the PIC, where the
8bits of portD is directly connected to the 8bits of my device. The WR,
RD and CS of the PIC connect to the RD, WR and CS of the device in the
order I've written. To read from the device I make WR and CS of the PIC
go low and read whts in PORTD (e.g. temp = PORTD).This works alright
however, when I want to write by making the RD and CS of the PIC go low
and PORTD = BINARYVALUE nothing happens.

2nd method. I don't use the PSP device but I still connect PORTD to the
8bit register and have RE0 connected to RD, RE1 to WR and RE2 connected
to CS of the device. When I want to read of the device I make PORTD
inputs and set RE0 and RE2 low (then high again), then temp = PORTD to
read. This also works fine, however when I want to write by making RE1
an RE2 low, PORTD outputs and PORTD = BINARYVALUE nothing happens
again.

The way I know the write isn't working is if the data was written
properly the device would send a response. When I write to the device I
keep the WR and CS low for approximately 40 micro seconds. I can't
seem to get the BINARYVALUE (which is e.g 11101100) to appear on the
PORTD pins for some reason.
If anyone has any suggestions I would be very grateful. For those who
might be interested the ANYbus device is used to interface a
micro-controller to the PLC so as to have something like a motor
controlled by the PLC.
To use the PSP, _you_ do not control the PORTE bits. The hardware does
this for you. If you access the PORTE bits (which you are doing in both
cases), you disable PSP.
You need to set the low three bits in the PORTE TRIS register to '1'
(input mode), and set bit 4 of the PORTE TRIS register to '1' as well
(PSPMODE). This enables PSP mode. Once done, do not perform any I/O on the
PORT E lines yourself.
Then if you input/output to PORTD, the hardware will automatically control
the lines for you. The I/O cycle takes two machine instruction times (8
clock cycles) to complete.
Because you are controlling the PORT E lines, you are overriding the PSP
mode.

Best Wishes
 
T

Tim Wescott

Jan 1, 1970
0
Roger said:
To use the PSP, _you_ do not control the PORTE bits. The hardware does
this for you. If you access the PORTE bits (which you are doing in both
cases), you disable PSP.
You need to set the low three bits in the PORTE TRIS register to '1'
(input mode), and set bit 4 of the PORTE TRIS register to '1' as well
(PSPMODE). This enables PSP mode. Once done, do not perform any I/O on the
PORT E lines yourself.
Then if you input/output to PORTD, the hardware will automatically control
the lines for you. The I/O cycle takes two machine instruction times (8
clock cycles) to complete.
Because you are controlling the PORT E lines, you are overriding the PSP
mode.

Best Wishes
And check your PIC data sheet for the timing. Usually the memory
master's WR line is connected to the WR line of the peripheral, and RD
to RD. If you have an oscilloscope to measure what's actually going on
and compare it to what you see on the bus that may be useful.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

Posting from Google? See http://cfaj.freeshell.org/google/
 
A

aerona

Jan 1, 1970
0
As it turns out the RD of the PIC should connect to the WR of the
device since they're both slaves. And the WR of the PIC should connect
to the RD of the Device for the same reason. I believe in the case
where there is a master and slave WR should connect to WR (or at least
we expect that).

Thank you for that....
 
A

aerona

Jan 1, 1970
0
Thank you for your reply...
I should have explained that the way I control the PSP control bits are
through external pins connected to them.. Meaning I've made the RD, WR
and CS all digital inputs as the datasheet mentions and have 3 pins of
PORTA connected to them so as to control them externally... I did this
because making them outputs didn't work... both the PIC and the device
I'm using are slave devices so I decided to make the PIC the master by
having these 3 external control bits
 
A

aerona

Jan 1, 1970
0
Thank you for your reply....
I should have explained that the way I control the PSP control bits are
through external pins connected to them.. Meaning I've made the RD, WR
and CS all digital inputs as the datasheet mentions and have 3 pins of
PORTA connected to them so as to control them externally... I did this
because making them outputs didn't work... both the PIC and the device
I'm using are slave devices so I decided to make the PIC the master by
having these 3 external control bits...
 
T

Tim Wescott

Jan 1, 1970
0
aerona said:
As it turns out the RD of the PIC should connect to the WR of the
device since they're both slaves. And the WR of the PIC should connect
to the RD of the Device for the same reason. I believe in the case
where there is a master and slave WR should connect to WR (or at least
we expect that).

Thank you for that....
If they're both slaves then they'll both sit there waiting for something
to happen, and it never will.

Your best bet would probably be to study the datasheet carefully and
just bit-bang the control lines from the PIC.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

Posting from Google? See http://cfaj.freeshell.org/google/
 
Top