Is there anyway to use PB6 and PB7 on an ATmega328 as digital pins? They don't seem to be defined as digital pins anywhere. I'm of course running off the internal oscillator.
Because they are ordinarily oscillator pins they are not defined for use as digital I/O pins in the arduino IDE. At the risk of being burnt down in flames you could try hacking the 'pins_arduino.h' file to add them to the 'digital_pin_to_port_PGM' & 'digital_pin_to_bit_mask_PGM' but I'm not sure this would work as I don't know where else to alter to be able to address these pins. Maybe a separate pinMODE, digitalREAD & digitalWRITE routine in the sketch to address these pins.
I've already tried to mess around in pins_arduino.c without success although I'm sure that it is the right way to go about this (I didn't even really know what to change). I'm able to use the pins directly without releasing any magic smoke by typing something along the lines of
DDRB = 192;
PORTB = 192;
but seeing as I'm trying to implement software serial on the pins, I need an actual pin number to work with.
For stand-alone (chip not on Arduino board), forget the Arduino pin numbers and get the ATMEL pin numbers. The 328 pins are identical to the 168 pins:
Here is complete (567 pages) pdf datasheet on the 328's and family ATMega chips:
Grab a copy, it's worth having. Then head for the Microcontrollers section of the forum.
Not sure what these "ATMEL pin numbers" of which you speak are. If you meant typing something like PB5 rather than 13 when trying to talk to a pin, I'm afraid that the arduino compiler doesn't like it. Also, giving me a 500 page datasheet without giving a clue as to what I should look for in it isn't helping much.
Alright, I figured it out. A bit more messing around in pins_arduino.c and I can now use 14 and 15 as PB6 and PB7. Now I have to do the same thing in arduino 1.0.1, which has no pins_arduino.c as far as I can tell.
EDIT: Nevermind, I found pins_arduino.h in 1.0.1
bobthebanana:
Alright, I figured it out. A bit more messing around in pins_arduino.c and I can now use 14 and 15 as PB6 and PB7.
Glad you have it sorted. Does it effect/upset the analogue pin numbers?
The 328 pins are identical to the 168 pins --- this is a chart of the pins with definitions:
Hope you can see that now.
The datasheet is pure info that you may use any time. That link makes it easy to find, hope you got your copy.
Does it effect/upset the analogue pin numbers?
Yes, it does indeed shift the analogue pins numbers up by two. I just redefined the A0-A5 to be two higher. However, if your sketches use 14-19 instead of A0-A5 (like most of mine), then you have to change them all to be two higher.
Greetings,
I did a similar thing in hardware (Using the internal oscillator and expecting to use the two ports (PB6 and PB7) as digital outputs.
This is a full PCB design, and using the Arduino 1.0.1 IDE for programming.
Does anyone have a revised pins_arduino.h (for 1.0.1)?? Or, can lead me through making the edits myself?
Thanks In Advance!
Peter
Hi everyones,
I'm using the 1.0.5 version of arduino rad.
I've created a atmega_noxtal directory under the hardware/arduino/variants one, and copied the pins_arduino.h from the standard directory into it. I've made all the changes and cleanning (of non atmega8 code) in the file.
The A0 was then shifted by two but strangely:
- when I used A0 in the analogRead function it was the A2 pin (PC2 instead of PC0).
- when I used 0 (the integer zero) in the analogRead function it was the A0 pin (the good one).
So I decided to look at the code in the hardware/arduino/cores/arduino directory, and what I've found is that whatever you change in pins_arduino.h you can't change that because the offset of the A0 pin in the analogRead function is hard coded. So if you want to have A0 associated with PC0 you must change the wiring_analog.c file.
The original code of analogRead begin like this :
int analogRead(uint8_t pin)
{
uint8_t low, high;
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
if (pin >= 54) pin -= 54; // allow for channel or pin numbers
...etc...
...etc...
#else
if (pin >= 14) pin -= 14; // allow for channel or pin numbers
#endif
Because I'm only interested in Atmega8 code I've just changed the line :
if (pin >= 14) pin -= 14; // allow for channel or pin numbers
by :
if (pin >= A0) pin -= A0; // allow for channel or pin numbers
And bingo, it works!
I don't know if others functions are coded like this one, but if you have a problem don't hesitate to dig into the core code !