In this case we will read out the pins from one whole port and write the read value to another port.
Setup steps
Example code
#define IN_PORT IOPORT_PORTA
#define OUT_PORT IOPORT_PORTB
#define MASK 0x00000060
static void ioport_init(void)
Initializes the IOPORT service, ready for use.
static void ioport_set_port_dir(ioport_port_t port, ioport_port_mask_t mask, enum ioport_direction dir)
Set I/O direction for a group of pins in a single IOPORT.
Workflow
- It's useful to give the ports symbolic names:
#define IN_PORT IOPORT_PORTA
#define OUT_PORT IOPORT_PORTB
- Note
- The port names differ between architectures:
- MEGA_RF, MEGA and XMEGA: There are predefined names for ports: IOPORT_PORTA, IOPORT_PORTB ...
- UC3: Use the index value of the different IO blocks: 0, 1 ...
- SAM: There are predefined names for ports: IOPORT_PIOA, IOPORT_PIOB ...
- Also useful to define a mask for the bits to work with:
- Initialize the ioport service. This typically enables the IO module if needed.
- Set one of the ports as input:
static void ioport_set_pin_dir(ioport_pin_t pin, enum ioport_direction dir)
Set direction for a single IOPORT pin.
- Set the other port as output:
Usage steps
Example code
static void ioport_set_port_level(ioport_port_t port, ioport_port_mask_t mask, enum ioport_value level)
Set a group of IOPORT pins in a single port to a specified logical value.
static ioport_port_mask_t ioport_get_port_level(ioport_pin_t port, ioport_port_mask_t mask)
Get current value of several IOPORT pins in a single port, which have been configured as an inputs.
uint32_t ioport_port_mask_t
Workflow
- Define a variable for port date storage:
- Read out from one port:
- Put the read data out on the other port: