I2C and MCP23008

Discussion on projects that are created by users and posted on mikroElektronika website.
Post Reply
Author
Message
om3bc
Posts: 7
Joined: 27 Mar 2019 09:01

I2C and MCP23008

#1 Post by om3bc » 27 Mar 2019 09:28

I use processor PIC32MX460F512L, mikroBasic Pro for PIC32 v 4.0.0 and two MCP23008 - one for input and one for output. Output working always fine, but input no.

function for read from MCP:
sub function MCP_Read(dim rAddr as byte) as byte
I2C2_Start() ' issue I2C start signal
I2C2_Write(0x42) ' send byte via I2C (device address + W)
I2C2_Write(rAddr) ' send byte (address of EEPROM location)
I2C2_Restart() ' issue I2C signal repeated start
I2C2_Write(0x43) ' send byte (device address + R)
result = I2C2_Read(_I2C_NACK) ' Read the data (NO acknowledge) PROGRAM STOPPED HERE
I2C2_Stop()
end sub

INIT is:
I2C2_Init(100000)
I2C2_SetTimeoutCallback(3000, @I2C2_TimeoutCallback)
MCP_Write($00,$FF)
MCP_Write($01,$00)
MCP_Write($02,$FF)
MCP_Write($03,$00)
MCP_Write($04,$00)
MCP_Write($05,%00010010)
MCP_Write($06,$FF)

Can anyone tell me why?

Joe Illes

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: I2C and MCP23008

#2 Post by stefan.filipovic » 03 Apr 2019 18:23

Hi Joe,

Welcome to the mikroE forum.

Would you like to share your main function?

Which register address have you tried to read?

Unfortunately, we are not working with 8-bit MCP expanders so I'm unable to test your code.

Kind regards,
Stefan Filipović

om3bc
Posts: 7
Joined: 27 Mar 2019 09:01

Re: I2C and MCP23008

#3 Post by om3bc » 04 Apr 2019 17:23

I try to read address $09 (PORT (GPIO) REGISTER).
I had no problem with MikroBasicPro version 3.5 or 3.6. I have detected problem only with v 4.0.

Joe

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: I2C and MCP23008

#4 Post by stefan.filipovic » 10 Apr 2019 14:17

Hi Joe,

That's the correct register address, but what about the slave address, how did you set A2, A1, and A0 pins of the MCP23008?
With your code, A2 and A1 pins must be connected to GND, but A0 pin must be connected to VCC.

I've tested I2C Simple and I2C Advanced examples from the following path: C:\Users\Public\Documents\Mikroelektronika\mikroBasic PRO for PIC32\Examples\Development Systems\EasyPIC Fusion v7\EEPROM (I2C)
I have not reproduced any issue with I2C, it worked well with both v.3.6.0 and v.4.0.0 of the mikroBasic PRO for PIC32.

Kind regards,
Stefan Filipović

om3bc
Posts: 7
Joined: 27 Mar 2019 09:01

Re: I2C and MCP23008

#5 Post by om3bc » 10 Apr 2019 15:52

Hi Stefan,

my program is a bit complex, it contains cca 25000 basic lines.
Address is OK. Now program running with MikroBasicPro for PIC32 v 4.0.0, but I do not understanding this problem:

If I compiling program with v 4.0.0, program running good. If I compiling same program without the changes with v3.6.1, the compiler does not detect any error, but the program loaded into the processor does not work. Works a few seconds, then stops. Program have problem with FT800_PWM_FadeIn, FT800_CP_IsIdle() (and maybe with others). There is no answer, the program stops.
Same program compiled with v 4.0.0 working.

Joe Illes

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: I2C and MCP23008

#6 Post by stefan.filipovic » 11 Apr 2019 13:19

Hi Joe,

It's great if it works with the latest version of the mikroBasic.

It was a huge upgrade from version 3.6.0 to version 4.0.0, one of the many changes is that the VisualTFT has integrated into the compiler with the latest version.
Probably, there were some bugs in the version 3.6.0 with FT800 library which cause this issue.
Anyway, it's always recommended using the latest version of our compilers.

Kind regards,
Stefan Filipović

Post Reply

Return to “User Projects”