SAMB11 XPLAINED PRO Read GPIO Level

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi There

I have a problem with reading a level on the pins. The code is configured in ATMEL START and  int_main() modified in atmel studio. All gpio are defined in driver_init.c  and not included to this code but from there I can control the pin level (true/false) also  I have a connected a LED to the GPIO_5.

​So, the problem is, no mater what  level I set on the pin (diode On/OFF) the serial port always displays"low".

#include <atmel_start.h>
#include <atmel_start_pins.h>
#include "driver_init.h"

struct io_descriptor *io1;

void USART_0_test(void)
{
 usart_sync_get_io_descriptor(&USART_0, &io1);
 usart_sync_enable(&USART_0);
}

int main(void)
{
 /* Initializes MCU, drivers and middleware */
 atmel_start_init();
 USART_0_test();
  
 bool pin_level;
 
 pin_level = gpio_get_pin_level(GPIO_5);
 if (pin_level == 1)
 {
   io_write(io1, (uint8_t *)"high", 4);
 }
 else
 {
   io_write(io1, (uint8_t *)"low", 3);
 }
}

Last Edited: Thu. May 25, 2017 - 10:48 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I haven't been able to get the pin_level to go high, low either maybe its because this gpio_get_pin_level() function was meant for pins being used as an input rather than using it as an output which you know what state it will be by calling the gpio_set_pin_level() function. I have noticed by setting the direction of the pin as an input and then calling the gpio_set_pin_level() the serial terminal will show a constant high output, which is why I believe the gpio_set_pin_level() was meant to for pins that are being driven, but I may be wrong haven't had much time to play around with this.  

 

Have you at least got the LED to light on and off?

MADEIT

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This seems to be a double post so I'll lock it for now, continue in the other thread.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Topic locked