Arduino DUE - SDA1 & SCL1 as digital pins

Greetings,

I just redesigned a board that I am using the DUE to drive. I realized I switched some pins around, and for one I put some IO lines on the SDA1 and SCL1 pins.

For some reason these pins are not behaving as I intended. I am defining them as pins 70 & 71 in the software and I am curious if there is anything special I need to do with these pins to get them to work?

When I say not behaving as I intended, I mean I am driving one low and another high, but then i look and they're both high at 3.3V.

Your code is not visible to us...

You don't need my code, I am asking if there is anything special that needs to be done to use SDA1 and SCL1 pins as digital IO, if there is anything special about them that requires extra work to make operate as Digital I/O pins.

#include <Wire.h>
#include "ADE_Registers.h"

union binaryFloat{
  float value;
  byte binary[4];
};

typedef enum ADE_SM
{
  POWER,
  IDLE,
  READ
} ADE_SM;

unsigned long period          = 500;
unsigned long previousMillis  = 0;

uint8_t IRQ_1                 = 4;                        // Interrupt 1, pin 3
uint8_t IRQ_0                 = 5;                        // Interrupt 0, pin 2
uint8_t ADE_RESET             = 12;                       // MCU controlled ADE7880 reset
uint8_t PM0                   = 13;                       // (PM1/PM0) - PSM0 Normal - (0/1), PSM1 Reduced - (0/0), PSM2 Low (1/0), PSM3 Sleep (1/1)
uint8_t PM1                   = 70;
uint8_t I2C_EN                = 71;                       // MCU controlled chip select used for selecting I2C comms interface with the ADE7880
uint8_t MCU_LED1              = 41;                       // D1 - LED's Ref Designators
uint8_t MCU_LED2              = 39;                       // D2
uint8_t MCU_LED3              = 37;                       // D3
uint8_t MCU_LED4              = 35;                       // D4
uint8_t MCU_LED5              = 33;                       // D5

float V_DIVIDER               = ((1000000+1000)/1000);    // Voltage divider constant to reverse the affect of a voltage divider when computing the register values
String cmd                    = "";                       // Initialize to empty string - global variable used in the ADE_Parser.ino file
 
void setup() {
  Wire.begin();
  Serial.begin(115200);                                                                    
  Serial1.begin(19200, SERIAL_8E1);                                   // Baud rate for communicating with GS2 VFD - Ensure P9.01 in GS2 is set to 02 - SERIAL_8E1 - 1 start bit, 8 data bits, 1 even parity bit, and 1 stop bit.

  pinMode(I2C_EN, OUTPUT);                        // ADE chip select pin used for enabling 12C as active serial port.
  pinMode(ADE_RESET, OUTPUT);                     // ADE reset pin.
  pinMode(PM0, OUTPUT);                           // Power mode pin 0.
  pinMode(PM1, OUTPUT);                           // Power mode pin 1.
  pinMode(MCU_LED1, OUTPUT);
  pinMode(MCU_LED2, OUTPUT);
  pinMode(MCU_LED3, OUTPUT);
  pinMode(MCU_LED4, OUTPUT);
  pinMode(MCU_LED5, OUTPUT);
  pinMode(IRQ_1, INPUT);
  pinMode(IRQ_0, INPUT);

  digitalWrite(PM0, HIGH);    
  digitalWrite(PM1, LOW);   
}

Here it is then.

There are indeed 70 and 71: https://github.com/arduino/ArduinoCore-sam/blob/master/variants/arduino_due_x/variant.h#L150

And it is also defined as digital pin: https://github.com/arduino/ArduinoCore-sam/blob/master/variants/arduino_due_x/variant.cpp

Here are the pinMode() and digitalWrite(): https://github.com/arduino/ArduinoCore-sam/blob/master/cores/arduino/wiring_digital.c

I don't see any trouble, but it is a high number. Maybe there is a bug somewhere.

Can you make a minimal sketch that does not include a library and only sets the pinMode for those two pins and toggle them. Try to measure them with a multimeter.
Show the sketch and tell us what the result is.

image

 Wire.begin();
 Serial1.begin(19200, SERIAL_8E1);    // Baud rate for communicating with GS2 

Looks like Serial1 could take over SDA1

1 Like

Did you try this in setup()?

pinMode(70, OUTPUT);
pinMode(71, OUTPUT);

Oooooo good catch let me disable that and try it

Barebones test:

const uint8_t SDA1 = 70;
const uint8_t SCL1 = 71;

void setup() {
  pinMode(SDA1, OUTPUT);
  pinMode(SCL1, OUTPUT);
  digitalWrite(SDA1, LOW);
  digitalWrite(SDA1, LOW);
}

void loop() {
 }

@dlloyd do you know how many bugs are in your sketch ?
SDA1 and SCL1 are already defined here: https://github.com/arduino/ArduinoCore-sam/blob/master/variants/arduino_due_x/variant.h#L159

static const uint8_t SDA1 = PIN_WIRE1_SDA;
static const uint8_t SCL1 = PIN_WIRE1_SCL;

It is not a toggle and they are already default low after a pinMode, and you used SDA1 twice.


uint8_t PM1                   = 70;
uint8_t I2C                   = 71;

void setup() {
  // put your setup code here, to run once:
  pinMode(70, OUTPUT);                                 // Power mode pin 1.
  pinMode(71, OUTPUT);                                 // Power mode pin 1
 
  digitalWrite(70, HIGH);   
  digitalWrite(71, HIGH);  
}
  
  void loop() {
  // put your main code here, to run repeatedly:

}

Alright so I did this code, and they did exactly what I wanted when not placed on the PCB I designed ( get 3.3V w the DMM when digitally written to HIGH and 0V when digitally written to LOW). Which tells me it is probably a problem with my schematic then (since it works fine when not attached to my board). I noticed that pin 13, is doing the same thing...

where when I put the DUE on my PCB and run the code, they stay pulled high no matter what I set the digitalWrite to (they meaning pins 70, 71, and 13 when I added 13 n there). And there is no pull up resistor on either of these rails.

I am using them to drive a power mode select pin (PM1) on an energy metering chip and an I2C select pin on the same chip. which is why I have PM1 = 70 and I2C = 71, just for reference when using the DMM.

Yeah, that's what happens when you compile using an UNO (haven't used a DUE in 3 years) and make the pin names match the diagram. I know about the default low thing and the default high thing (with pullups enabled), but no harm done here.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.