AVR128DB28 Trouble using part of PORTC

I must be doing something wrong, but for the life of me can't figure out what. Briefly, I'm trying to use an AVR128DB28 and the problem I'm having is that some of the pins in the MVIO port (PORTC) aren't responding when I try to use digitalWrite() to set them HIGH or LOW.

I am using the SOIC version of the chip, which was sourced from Mouser. I have tried three of them so far- two on a custom breakout board and one on a basic SOIC-DIP adapter board. My custom breakout board is very simple- it just has a DIP socket for mounting a Flash chip, and an MCP1799 3.3V LDO to supply 3.3V to the Flash chip and also let me run the MVIO port at 3.3V. On one of the breakout boards I populated everything, on the other one I only populated the decoupling caps.

For programming I am using a CH340 USB-Serial adapter with a 4k7 resistor between TX and RX, and a 240R resistor between the USB-Serial adapter and breakoutboard. I can successfully program all three of the boards. They run a blink sketch without any problem (as long as I'm not trying to blink one of the PORTC pins) and they all communicate over serial when I hook up a second USB-Serial adapter to the hardware UART.

The puzzling thing about the fault is that two of the PORTC pins (PC3 and PC2) respond completely normally. I can digitalWrite() them without any problem, and their output when they are HIGH matches the voltage on the VDDIO2 pin. Pins PC1 and PC0 don't do anything at all, even setting them to inputs with pullups enabled doesn't drive them HIGH.
For example, the following code drives pin PC3 HIGH for 5 seconds, then LOW for five seconds:

void setup() {
pinMode(PIN_PC3, OUTPUT);
}

void loop() {
digitalWrite(PIN_PC3, HIGH);
delay(5000);
digitalWrite(PIN_PC3, LOW);
delay(5000);
}

But when using the following code pin PC1 just floats anywhere from 20mV to about 60mV:

void setup() {
pinMode(PIN_PC1, OUTPUT);
}

void loop() {
digitalWrite(PIN_PC1, HIGH);
delay(5000);
digitalWrite(PIN_PC1, LOW);
delay(5000);
}

I've checked for shorts using a microscope and multimeter, and made sure that the pins on the breakout boards are actually connected to the pins on the chip itself.

Here is the basic circuit diagram that shows how I have the basic SOIC-DIP breakout board wired up. As you can see it is very simple, and works in that I can upload sketches to the board and have most of the pins respond as expected. The decouple caps are 0.1uF.

Hopefully someone can point out something dumb that I'm missing, because I'm stumped.

What core are you using?

Sorry, I should have said- I am using DrAzzy's DXCore.

See if this works just to check


PORTC_DIRSET = 1<<1 | 1<<0;

loop()
{	

	PORTC_OUTSET = 1<<1 | 1<<0;

	delay();

	PORTC_OUTCLR = 1<<1 | 1<<0;

	delay();

}

Thanks for your input. As a sanity check I first tested this code:

void setup() {
PORTC_DIRSET = 1<<3 | 1<<2;
}

void loop() {
PORTC_OUTSET = 1<<3 | 1<<2;
delay(5000);
PORTC_OUTCLR = 1<<3 | 1<<2;
delay(5000);
}

Which toggles PORTC3 and PORTC2 as I'd expect. Then I ran your code:

void setup() {
PORTC_DIRSET = 1<<1 | 1<<0;
}

void loop() {
PORTC_OUTSET = 1<<1 | 1<<0;
delay(5000);
PORTC_OUTCLR = 1<<1 | 1<<0;
delay(5000);
}

... and it works! Pin C1 and C0 toggle high and low as expected. If I change the PORTC_DIRSET to pinMode() then the pin stops responding.
I'm so glad to have found a workaround to this, thanks for you help. I'd be very interested to see if anyone else can replicate this fault, and what the explanation is.

There is a bug with 28 pin parts in dxcore, a copy paste error duplicated two lines of the digital pin to port lookup table, and the result is that pins 0 and 1 in every port after portA are broken, and controlled by the next port's pin 0 and 1. It was reported a couple of days ago and will be in an urgent bugfix release this week

That's great to know, I'm glad it wasn't just because I was being a doofus :slight_smile: Thanks for all you've done to bring these micros to Arduino, I'm a big fan of your previous ATTiny cores too.

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