How do I use the clock output on atmega328p?


I'm trying to interface a thermopile sensor with my arduino duemilanove with atmega328p 16Mhz.
The sensor is working with an odd version of SPI and I need to feed it with 1Mhz clock.
I use the arduino-0022 environment.
I defined f_cpu 1000000UL in the software.
I connected the clock pin to the arduino pin no. 8.
I changed the low fuse in the boards.txt to 0x80.
When sniffing the pin with arduinoscope I can see voltage running trough it but so does any other pin I sniff (which wasn't defined by pinMode).

The Atmega328p datasheet say that:

the normal operation of I/O
pin will be overridden when the fuse is programmed

but when I call pinMode(8, OUTPUT), the arduinoscope show me that the voltage in pin8 is 0.
What am I doing wrong?

Hope that there is someone out there that can help a frustrated man...


changing th fuse setting in boards.txt wont do anything until you go to bootload another chip

I burned the program to the chip after the changes if that what you mean. If not, please explain.

You almost certainly don't want to change the fuses - the SPI clock isn't a continuous clock, it sends bursts of 8 pulses only. (Though you did say it was an odd SPI I suppose...)

It's possible to set the SPI clock to 8, 4, 2, 1MHz, 500, 250, 125kHz (Assuming a 16MHz system clock). The fastest SPI rate is half the system clock.

What is the sensor? - someone may well have interfaced to it before on here...

And the fuses are not programmed when a sketch is downloaded, only the application area of flash memory is overwritten. An ISP programmer is needed to change fuses or bootloader area.

This sensor is called HTPA from heimann, I doubt it if anyone tried to interface it but I will be glad to meet him :wink:
The sensor need to be feed with the chip Master clock as well as the SPI clock (two different legs), that is why I need it.
Is there another way to get a 1Mhz clock to this sensor?
About the fuses, I thought that the arduino doesn't need a programmer like the STK does, I just use my AVRKSP II.


Each timer is able to directly manipulate up to two output pins. I suggest you configure Timer 1 or Timer 2 to toggle an output pin at 1 MHz. The datasheet and this should help...

I think you might mean one of this series?

That indeed requires an external 1MHz clock in addition to SPI clock and data. I think the CONT input controls whether the device acts as SPI slave or master and there's only one data pin for both modes - not really SPI! In master mode it clocks at half the master clock so I think its safe to assume it can handle 500kHz SPI clock on SCLK_IO

BTW here's code that should set pin 3 to 1MHz - it uses timer2 and the normal analogWrite function for pins 3 and 11 won't be available if you do this.

Note that the pin and timer assignments are different on the Arduino Mega - this code is for standard Arduino only:

#define PWMout 3

void setup ()
  TCCR2A = 0xB3 ; // fast PWM with programmed TOP val
  TCCR2B = 0x09 ; // divide by 1 prescale
  TCNT2  = 0x00 ;
  OCR2A  = 0x0F ; // TOP = 15, cycles every 16 clocks
  OCR2B  = 0x07 ; // COMP for pin3
  pinMode (PWMout, OUTPUT) ;



I think I'm in love with you :slight_smile:
It worked!
And the sensor gives a signal!
No matter what other bad stuff will happen, tonight I can sleep like a baby (Unless my baby will wake me up).

Thank you all for your help, for now :wink:

Great! If you can't sleep there's always the ATmega328 datasheets to read LOL.

Incidentally are those sensors expensive - I've just seen the thermal image examples on their website for the 32x31 pixel version - a low cost thermal imaging camera would be very very sweet...

They are cheap only if you buy them in stocks (like 1000pcs.).
1 sensor of 8x8 costs several hundred US dollars.