I2C PortExpander - MCP23017 - library and examples

General discussion on mikroBasic.
Post Reply
Author
Message
yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

I2C PortExpander - MCP23017 - library and examples

#1 Post by yo2lio » 15 Jul 2007 20:56

I2C PortExpander library for MCP23017.

This library is tested on EasyPIC4 board, PIC16F877A, PIC18F452 MCU and home made MCP23017 board, made by me.

First: copy i2cportexpander_lib_p16.mcl file in dir ../uses/P16 and i2cportexpander_lib.mcl file in dir ../uses/P18.

Library include :

Code: Select all

sub procedureI2CExpander_Init(dim byref RstPort as byte, dim RstPin, ModuleAddress as byte)
'I2C_Init(100000) must be called before initializing I2C Port Expander'

sub function I2CExpander_Read_Byte(dim ModuleAddress, RegAddress as byte) as byte

sub procedureI2CExpander_Write_Byte(dim ModuleAddress, RegAddress, Data as byte)

sub procedureI2CExpander_Set_Mode(dim ModuleAddress, Mode as byte)

sub procedureI2CExpander_Read_ArrayPortA(dim ModuleAddress, NoBytes as byte, dim byref DestArray as byte[100])

sub procedureI2CExpander_Read_Array(dim ModuleAddress, StartAddress, NoBytes as byte, dim byref DestArray as byte[100])

sub procedureI2CExpander_Write_Array(dim ModuleAddress, StartAddress, NoBytes as byte, dim byref SourceArray as byte[100])

sub function I2CExpander_Read_PortA(dim Address as byte) as byte

sub function I2CExpander_Read_PortB(dim Address as byte) as byte

sub procedureI2CExpander_Read_ArrayPortB(dim ModuleAddress, NoBytes as byte, dim byref DestArray as byte[100])

sub procedureI2CExpander_Write_PortA(dim ModuleAddress, Data as byte)

sub procedureI2CExpander_Write_PortB(dim ModuleAddress, Data as byte)

sub procedureI2CExpander_Set_DirectionPortA(dim ModuleAddress, Data as byte)

sub procedureI2CExpander_Set_DirectionPortB(dim ModuleAddress, Data as byte)

sub procedureI2CExpander_Set_PullUpsPortA(dim ModuleAddress, Data as byte)

sub procedureI2CExpander_Set_PullUpsPortB(dim ModuleAddress, Data as byte)
You can download code and example for P16 and P18 MCU from:
http://www.microelemente.ro/MikroBasic/ ... pander.zip

Source code of library is available in MikroPascal language:
http://www.microelemente.ro/I2CPortExp_Source.zip
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

kostasgr
Posts: 15
Joined: 16 Jan 2008 12:57

#2 Post by kostasgr » 13 Feb 2008 00:14

Hello!

Is there any posibility to have a code snippet that puts all portA pins output 1?
I tried to do it but it didn't worked. I did set the portA as output and written %11111111 but nothing happens.

Thx:)

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#3 Post by yo2lio » 13 Feb 2008 10:20

Hi,

Unfortunately this library is old and now I can't offer support for them (I don't have time for this).

But you have source code in MikroPascal language : http://www.microelemente.ro/MikroPascal ... Source.zip
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

oliverb
Posts: 570
Joined: 24 May 2007 15:09

#4 Post by oliverb » 14 Jan 2009 11:06

Was the SPI Port Expander source ever published?

I'm curious because I started writing my own version, partly because of the lack of source, mainly to see if the reset pin is really needed?

IMO Reset isn't needed and could be tied to supply, the device can be forced into a known state via software. Currently I can't prove this.

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#5 Post by yo2lio » 14 Jan 2009 12:27

oliverb wrote:Was the SPI Port Expander source ever published?
yo2lio wrote: Unfortunately this library is old and now I can't offer support for them (I don't have time for this).

But you have source code in MikroPascal language : http://www.microelemente.ro/MikroPascal ... Source.zip
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

kostasgr
Posts: 15
Joined: 16 Jan 2008 12:57

#6 Post by kostasgr » 14 Jan 2009 17:30

Well the library worked fine for me. I allready communicated with two port expanders without problems.
Special thank's to yo2lio for converting and sharing his sources.

Post Reply

Return to “mikroBasic General”