MCP23017

For general Flowcode discussion that does not belong in the other sections.
jimhook_uk1
Posts: 13
http://meble-kuchenne.info.pl
Joined: Fri Dec 04, 2020 5:22 pm
Has thanked: 1 time
Been thanked: 3 times

MCP23017

Post by jimhook_uk1 »

Hi,
I am working with an existing hardware design, the original code was written using MPLAB but I am trying to replicate it with Flowcode as a learning exercise. This design uses dsPICEP32GP504 and 4x MCP23017, the problem is I am using RC6 and RC5 for the I2C. The MCP23017 does not use these pins, is it possible to modify a copy of this component?

Thanks.

LeighM
Valued Contributor
Posts: 394
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 69 times
Been thanked: 208 times

Re: MCP23017

Post by LeighM »

Hi,
Please could you copy the attached file into your PC directory C:\ProgramData\MatrixTSL\FlowcodeV9\FCD\PIC16
Then restart Flowcode.
btw. The dsPIC33EP32GP504 datasheet indicates that SDA1 and SCL1 are on pins C4 and C5, so I have implemented that.
Let me know if that's wrong.
Thanks
Attachments
33EP32GP504.fcdx
(34.29 KiB) Downloaded 98 times

jimhook_uk1
Posts: 13
Joined: Fri Dec 04, 2020 5:22 pm
Has thanked: 1 time
Been thanked: 3 times

Re: MCP23017

Post by jimhook_uk1 »

Hi LeighM,
Yes it is on C4 and C5 - sorry.
My project has loaded up with the correct ports on the properties tab.

Thanks

jimhook_uk1
Posts: 13
Joined: Fri Dec 04, 2020 5:22 pm
Has thanked: 1 time
Been thanked: 3 times

Re: MCP23017

Post by jimhook_uk1 »

Hi,
The next snag I've encountered is hopefully obvious to someone more experienced than me. I am looking at a single port pin A:7 that has a switch on the outside, when this switch is on I want to switch a pin on the dsPIC high but I can't seem to make it work, not sure what I'm doing wrong but suspect it has something to do with variables and return values.

Thanks
Attachments
P130 V01.fcfx
(11.99 KiB) Downloaded 97 times

BenR
Matrix Staff
Posts: 1707
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: MCP23017

Post by BenR »

Hello,

Your project looks ok to me though you might need to look at your configuration settings, the watchdog timer is enabled which could be causing problems.

Do you have pull up resistors connected between the SDA/SCL pins and VCC? Say 4K7 or 10K should work fine.

You can also enable internal pull up's in software using the following C code inside a C icon if you don't want to fit external ones.

Code: Select all

//Enable pull up resistor on pins C4 and C5
CNPUC |= 0x0030;
It may be worth checking if you can talk to the expander IO at all using an WritePortPin and a LED.

If the LED is working but the switch is not then it may be worth checking the wiring of the switch is similar to how it's shown here.
https://www.flowcode.co.uk/wiki/index.p ... )#Examples

jimhook_uk1
Posts: 13
Joined: Fri Dec 04, 2020 5:22 pm
Has thanked: 1 time
Been thanked: 3 times

Re: MCP23017

Post by jimhook_uk1 »

Hi Ben,
Thanks for the reply I will check the configuration settings. I know the hardware is fine as this is a product that has been in production for several years. I am trying to replicate the functions of this product using Flowcode as a learning exercise. The bus has 4k7 pull ups and the existing hand written code works fine. The product has many switch inputs which are all connected to the IO expanders, there are no outputs connected directly to IO expander pins. So I'm convinced it is an error in my flowcode model.

Thanks

BenR
Matrix Staff
Posts: 1707
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: MCP23017

Post by BenR »

I beleive it could be these configuration settings at fault, they probably should be set to disabled to match your I2C pin selection.
Settings.jpg
Settings.jpg (16.86 KiB) Viewed 3242 times

jimhook_uk1
Posts: 13
Joined: Fri Dec 04, 2020 5:22 pm
Has thanked: 1 time
Been thanked: 3 times

Re: MCP23017

Post by jimhook_uk1 »

Hi Ben,
Yes that was the issue, I am now reading port pins without issue.

However, WritePortPin just does not seem to work at all.

jimhook_uk1
Posts: 13
Joined: Fri Dec 04, 2020 5:22 pm
Has thanked: 1 time
Been thanked: 3 times

Re: MCP23017

Post by jimhook_uk1 »

Hi,
My project also uses a TLC59116 LED driver, would it be possible to save the attached as a later version so I can view it please?

Thanks in advance.
Attachments
LED Driver i2c TLC59116.zip
(3.39 KiB) Downloaded 103 times

BenR
Matrix Staff
Posts: 1707
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: MCP23017

Post by BenR »

Hello,

Here you go.
LED Driver i2c TLC59116_v7.fcfx
(23.14 KiB) Downloaded 110 times
I'll investigate the WritePortPin problem for you and see if I can spot anything.

Post Reply