Library for MAX7300 GPIO Expander

Dependents:   MAX14871_Shield

Embed: (wiki syntax)

« Back to documentation index

Max7300 Class Reference

Max7300 Class Reference

2-Wire-Interfaced, 2.5V to 5.5V, 20-Port or 28-Port I/O Expander More...

#include <max7300.h>

Public Types

enum  max7300_i2c_adrs_t
 

Valid 7-bit I2C addresses.

More...
enum  max7300_port_type_t
 

Valid port configurations.

More...
enum  max7300_port_number_t
 

Valid port numbers.

More...

Public Member Functions

 Max7300 (I2C *i2c_bus, max7300_i2c_adrs_t i2c_adrs)
 Constructor for Max7300 Class.
 Max7300 (PinName sda, PinName scl, max7300_i2c_adrs_t i2c_adrs)
 Constructor for Max7300 Class.
 ~Max7300 ()
 Default destructor for Max7300 Class.
int16_t enable_ports (void)
 Enables MAX7300 GPIO Ports.
int16_t disable_ports (void)
 Disables MAX7300 GPIO Ports.
int16_t enable_transition_detection (void)
 Enables Transition Detection.
int16_t disable_transition_detection (void)
 Disables Transition Detection.
int16_t config_port (max7300_port_number_t port_num, max7300_port_type_t port_type)
 Configures a single MAX7300 GPIO port.
int16_t config_4_ports (max7300_port_number_t low_port, uint8_t data)
 Configure 4 MAX7300 GPIO ports.
int16_t config_all_ports (max7300_port_type_t port_type)
 Configures all MAX7300 GPIO ports.
int16_t read_port (max7300_port_number_t port_num)
 Read a single MAX7300 GPIO port.
int16_t write_port (max7300_port_number_t port_num, uint8_t data)
 Write a single MAX7300 GPIO port.
int16_t read_8_ports (max7300_port_number_t low_port)
 Read 8 MAX7300 GPIO ports.
int16_t write_8_ports (max7300_port_number_t low_port, uint8_t data)
 Write 8 MAX7300 GPIO ports.
int16_t read_mask_register (bool enable_snapshot)
 Read transition detection mask register.
int16_t write_mask_register (uint8_t data)
 Write transition detection mask register.

Detailed Description

2-Wire-Interfaced, 2.5V to 5.5V, 20-Port or 28-Port I/O Expander

The MAX7300 compact, serial-interfaced, I/O expansion peripheral provides microprocessors with up to 28 ports. Each port is individually user configurable to either a logic input or logic output.

 #include "mbed.h"
 #include "max7300.h"

 int main (void)
 {
      I2C i2c_bus(D14, D15);

      Max7300 io_expander(&i2c_bus, Max7300::MAX7300_I2C_ADRS0);   
      
      for(uint8_t idx = 0; idx < 10; idx++)
      {
          //configure ports 12 - 21 as outputs
          io_expander.config_port((Max7300::max7300_port_number_t) (idx+12), Max7300::MAX7300_PORT_OUTPUT);

          //configure ports 22 - 31 as inputs
          io_expander.config_port((Max7300::max7300_port_number_t) (idx+22), Max7300::MAX7300_PORT_INPUT);
      }

      io_expander.enable_ports();
      
      //rest of application...
 }

Definition at line 74 of file max7300.h.


Member Enumeration Documentation

Valid 7-bit I2C addresses.

16 valid I2C addresses are possible through the connection od AD0 and AD1 to Vcc, GND, SDA, or SCL.

Definition at line 83 of file max7300.h.

Valid port numbers.

Simple enumeration of port numbers

Definition at line 121 of file max7300.h.

Valid port configurations.

Valid port configurations for the MAX7300 are; push-pull GPO, schmitt GPI, schmitt GPI with pull-up.

Definition at line 109 of file max7300.h.


Constructor & Destructor Documentation

Max7300 ( I2C *  i2c_bus,
max7300_i2c_adrs_t  i2c_adrs 
)

Constructor for Max7300 Class.

Allows user to use existing I2C object

On Entry:

Parameters:
[in]i2c_bus- pointer to existing I2C object
[in]i2c_adrs- 7-bit slave address of MAX7300

On Exit:

Returns:
None

Definition at line 53 of file max7300.cpp.

Max7300 ( PinName  sda,
PinName  scl,
max7300_i2c_adrs_t  i2c_adrs 
)

Constructor for Max7300 Class.

Allows user to create a new I2C object if not already using one

On Entry:

Parameters:
[in]sda- sda pin of I2C bus
[in]scl- scl pin of I2C bus
[in]i2c_adrs- 7-bit slave address of MAX7300

On Exit:

Returns:
None

Definition at line 63 of file max7300.cpp.

~Max7300 (  )

Default destructor for Max7300 Class.

Destroys I2C object if owner

On Entry:

On Exit:

Returns:
None

Definition at line 74 of file max7300.cpp.


Member Function Documentation

int16_t config_4_ports ( max7300_port_number_t  low_port,
uint8_t  data 
)

Configure 4 MAX7300 GPIO ports.

Allows user to configure 4 ports at a time

On Entry:

Parameters:
[in]low_port- lowest of 4 ports to configure, on 4 port boundaries as in datasheet
[in]data- Byte with each ports desired type with the following format - xx|xx|xx|xx

On Exit:

Returns:
0 on success, non-0 on failure

Definition at line 164 of file max7300.cpp.

int16_t config_all_ports ( max7300_port_type_t  port_type )

Configures all MAX7300 GPIO ports.

Allows user to configure all ports to a single type

On Entry:

Parameters:
[in]port_type- One of the following port types MAX7300_PORT_OUTPUT MAX7300_PORT_INPUT MAX7300_PORT_INPUT_PULLUP

On Exit:

Returns:
0 on success, non-0 on failure

Definition at line 187 of file max7300.cpp.

int16_t config_port ( max7300_port_number_t  port_num,
max7300_port_type_t  port_type 
)

Configures a single MAX7300 GPIO port.

Configures MAX7300 GPIO port as either an output, input, or input with pullup.

On Entry:

Parameters:
[in]port_num- GPIO port to configure
[in]port_type- One of the following port types MAX7300_PORT_OUTPUT MAX7300_PORT_INPUT MAX7300_PORT_INPUT_PULLUP

On Exit:

Returns:
0 on success, non-0 on failure

Definition at line 128 of file max7300.cpp.

int16_t disable_ports ( void   )

Disables MAX7300 GPIO Ports.

Clears 'S' bit of configuration register

On Entry:

On Exit:

Returns:
0 on success, non-0 on failure

Definition at line 95 of file max7300.cpp.

int16_t disable_transition_detection ( void   )

Disables Transition Detection.

Clears 'M' bit of configuration register

On Entry:

On Exit:

Returns:
0 on success, non-0 on failure

Definition at line 117 of file max7300.cpp.

int16_t enable_ports ( void   )

Enables MAX7300 GPIO Ports.

Sets 'S' bit of configuration register

On Entry:

On Exit:

Returns:
0 on success, non-0 on failure

Definition at line 84 of file max7300.cpp.

int16_t enable_transition_detection ( void   )

Enables Transition Detection.

Sets 'M' bit of configuration register

On Entry:

On Exit:

Returns:
0 on success, non-0 on failure

Definition at line 106 of file max7300.cpp.

int16_t read_8_ports ( max7300_port_number_t  low_port )

Read 8 MAX7300 GPIO ports.

On Entry:

Parameters:
[in]low_port- lowest port of 8 ports to read, on 8 port boundaries as in datasheet. Max is port 24

On Exit:

Returns:
State of ports, or -1 on failure

Definition at line 257 of file max7300.cpp.

int16_t read_mask_register ( bool  enable_snapshot )

Read transition detection mask register.

See page 11 of DS, right hand side column, paragraph 2 for details on one-shot event.

On Entry:

Parameters:
[in]enable_snapshot- true to re-enable transition detection

On Exit:

Returns:
0 on success, non-0 on failure

Definition at line 309 of file max7300.cpp.

int16_t read_port ( max7300_port_number_t  port_num )

Read a single MAX7300 GPIO port.

On Entry:

Parameters:
[in]port_num- MAX7300 port number to read

On Exit:

Returns:
State of port, or -1 on failure

Definition at line 211 of file max7300.cpp.

int16_t write_8_ports ( max7300_port_number_t  low_port,
uint8_t  data 
)

Write 8 MAX7300 GPIO ports.

On Entry:

Parameters:
[in]low_port- lowest port of 8 ports to write, on 8 port boundaries as in datasheet. Max is port 24
[in]data- Data is written to ports

On Exit:

Returns:
0 on success, non-0 on failure

Definition at line 288 of file max7300.cpp.

int16_t write_mask_register ( uint8_t  data )

Write transition detection mask register.

Enables transition detection on Ports 30-24

On Entry:

Parameters:
[in]data- Bits to set

On Exit:

Returns:
0 on success, non-0 on failure

Definition at line 352 of file max7300.cpp.

int16_t write_port ( max7300_port_number_t  port_num,
uint8_t  data 
)

Write a single MAX7300 GPIO port.

On Entry:

Parameters:
[in]port_num- MAX7300 port to write
[in]data- lsb of byte is written to port

On Exit:

Returns:
0 on success, non-0 on failure

Definition at line 239 of file max7300.cpp.