SAM4SD32 (SAM4S-EK2)
Loading...
Searching...
No Matches
Advanced use case doing port access

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.
Definition ioport.h:145
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.
Definition ioport.h:251
@ IOPORT_DIR_OUTPUT
Definition ioport.h:78
@ IOPORT_DIR_INPUT
Definition ioport.h:77

Workflow

  1. 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 ...
  2. Also useful to define a mask for the bits to work with:
    • #define MASK 0x00000060
  3. Initialize the ioport service. This typically enables the IO module if needed.
  4. Set one of the ports as input:
  5. Set the other port as output:

Usage steps

Example code

value = ioport_get_port_level(IN_PORT, MASK);
ioport_set_port_level(OUT_PORT, MASK, value);
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.
Definition ioport.h:288
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.
Definition ioport.h:315
uint32_t ioport_port_mask_t
Definition ioport_pio.h:95

Workflow

  1. Define a variable for port date storage:
  2. Read out from one port:
  3. Put the read data out on the other port: