ATtiny85 communication with other MC - Help with deciding

Hi Everyone,

I've been working on making a counter with an ATtiny85: ATtiny85 Counter/Timer0 - How to make it count up and move Millis() to Timer1 - Microcontrollers - Arduino Forum which I ultimately want to have a parent device read the value.

I've been looking into I2C slave, and 1-wire slave, but since I'm using Timer0 with an external signal, it seems to conflict with the USI clock pin which is used in these serial communication protocols. Is there a simple work around? Bit banging(not so simple)?

Is there another way to capture frequency with an ATTiny85? Interrupt based?(I'm somewhat moving away from that method, but may try it. (Interrupts firing during a communication transaction?)

I may move to an ATtiny84 which seems to not have a pin conflict with T0 and USI clock.

Thanks for the feedback.

Can you use software serials comms?

Is it possible to use Timer 1 for your own code and free up Timer 0 for the comms?

...R

Robin2:
Can you use software serials comms?

Is it possible to use Timer 1 for your own code and free up Timer 0 for the comms?

…R

It looks like Timer1 cannot use an external signal to “clock” it. Only Timer0 has that capability. But I’m no expert.

I've had a quick look at the other thread. You don't seem to have described what you are trying to achieve. Maybe there is another way to do it.

...R

Robin2:
I've had a quick look at the other thread. You don't seem to have described what you are trying to achieve. Maybe there is another way to do it.

...R

I'm looking to make a frequency counter. Need fairly good accuracy from about 20hz-400hz +-1% or better.
Another thread I made here that has no responses: ATtiny85 Counter/Timer0 Input for Frequency Capture - Microcontrollers - Arduino Forum

Thanks!

It would cost £1 or £2 more but it would be so much easier to implement your project with a breadboard Atmega 328 which has an inbuilt USART.

...R

For communication you could use TinyDebugSerial, it is part of the core you are using.
It works the same way as on the UNO and the syntax is the same:
So this would output Serial on pin PB3

void setup() {
Serial.begin(9600);
}

void loop() {
Serial.println("Testing..");
}

https://code.google.com/p/arduino-tiny/

BTW I once made a simple freqence counter with an ATtiny85, using PCINT
I don’t rember the upper freqence limit

volatile unsigned long Count;
long previousMillis = 0; 
long interval = 1000;

ISR(PCINT0_vect) {
  Count++; 
}

void setup()
{ 
  Serial.begin(9600);
  Serial.println("Freq......");
  GIMSK = _BV(PCIE);    // Enable pin change interrupt Table 9.3.2
  PCMSK = _BV(PCINT4);  // Enable the interrupt for only pin 4,Table 9.3.4
}

void loop ()   {
unsigned long currentMillis = millis();
  if(currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;   
    Serial.println("Count  ");
    Serial.println(Count);
    Count=0;
  }
} //loop

Robin2:
It would cost £1 or £2 more but it would be so much easier to implement your project with a breadboard Atmega 328 which has an inbuilt USART.

...R

Agreed, but I don't need all the extra pins and I want something small...even for prototyping. I'm only trying to accomplish a specific task with one chip.

Erni:
BTW I once made a simple freqence counter with an ATtiny85, using PCINT
I don't rember the upper freqence limit

volatile unsigned long Count;

long previousMillis = 0;
long interval = 1000;

ISR(PCINT0_vect) {
  Count++;
}

void setup()
{
  Serial.begin(9600);
  Serial.println("Freq......");
  GIMSK = _BV(PCIE);    // Enable pin change interrupt Table 9.3.2
  PCMSK = _BV(PCINT4);  // Enable the interrupt for only pin 4,Table 9.3.4
}

void loop ()  {
unsigned long currentMillis = millis();
  if(currentMillis - previousMillis > interval) {
    previousMillis = currentMillis; 
    Serial.println("Count  ");
    Serial.println(Count);
    Count=0;
  }
} //loop

Erni, Thanks for the quick example. I think that's one of the methods I mentioned in another thread, but good to see the actual code.

I don't think I'll be able to use serial easily as I need to communicate with another MCU. Also, the usbTinyISP doesn't make a com port to debug with. I'd need a different programmer/hardware to make that work.

I'd need to try out that code and try to figure out how to get the I2c slave code working.

I don't think I'll be able to use serial easily as I need to communicate with another MCU.

I don't understand what yoym mean. Serial communication between MCU's are quite normal.
I have a ATtiny85 communicating with my Raspberry Pi via serial

Erni:
I don't understand what yoym mean. Serial communication between MCU's are quite normal.
I have a ATtiny85 communicating with my Raspberry Pi via serial

Sorry, let me clarify, generally speaking, I would like to communicate via some form of serial communication with the Attiny to another device. I would prefer I2C if possible for minimal wires and already have a few I2C devices already on a bus. In my case, my parent/master device is a netduino.

gismo:
Agreed, but I don't need all the extra pins and I want something small...even for prototyping. I'm only trying to accomplish a specific task with one chip.

You seem to be prepared to invest an awful lot of time to avoid having a few unused pins. I suspect you have already used up a lot more than £2 worth of your own time.

...R

Robin2:
You seem to be prepared to invest an awful lot of time to avoid having a few unused pins. I suspect you have already used up a lot more than £2 worth of your own time.

...R

Ha. Yes. That's true. I'm using it as a learning experience and ultimately would like to make my own pcb and package it neatly and small. It's certainly a balancing act. Also, minimizing power consumption and other things too.