16mhz output from atmega 328 to replace crystal on another chip

Hi guys,

I am using spi communication between the atmega328 and a bluetooth IC. The bluetooth needs its own 16mhz crystal to operate too. But, there is an option in the datasheet to just drive one of the bluetooth chip's crystal pins with a 16mhz signal. Board space is limited on this project and one less crystal would be handy.

I looked at the atmega datasheet and it looks like PB0(clkO) which is digital pin 8 should be the pin to output the system clock. I found this code but do not fully understand direct port manipulation yet:

void setup(void)
{
  DDRB = _BV(DDB1);                  //set OC1A/PB1 as output (Arduino pin D9, DIP pin 15)
  TCCR1A = _BV(COM1A0);              //toggle OC1A on compare match
  OCR1A = 0;                         //top value for counter
  TCCR1B = _BV(WGM12) | _BV(CS10);   //CTC mode, prescaler clock/1
}

void loop(void)
{
}

It outputs a 1MHZ signal to digital pin 9. I changed the OCR1A to 0 and got 8mhz (but I still need double that!). I thought changing DDB1 to DDB0 would output on pin8 but it just stopped it from working.

Any help is appreciated. I read the arduino page on port manipulation, but most of these symbols don't come up there. Maybe someone has a good link to a page on how to use this type of code or can help describe what it does.

Thanks

I saw this the other day, AVR Tutorial - Fuses

It has a section on clock output, the 16Mhz crystal can be attached to the arduino, then its clock output tied to the bluetooth clock input.

cool, thanks. I got it to work.

I ended up editing the boards.txt file and added a board:

....

##############################################################

pro5v328.name=Arduino CUSTOM (3V, 16 MHz) w/ ATmega328

pro5v328.upload.protocol=stk500
pro5v328.upload.maximum_size=30720
pro5v328.upload.speed=57600

pro5v328.bootloader.low_fuses=0xBF
pro5v328.bootloader.high_fuses=0xDA
pro5v328.bootloader.extended_fuses=0x05
pro5v328.bootloader.path=atmega
pro5v328.bootloader.file=ATmegaBOOT_168_atmega328.hex
pro5v328.bootloader.unlock_bits=0x3F
pro5v328.bootloader.lock_bits=0x0F

pro5v328.build.mcu=atmega328p
pro5v328.build.f_cpu=16000000L
pro5v328.build.core=arduino

I then had to reburn the bootloader selecting this new board

The Low fuse byte is what I changed from 0xFF to 0xBF (from 11111111 to 10111111)

The 6th bit is the clock output bit.