Skip to content

the pin mode is changed to INPUT mode #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Makeblock-official opened this issue Aug 23, 2015 · 6 comments
Closed

the pin mode is changed to INPUT mode #28

Makeblock-official opened this issue Aug 23, 2015 · 6 comments
Assignees

Comments

@Makeblock-official
Copy link

on file wiring.c line 87(Fun init()) Setup all pins (digital and analog) in INPUT mode (default is nothing)
Pin mode should not be set.This line should comment.

on file wiring_digital.c line 81 (Fun digitalWrite()) Enable pull-up resistor.
This line should comment.

The pin mode will be initialized when construct the object.

For example:

class LED
{
  public:
    LED(int pin);
    void low();
    void high();
  private:
    int led_pin;
};

LED::LED(int pin)
{
  led_pin = pin;
  pinMode(led_pin, OUTPUT) ;
}

void LED::low()
{
  digitalWrite(led_pin, LOW);
}
void LED::high()
{
  digitalWrite(led_pin, HIGH);
}

LED led(13);
void setup() {
}

void loop() {
  led.high();
  delay(1000);
  led.low();
  delay(1000);
}

Since the pin mode is changed to INPUT,led.high() is set to input pull-up and led.low() is set to input pull-down.So the led will be very dark.

@aethaniel
Copy link
Contributor

Indeed, the pull-up should be set only on a digitalWrite(pin, HIGH) when pin is in INPUT mode.

aethaniel added a commit to aethaniel/ArduinoCore-samd that referenced this issue Sep 9, 2015
aethaniel added a commit to aethaniel/ArduinoCore-samd that referenced this issue Sep 21, 2015
@Makeblock-official
Copy link
Author

It is not correct, I mean, Pin mode should not be set at initialization.

the Fun void init( void )
// Setup all pins (digital and analog) in INPUT mode (default is nothing)
for ( ul = 0 ; ul < NUM_DIGITAL_PINS ; ul++ )
{
pinMode( ul, INPUT ) ;//This line should comment.
}

void digitalWrite( uint32_t ulPin, uint32_t ulVal )
{
// Handle the case the pin isn't usable as PIO
if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN )
{
return ;
}

the Fun void digitalWrite( uint32_t ulPin, uint32_t ulVal )
// Enable pull-up resistor
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg=(uint8_t)(PORT_PINCFG_PULLEN) ;//This line should comment.

1 similar comment
@Makeblock-official
Copy link
Author

It is not correct, I mean, Pin mode should not be set at initialization.

the Fun void init( void )
// Setup all pins (digital and analog) in INPUT mode (default is nothing)
for ( ul = 0 ; ul < NUM_DIGITAL_PINS ; ul++ )
{
pinMode( ul, INPUT ) ;//This line should comment.
}

void digitalWrite( uint32_t ulPin, uint32_t ulVal )
{
// Handle the case the pin isn't usable as PIO
if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN )
{
return ;
}

the Fun void digitalWrite( uint32_t ulPin, uint32_t ulVal )
// Enable pull-up resistor
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg=(uint8_t)(PORT_PINCFG_PULLEN) ;//This line should comment.

@aethaniel
Copy link
Contributor

@Makeblock-official, can you put comments in the pull request itself on the lines which disturb you, please?

mattairtech added a commit to mattairtech/ArduinoCore-samd that referenced this issue Nov 24, 2015
xiaoyu-makeblock added a commit to xiaoyu-makeblock/ArduinoCore-samd that referenced this issue Dec 11, 2015
…call void init( void ). Setup all pins (digital and analog) in INPUT mode (default is nothing)

such as :LiquidCrystal examples
@WestfW
Copy link

WestfW commented Dec 28, 2015

Having all pins start out as inputs is compatible with the AVR Arduinos...

@sandeepmistry
Copy link
Contributor

Closing as setting all pins to INPUT is desired, to maintain compatibility AVR based boards as mentioned by @WestfW above.

#94 is open the track @Makeblock-official's concern from #28 (comment).

the Fun void digitalWrite( uint32_t ulPin, uint32_t ulVal )
// Enable pull-up resistor
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg=(uint8_t)(PORT_PINCFG_PULLEN) ;//This line should comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants