ATmega328p PORTB not working ?

hello i have some atmega328p chips i bought a few months ago and when i first got them everything worked fine now I tried to use them and for some reason port B is not working port D works fine ive tested them both and have the same problem with both I did mess with the fuses a little but i tried to reset the fuses with arduino and that seemed to work but still having the same problem like I said port D works but not port B dont know any suggestions ?

Could you have caused electrical damage - for example by drawing too much current ?

Have you a short test program that demosntrates the problem? If so, please post it.

...R

void setup() { pinMode(PB0, OUTPUT); // sets the pin as output }

void loop() { digitalWrite(PB0, HIGH); // sets the LED on delay(1000); // waits for a second digitalWrite(PB0, LOW); // sets the LED off delay(1000); // waits for a second }

here is the program i used to test port B with

i just tetsed port C and it is not working either :frowning:

there is no way i used to much current because all i have used is LEDs one at a time

PB0 is defined as 0, a number of a bit in a register,

so your test is a digitalWrite to pin 0.

https://www.arduino.cc/en/Reference/PortManipulation

have u tried to re-burn the bootloader again? not sure but it may have a defective part in the loader

mm could be but it was working a few weeks ago ?

well I have two microcontrollers and both have the same problem ?

bandmwhitt2013: void setup() { pinMode(PB0, OUTPUT); // sets the pin as output }

void loop() { digitalWrite(PB0, HIGH); // sets the LED on delay(1000); // waits for a second digitalWrite(PB0, LOW); // sets the LED off delay(1000); // waits for a second }

The code does not what you think it does.

It tests a led that is connected to pin 0, the mapping to the ports is boardspecific.

On a mega one of the tables starts like as follows:

const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
    // PORTLIST     
    // -------------------------------------------      
    PE  , // PE 0 ** 0 ** USART0_RX 
    PE  , // PE 1 ** 1 ** USART0_TX 
    PE  , // PE 4 ** 2 ** PWM2  
    PE  , // PE 5 ** 3 ** PWM3  
    PG  , // PG 5 ** 4 ** PWM4  
    PE  , // PE 3 ** 5 ** PWM5  
    PH  , // PH 3 ** 6 ** PWM6  
    PH  , // PH 4 ** 7 ** PWM7

So your test disabled rx and tried to lite a led connected there (on port E?).

Probably mega is wrong, it seems to match only a 2560.

This (standard) should show at least the pin to port and bitmask

const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
    _BV(0), /* 0, port D */
    _BV(1),
    _BV(2),
    _BV(3),
    _BV(4),
    _BV(5),
    _BV(6),
    _BV(7),
    _BV(0), /* 8, port B */
    _BV(1),
    _BV(2),
    _BV(3),
    _BV(4),
    _BV(5),
    _BV(0), /* 14, port C */
    _BV(1),
    _BV(2),
    _BV(3),
    _BV(4),
    _BV(5),
};

bandmwhitt2013: mm could be but it was working a few weeks ago ?

so it is more possible of a hardware damage cz of static charge

Probably the chip is not damaged at all.

The test is 'damaged'.

i hope not... but if so well i guess another one bites the dust i ordered two more anyway

Create a proper test based on:

DDRD is the direction register for Port D (Arduino digital pins 0-7). The bits in this register control whether the pins in PORTD are configured as inputs or outputs so, for example:

DDRD = B11111110;  // sets Arduino pins 1 to 7 as outputs, pin 0 as input
DDRD = DDRD | B11111100;  // this is safer as it sets pins 2 to 7 as outputs
                      // without changing the value of pins 0 & 1, which are RX & TX 

//See the bitwise operators reference pages and The Bitmath Tutorial in the Playground

PORTD is the register for the state of the outputs. For example;

PORTD = B10101000; // sets digital pins 7,5,3 HIGH

You will only see 5 volts on these pins however if the pins have been set as outputs using the DDRD register or with pinMode().

PIND is the input register variable It will read all of the digital input pins at the same time.

here is the program i used to test port B with

void setup()
{
  pinMode(PB0, OUTPUT);      // sets the pin as output
}

void loop()
{
  digitalWrite(PB0, HIGH);   // sets the LED on
  delay(1000);                  // waits for a second
  digitalWrite(PB0, LOW);    // sets the LED off
  delay(1000);                  // waits for a second
}

You say that you are using a AT328 chip. PB0 is physical pin 14 on the processor. It is digital pin 8 on the Arduino products using that chip. Do you have an led with the appropriate resistor connected to pin 14 of the chip?

Your syntax for addressing that pin is wrong. Try

void setup()
{

 DDRB |= _BV(0);//set PORTB, bit0 = OUTPUT 
}

void loop()
{
  
  PORTB ^= _BV(0);//this will toggle the pin output
  delay(1000);  // waits for a second

}

will this test port B or C thats the ones that aren't working

ied that now Im getting Arduino: 1.6.5 (Windows 8.1), Board: "ATmega328 on a breadboard (8 MHz internal clock)"

avrdude: Warning: cannot query manufacturer for device:

avrdude: Warning: cannot query product for device:

avrdude: error: could not find USB device with vid=0x16c0 pid=0x5dc vendor='www.fischl.de' product='USBasp'

Error while burning bootloader.

The code I gave will test PORTB with an led connected to physical pin 14 on the chip. What pin do you want to set up to test PORTC? The code should be the same with PORTC substituted for PORTB and the bit value set for the physical pin you want to set as an output and toggle.

PC0 = 23
PC1 = 24
PC2 = 25
PC3 = 26
PC4 = 27
PC5 = 28

bandmwhitt2013:
ied that now Im getting Arduino: 1.6.5 (Windows 8.1), Board: “ATmega328 on a breadboard (8 MHz internal clock)”
avrdude: Warning: cannot query manufacturer for device:
avrdude: Warning: cannot query product for device:
avrdude: error: could not find USB device with vid=0x16c0 pid=0x5dc vendor=‘www.fischl.de’ product=‘USBasp’
Error while burning bootloader.

STOP !