CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Mon Jan 27, 2020 4:59 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Fri Dec 20, 2019 4:57 pm 
Offline

Joined: Wed Dec 11, 2019 11:49 am
Posts: 2
Hello Everyone,

I am a new user here and I have a raspberry Pi 3 model B which I have installed CODESYS Control for Raspberry Pi MC SL. I am trying to communicate with the MCP23017 chip using i2c. I have downloaded the library, and driver as well as the sample code but I am not able to get it to work - thus any help would be greatly appreciated.

I have managed to communicate with the MCP23017 chip using the raspberry pi terminal itself using the code

$ i2cset -y 1 0x20 0x00 0x00 (this code on the pi declares all pins of Bank A (GPA) as outputs)
$ i2cset -y 1 0x20 0x14 0x01 (this code on the pi turns on the 1st led on channel A)

I have been trying to replicate this in codesys but its not working and I am quite lost. If anyone has some tips please contact me.

Kind regards, Oliver


Top
   
PostPosted: Sat Dec 21, 2019 9:02 am 
Offline

Joined: Sat Aug 11, 2018 7:17 am
Posts: 22
hello oliver,
Codesys does not manage MCP23017 in I2C, but MCP23S17 in SPI.

viewtopic.php?f=23&t=6247


Top
   
PostPosted: Sat Dec 21, 2019 2:09 pm 
Offline

Joined: Tue Mar 26, 2019 4:28 pm
Posts: 83
Hello, in my brief search I couldn't find your exact Codesys driver.

You can make your own though, here is the documentation.
https://forge.codesys.com/drv/io-drivers/doc/I2C/

If you decide to develop your driver on forge.codesys.com, there is a wonderful community to help when you are stuck.

Let me know if there are any specific questions about the process, or of course you can ask there.


Top
   
PostPosted: Sat Dec 28, 2019 10:56 am 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3603
Hi,
you could give the driver from the section here a try:
viewtopic.php?f=23&t=5872
or is it what you have already done?

This section will move to forge too...next
BR
Edwin


Top
   
PostPosted: Mon Dec 30, 2019 7:02 pm 
Offline

Joined: Wed Dec 11, 2019 11:49 am
Posts: 2
Hello everyone,

Sorry for my late response - hope you all had a lovely Christmas.

Yes I downloaded that driver, library and sample code from that thread Edwin but I was not able to get any response. I think I am missing something trivial but such as setting the GPIO to an input/output but I am not able to see the i2c gpio in codesys. Is this correct?

If anyone has 30 minutes (or any time at all) to have a quick run through of what I have already done and give some advice I would greatly appreciate it.

I look forward to hearing from you


Top
   
PostPosted: Tue Dec 31, 2019 8:46 am 
Offline
Site Admin

Joined: Mon Sep 05, 2005 9:42 am
Posts: 3603
Hi,
no mapping is needed for I2C on the GPIO's.
Did you enable I2C by using CLI?

sudo raspi-config
That's basically the only thing which is needed.

You could check your device by:
i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
If this works CODESYS should work with the I2C too.

BR
Edwin


Top
   
PostPosted: Mon Jan 13, 2020 8:33 am 
Offline

Joined: Sun Jan 17, 2016 7:45 pm
Posts: 20
Hello
from time to time I trying to work with the MCP23017. I have no problem to use the MCP ports as inputs but until now I was not able to use the MCP ports as outputs (e.g. to control a LED).
Regards
JJoe


Top
   
PostPosted: Mon Jan 13, 2020 11:45 am 
Offline

Joined: Sun Jan 17, 2016 7:45 pm
Posts: 20
Sorry I forgot my Codesys code:
MCP23017_0x24.OUT_A:=16#00; //Porta --> Output
MCP23017_0x24.OUT_B:=16#FF; //PortB --> Input
GVL.xPB:=MCP23017_0x24.IN_B.0;

IF NOT GVL.xPB THEN
MCP23017_0x24.OUT_A.0:=TRUE;
MCP23017_0x24.OUT_A.1:=TRUE;
MCP23017_0x24.OUT_A.2:=TRUE;
MCP23017_0x24.OUT_A.3:=TRUE;
MCP23017_0x24.OUT_A.4:=TRUE;
MCP23017_0x24.OUT_A.5:=TRUE;
MCP23017_0x24.OUT_A.6:=TRUE;
MCP23017_0x24.OUT_A.7:=TRUE;
END_IF

IF GVL.xPB THEN
MCP23017_0x24.OUT_A.0:=FALSE;
MCP23017_0x24.OUT_A.1:=FALSE;
MCP23017_0x24.OUT_A.2:=FALSE;
MCP23017_0x24.OUT_A.3:=FALSE;
MCP23017_0x24.OUT_A.4:=FALSE;
MCP23017_0x24.OUT_A.5:=FALSE;
MCP23017_0x24.OUT_A.6:=FALSE;
MCP23017_0x24.OUT_A.7:=FALSE;
END_IF


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 8 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited