I want to monitor 100 GPIO pins on the AT32UC3C0128C and indicate the changes on the USART (RS-485 transceiver).

In the code snippet below, I have set one of the pins as an input with the internal pull up activated.

#include <asf.h>
#include <gpio.h>
#include "PinDefine.h"
int temp;
int main (void)
    /* Insert system clock initialization code here (sysclk_init()). */



    if (gpio_get_pin_value(AVR32_PIN_PA00) == true)


    /* Insert application code here, after the board has been initialized. */

I understand that I need to configure each pin (copy and paste exercise). What is best way for me to monitor the GPIO, without having 100 if {} statements? Haven't figured out the USART yet.

Any suggestions will be appreciated. Thanks. (new to coding)

  • \$\begingroup\$ Use switch-case? \$\endgroup\$ – Leon Heller Jul 22 '18 at 16:13
  • \$\begingroup\$ if you use a case statement when the code breaks will the rest of the i/o's be ignored? \$\endgroup\$ – JOHNDOE Jul 22 '18 at 16:18
  • \$\begingroup\$ I don't have experience with AT32 but can you handle input register ? \$\endgroup\$ – Long Pham Jul 22 '18 at 16:50
  • 1
    \$\begingroup\$ You should probably iterate over the ports and bits rather than write specific code for each. But the question is far too broad as you haven't specified what you are looking for. Any sort of reporting scheme beyond giving all the values over and over slowly would be a form of compression and picking appropriate compression requires having a sense of the behavior of the data and/or what aspects of it you do and do not care about. \$\endgroup\$ – Chris Stratton Jul 22 '18 at 16:59
  • 1
    \$\begingroup\$ "copy and paste exercise" is a safe retreat for a lazy mind. You can do better than that. \$\endgroup\$ – Maple Jul 22 '18 at 20:26

I've never used Atmel chips so don't take the example as is.

As Long and Chris pointed in the comments you can use direct register access

I would recommend reading first the chapter 23 of datasheet with the gpio section.

For pullups (use set register to avoid messing up with other functions):

AVR32_GPOI.port[0].puers = bit_pattern_0
AVR32_GPOI.port[1].puers = bit_pattern_1
AVR32_GPOI.port[2].puers = bit_pattern_2
AVR32_GPOI.port[3].puers = bit_pattern_3

where bit_pattern_x is a 32 bit unsigned word containing the pullup configuration for portX PIN00 being driven by bit 0 , PIN01 being driven by bit 1 and so on. Setting bit to one activates the pullup.

Similar the direction registers but use clear register for the same reason :

AVR32_GPOI.port[0].oderc = bit_pattern_0
AVR32_GPOI.port[1].oderc = bit_pattern_1
AVR32_GPOI.port[2].oderc = bit_pattern_2
AVR32_GPOI.port[3].oderc = bit_pattern_3

You might need to unlock the ports first using AVR32_GPOI.port[0].lockc[x]

Now you read the 32 pins at once reading AVR32_GPOI.port[x].pwr

You can either send data as is , just masked by bit_pattern_x, to the host or loop through the bits using the same bit pattern to skip unused pins.

  • \$\begingroup\$ Thanks so. The bit pattern will be hex value that will setup the entire port as pullup or input. \$\endgroup\$ – JOHNDOE Jul 23 '18 at 11:09
  • \$\begingroup\$ @JOHNDOE Is a binary pattern with "1" in the place you are using the pin. \$\endgroup\$ – Dorian Jul 23 '18 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.