Using IO
Last updated
Last updated
The Binho Nova Multi-Protocol USB Host Adapter features a total of 5 x IO pins. Each of the IO pins is capable of multiple functions. The graphic below present the pin out as well as the functions of each of the IO pins.
The operating mode of the Binho Nova Multi-Protocol USB Host Adapter is set to IO by default at power-on. If the host adapter is in another mode of operation, then only the subset of IO pins that are unused will be available for use as IO.
Discussion regarding the specific protocols will follow this chapter, and for now the focus will be on the general use of the IO pins. These functions include Digital Input, Digital Output, Analog Input, Analog Output, PWM output, as well as interrupt-enabled inputs.
Despite the vast configuration options, this can all be achieved using just three commands.
All IO Commands must be prefaced by IO[n]
, where n is the pin number. The Binho Nova Multi-Protocol USB Host Adapter features 5 pins, therefore the only valid values for n are integers from 0 through 4.
Command
Description
Link
MODE
Gets/sets the current mode of a specific IO signal.
INT
Gets/sets the interrupt configuration of a specific IO signal.
VALUE
Gets/sets the current value of a specific IO signal. The meaning of the value is dependent on the current mode setting of the signal.
PWMFREQ
Gets/sets the current value of the PWM frequency of a specific IO signal. This is only applicable when in PWM Mode. Note that IO0 and IO2 share a PWM Frequency, and IO3 and IO4 share a PWM Frequency.
All 5 of the IO pins are capable of functioning as a digital input pin. A pin can be set as a digital input by setting the MODE
to DIN
. The value of the input can then be queried. The following example demonstrates how to use IO2 as a digital input and get it's current value.
All 5 of the IO pins are capable of functioning as a digital output pin. A pin can be set as a digital output by setting the MODE
to DOUT
. The value of the pin can then be set using the VALUE
command. The following example demonstrates how to use IO2 as a digital output and set its output to HIGH.
All 5 of the IO pins are capable of functioning as analog inputs. A pin can be set as an analog input by setting the MODE
to AIN
. The value of the pin can then be queried. The measured value will be returned in both ADC counts (12-bit integer) and in units of volts. Note that the voltage reference is 3.3 Volts. The following example demonstrates how to use IO2 as an analog input and get it's current value.
Only IO1 is capable of functioning as an analog output. This pin can be configured to use the 10-bit DAC to output a voltage between 0 and 3.3 Volts. IO1 can be set as an analog output by setting the MODE
to AOUT
. The output voltage can then be set using the VALUE
command. The output voltage can be set either by passing a voltage or a 10-bit integer value. Note that the voltage reference is 3.3 Volts. The following example demonstrates how to use IO1 as an analog output.
IO0, IO2, IO3, and IO4 pins have PWM output capabilities. The duty cycle and frequency can both be controlled programmatically. The duty cycle can be set either in counts from 0 to 1024, or in percentage from 0% to 100%. Both are implemented with the VALUE
command.
The default PWM Frequency is 10kHz, but can be changed from 750Hz up to 80kHz.
IO0 and IO2 PWM peripheral share a timer, so the PWMFREQ setting for these channels will always be the same. IO3 and IO4 PWM peripheral also share another time, so the PWMFREQ setting for these channels will always be the same.
When changing the PWM Frequency, the current duty cycle assigned to that signal will remain unchanged.
IO1, IO2, IO3, and IO4 signals support hardware interrupts. The interrupts can be configured to fire on rising edge, on falling edge, or on any edge. There is much more discussion on how to handle interrupts on this page.