Page 1 of 2

MCP23017

Posted: Thu Oct 14, 2021 11:06 am
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.

Re: MCP23017

Posted: Fri Oct 15, 2021 8:57 am
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

Re: MCP23017

Posted: Fri Oct 15, 2021 9:19 am
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

Re: MCP23017

Posted: Mon Oct 18, 2021 3:07 pm
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

Re: MCP23017

Posted: Mon Oct 18, 2021 4:08 pm
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

Re: MCP23017

Posted: Mon Oct 18, 2021 7:54 pm
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

Re: MCP23017

Posted: Tue Oct 19, 2021 9:26 am
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 3319 times

Re: MCP23017

Posted: Wed Oct 20, 2021 8:54 am
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.

Re: MCP23017

Posted: Wed Oct 20, 2021 12:27 pm
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.

Re: MCP23017

Posted: Wed Oct 20, 2021 2:17 pm
by BenR
Hello,

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