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
I2C and MCP23008
- stefan.filipovic
- mikroElektronika team
- Posts: 1135
- Joined: 18 Dec 2018 10:30
Re: I2C and MCP23008
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,
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ć
Re: I2C and MCP23008
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
I had no problem with MikroBasicPro version 3.5 or 3.6. I have detected problem only with v 4.0.
Joe
- stefan.filipovic
- mikroElektronika team
- Posts: 1135
- Joined: 18 Dec 2018 10:30
Re: I2C and MCP23008
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,
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ć
Re: I2C and MCP23008
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
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
- stefan.filipovic
- mikroElektronika team
- Posts: 1135
- Joined: 18 Dec 2018 10:30
Re: I2C and MCP23008
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,
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ć