In this section we describe how to configure and use the API library.
Include the header file and make a global class instance, i.e., put it outside of any function at the top of the sketch. The constructor of this class takes five variables:
|2||data in pin||DIN|
|3||data out pin||DOUT|
|4||chip select pin||CS|
The chip type should be
true for the MAX7301AAX,
If, for example, we have the clock, data in, data out and chip select on pins 4, 5, 6 and 7 respectively and our chip is of type MAX7301ANI, initialise the class instance as follows:
#include <max7301.h> MAX7301 max7301(4, 5, 6, 7, false);
After initialisation, the MAX7301 is in shutdown mode. Use the
function to make it enter normal operation mode. This is typically done in the
Pins can be configured by using the
pinMode() function which takes the pin
number and a mode as arguments.
||logic input with internal pullup|
For example, configure pin 12 as an input with the internal pullup resistor enabled and pin 22 as an output:
max7301.pinMode(12, GPIO_INPUT_PULLUP); max7301.pinMode(22, GPIO_OUTPUT);
The pin configuration can be queried with the
byte result = max7301.getPinMode(12); // Should return GPIO_INPUT_PULLUP.
digitalWrite() can be used to read from
a pin, or write to a pin.
byte result = max7301.digitalRead(12); max7301.digitalWrite(22, HIGH);
digitalWriteRange() can be used to
read from up to 8 consecutive pin at once. The first parameter indicates the
first pin in the range. The pin states are encoded in one byte with the pin
with the lowest number in its least significant position.
byte result = max7301.digitalReadRange(12); // Read pin 12-19. max7301.digitalWriteRange(22, 0x01); // Set pin 22 HIGH and 23-29 LOW.
The MAX7301 can be put in shutdown mode with the
disable() function. In
this mode, all pins are set to input and the pullup resistors are turned off.
The MAX7301 is capable of transition detection on pins 24 to 30. If a transition is detected, pin 31 will go high.
To set this up, the pins must be configured correctly with the
function and the input pins must be registered for active monitoring with the
First make sure pin 31 is configured as an output pin.
To configure pin 24 as input:
max7301.pinMode(24, GPIO_INPUT); max7301.configureTransitionDetection(24, true);
Finally, activate transition detection with the
function. This function must be called after every transition event to reenable
Transition detection can be disabled with the
Low level functions¶
Registers can be read with the
read() function and written to with the
write() function. The first parameter is the address of the register.
byte result = max7301.read(0x09); // First port configuration register. max7301.write(0x09, 0x55); // Set port 4-7 to output.