Go Down

Topic: Barebones 328 ( 8MHz) access PB6 PB7 (Read 1 time) previous topic - next topic

Glenn81

Hi,
I'm working on a project with a bare 8MHz MEGA328 (no crystal) and I really want to use PB6 & PB7 as digital outputs.
I've tried modifying a core pins_arduino.h file, but I'm not really sure what I'm doing and, especially, don't know what numbers the two ports will have if all this works.
( My modified file is correctly accessed - I see it called in the compile traces )
I've attached my file, if anyone can help.
Thanks, in advance,
Glenn


pito

You must change the fuse setting as well.

CrossRoads

Need to change these 2 arrays as well
Code: [Select]

const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
PD, /* 0 */
PD,
PD,
PD,
PD,
PD,
PD,
PD,
PB, /* 8 */
PB,
PB,
PB,
PB,
PB,
PB,      << move to end - otherwise they are D14, D15
PB,      << move to end
PC, /* 16 */
PC,
PC,
PC,
PC,
PC,
};

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(6),      << move to end
_BV(7),      << move to end
_BV(0), /* 16, port C */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
};

and add two more NOT_ON_TIMER, to end of this

#endif
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER, /* 16 - port C */
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
};
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

bperrybap

#3
May 23, 2014, 10:53 pm Last Edit: May 23, 2014, 10:55 pm by bperrybap Reason: 1
You could use my avrio package:
http://code.google.com/p/mcu-io/downloads/list
It is licensed GPL v3.
You can then directly access any AVR i/o pin you want by using a PIN_Pb syntax.
i.e.
to set PB6 low you would do:
Code: [Select]
avrio_digitalWrite(PIN_B6, LOW);

It will do raw port i/o which is around 40x faster than the Arduino routines.

There is lots of information about the i/o primitives in the header file.
There is one catch.
All the arguments must be compile time constants.
i.e.
the pin must be a PIN_Pb define
the value must 0, 1, HIGH or LOW.


There is no modifying of any other files.
Just include the avrio.h header and that it is all.
And as Pito said earlier, the fuses must be set to allow the pins
to be used as i/o pins.

--- bill

Glenn81

#4
May 24, 2014, 08:30 am Last Edit: May 24, 2014, 08:58 am by Glenn81 Reason: 1
@all : thanks for the quick replies !

@pito : where's the easiest place to put changed fuse settings, only for my 'breadboard' variant ? (I reply to my own question : this is already done, my barebones is already working on a breadboard with no crystal) : in the sketchbook/hardware/<variant>/boards.txt file.

@CrossRoads : Thanks, that's exactly what I needed - I got lost inside the file.  Works great.  Thankyou.

Thanks again,
Glenn

CrossRoads

Fuses are changed in the boards.txt file.
Make up a new one for your specific board name if needed.
Put it and the pins_arduino.h on
/variants/new_board/ folder

Example:
Code: [Select]

bobuino.name=Bobuino
bobuino.upload.protocol=arduino
bobuino.upload.maximum_size=130048
bobuino.upload.speed=115200
bobuino.bootloader.low_fuses=0xff
bobuino.bootloader.high_fuses=0xde
bobuino.bootloader.extended_fuses=0xfd
bobuino.bootloader.path=Bobuino
bobuino.bootloader.file=AtmegaBOOT_1284P_16MHZ.hex
bobuino.bootloader.unlock_bits=0x3F
bobuino.bootloader.lock_bits=0x0F
bobuino.build.mcu=atmega1284p
bobuino.build.f_cpu=16000000L
#bobuino.build.core=arduino:arduino
bobuino.build.core=standard
bobuino.build.variant=bobuino

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up