Blogue de Guillaume DALLAIRE's Blog

June 25, 2008

Using a MAX7300 I/O port expander with an Arduino

Filed under: arduino — Tags: , — gdallaire @ 8:11 pm

The MAX7300 from Maxim is an I²C interfaced 20-Port or 28-Port I/O expander. See this page for more information.

With this simple IC, you can expand the total number of digital I/O normally available in a Arduino based design. The wire library eases the I²C interfacing between the MCU and the MAX7300. Here is a example of how to use it. I first wrote a function that sends one command to the I/O expander:

#include <Wire.h>
byte MAX7300_Address = 0x40;  // MAX7300 A0=0 A1=0 A2=0 A3=0
void sendI2C(byte command, byte data)
{
  Wire.beginTransmission(MAX7300_Address);
  Wire.send(command);
  Wire.send(data);
  Wire.endTransmission();
}

The less obvious thing is the address used as argument for the Wire.begin() function. As noted in the Wire reference, this address is 7 bit long (because the R/W bit is set “inside” the library). For the MAX7300, the address format becomes 0b100NNNN where NNNN are A3,A2,A1,A0.

Then to use the MAX7300, you first need to configure it as follow:

void setup()
{
  Wire.begin();
  sendI2C(0x04, 0x01); // Shutdown disabled
  sendI2C(0x0B, 0x55); // P15, P14, P13, P12 ports in OUTPUT mode
  ....
}

Finally, for example, to clear ports P20 to P27:

sendI2C(0x54, 0x00);

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.

Powered by WordPress