Siemens S7 CP340 Programming

E

Thread Starter

Ed

I am a relatively new S7 programmer, so maybe I've missed something. I created a new program with only one FB in OB1, which is the lib function F3 for the CP340. I renamed it to FB1000, imported it into OB1, and set it up as follows:

REQ = DB1000.0
R = DB1000.1
LADDR = DB1002 (=272 below)
DBNO = DB1004 (=1001 below)
DBBNO = DB1006 (start byte 0 below)
LEN = DB1008 (length below = 15)
Done = DB1010.0 (done bit out per interface)
ERROR = DB1010.1 (error bit per interface)
STATUS = DB1012 (word for status per interface)

DB1000 contains setup info for the CP340
start = BOOL FALSE
reset = BOOL FALSE
Laddr = INT 272 (from hardware setup for CP)
Dbno = INT 1001 (db to contain ascii data)
Dbbno = INT 0 (start byte of ascii in 1001
Len = INT 15 (end of string in 1001
error = BOOL FALSE (for error out
done = BOOL FALSE (for dione bit from CP340
status= WORD W#16#0 (status result from CP

In addition, there is an instance DB for FB1000 called DB1002, of type instance DB linked to FB1000 (in call hierarchy and thru properties), which I initialized so the values are correct just in case.

There is a DB called DB1001 for the string data, initialized so the first 15 chars are a string (the DB1000 data points to DB1001 in DBNO, and the start and len is 0 and 15 respectively.

This is exactly what is listed in the Cp ref manual. I checked all the values to be sure they are as listed. I call FB1000 with DB1002 as an instance DB, it should send the chars from DB1001 starting at 0 and going for 15 chars. I go into OB1, CPU in RUN, everything is fine. I toggle the start (REQ) bit on the FB and the CPU immediately faults. CPU error says "I/O error accessing parameter area 1010" or something like that. Then I get the usual complaint about the CPU stopping because OB122 is not able to run (not in program). Now cannot for the life of me figure out what it does not like. The instance DB is exactly like the parameter DB I set up, I checked it a hundred times. The ref to DBNO is an INT (as called for in CP340 manual) so it SHOULD reference DB1001, which contains the string, and since we are starting at 0 (DBBNO) and going for 15 chars (len) we should output the 15 chars to the CP340. I give up. There are NO refernces anywhere in the program to 1010 of anything, so what the heck is the "I/O parameter 1010..." thing about. The hardware config confirms the channel #'s for the CP340 and no conflicts. In fact, the ONLY other channels used above 100 are for an analog card which is at 259-271. Any ideas?

BTW: this is the "stripped" CP340 with RS232 only, not the one with selection for Printer/ASCII/3694. This one is 3694 ONLY.

Also, after it faults, I go in and look at the instance DB and it is zero so it does not look like it is even getting to the point of loading the IDB.

Appreciate any ideas. Thanks in advance

Ed
 
D

Daniel Chartier

Hello Ed;

Here is one thing that attarcted my attention in your setup:

> REQ = DB1000.0
> R = DB1000.1
> LADDR = DB1002 (=272 below)
....

Local Address (LADDR) should be the hex value of the hardware setup of the CP (dec 272=hex110). Try writing this value directly in your FB1000 call, and tell us if this helps.

Daniel Chartier
 
D

Daniel Chartier

I would also want to point out that you are not using correct bit addressing for the DB addresses you use:

DB1000.0 should be DB1000.DBX0.0
DB1000.1 should be DB1000.DBX0.1

Same thing for your word and Dword addressing, you should use the standard formats:

bit addressing---> DBx.DBXy.z
word addressing--> DBx.DBWy
Dword addressing (or real)--> DBx.DBDz

Why don't you use M-memory for your initial tests? e.g. M10.0, Mw22, Md34? It would be easier to manage, you don't need to create and structure the initial DB and you can correct errors in addressing much easier.

Hope this helps,
Daniel Chartier
 
Hi Dan and All,

Thanks all but I figured out what I was doing wrong. The addressing I fixed, but it still didn't work. Turns out I had a conditional in the ENO line to the block, erroneuosly thinking this was the "enable" for the function (to output the chars). I took it out, put the conditional into the REQ line and voila! I defined a DB to hold all the params for the CP340 and used the symbolic addresses so the addressing nonsense went away.

Now my problem is to concatenate the strings to go to the CP340. The string functions in this thing are abysmal at best.

ED
 
Top