I2C communication, controlling how fast can be, using MCP23008

hI! I am using an arduino and a microchip MCP23008 to test how fast an I2C communcation can be. To see that I am controlling a LED. The LED blinks for some time and then it stays on. After some time blinks again and stays on. So it keeps doint that. My intention is to blink nonstop. The other problem is that thic microchip is 400kHz. When I set the delay in 20 miliseconds or 10 is not able to handle.
#include <Wire.h>

// I2C address of the MCP23008
#define MCP23008_ADDRESS 0x20

// MCP23008 registers
#define IODIR 0x00 // I/O direction register
#define OLAT 0x0A // Output latch register

void setup() {
// Start the I2C communication
Wire.begin();

// Set I2C clock speed to 400kHz
Wire.setClock(400000);

// Set all pins to output (IODIR register to 0x00)
Wire.beginTransmission(MCP23008_ADDRESS);
Wire.write(IODIR);
Wire.write(0x00); // All pins as outputs
Wire.endTransmission();

// Turn off all pins initially (OLAT register to 0x00)
Wire.beginTransmission(MCP23008_ADDRESS);
Wire.write(OLAT);
Wire.write(0x00); // All pins low
Wire.endTransmission();
}

void loop() {
// Turn on the LED connected to pin 0
Wire.beginTransmission(MCP23008_ADDRESS);
Wire.write(OLAT);
Wire.write(0x01); // Set pin 0 high
Wire.endTransmission();

// Wait for 10 milliseconds
delay(10);

// Turn off the LED connected to pin 0
Wire.beginTransmission(MCP23008_ADDRESS);
Wire.write(OLAT);
Wire.write(0x00); // Set pin 0 low
Wire.endTransmission();

// Wait for 10 milliseconds
delay(10);
} What could be the problem?

Can you tell more ?
Can you show a photo with all the wires ? Which Arduino board do you use ? Do you have pullup resistors ? Do you have a MCP23008 module or just the chip ? On a breadboard ? without decoupling capacitors ? There are many things that can go wrong.

What happens at 100kHz, I suppose it will work better.
Can you set the delays to 100ms, to see the led blinking.

SDA SCL with 5k resistor to arduino UNO. Only the chip. on breadboard. without decoupling capacitors. Also in 100khz works same.

Breadboards can have bad contacts. The on and off switching of the led might cause noise which gets somehow to the I2C bus. That is just a guess, but I'm thinking in that direction.
A schematic or a photo will help us to see if the GND wire is connected properly.

I moved your topic to an appropriate forum category @albionqovanaj.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

You can test how many bytes really have been transmitted.

1 Like

You should also put a resistor or direct connect the RESET to Vcc, otherwise the IC it's not stable at all. (I know 'cause happened to me in the past)

Ciao, Ale.

2 Likes

I didn't know that, I think that could be the problem. I checked the datasheet:

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.