Attiny 44a is draining battery when enabling SPI

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi everyone.

 

I've run into a peculiar problem, I was wondering if anyone else has had a similar issue.  I have a design using an Attiny44a that uses both I2C and SPI.  The circuit's normal operation bit bangs I2C using PA4 and PA5 as SCL and SDA.  These lines are pulled up through 4.7k resistors.  Those same ports are also used when some diagnostic code is run to communicate over SPI.  For this I am using the USI driver referenced in an ATMEL app Note.  Until yesterday everything seem to work fine, I had been running the code on a board powered by a bench top supply.  When I finally attached a battery it was drained rather quickly.  I've determined that once the setup_spi() function is called, the battery starts to get drained:

void setup_spi(void)
{
	//set DI and USCK pins to input
	USI_DIR_REG &= ~(1 << SPI_MOSI);
	USI_DIR_REG &= ~(1 << SPI_CLK);


	//Set DO pin to output
	USI_DIR_REG |= (1 << SPI_MISO);
	//enable pullups on inputs
	//PORTA |= (1 << PORTA4) | (1 << PORTA6);
	 
	 
	//set USI Controll Register: overflow interrupt, 3 wire mode, external clock 
	//positive edge
	USICR = (1<<USIOIE) | (1<<USIWM0) | (1<<USICS1);
	
	// Init driver status register.
	spiX_status.masterMode       = 0;
	spiX_status.transferComplete = 0;
	spiX_status.writeCollision   = 0;
	
	storedUSIDR = 0;
	
}

Any ideas on what might be happening here?  I am using a cr2032 battery to power the circuit.  

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Valueduser wrote:
Those same ports are also used when some diagnostic code is run to communicate over SPI.

Show a schematic.

 

I'm not a USI person -- does the above indicate you are a USI slave?

 

In any case, which pin is SPI_MISO?  One of the pulled up pins?  Then obviously when you make it a low output

 

Valueduser wrote:
//Set DO pin to output USI_DIR_REG |= (1 << SPI_MISO);

...you will be fighting the external resistor.

 

Make it a high output?  Dunno with USI.

 

Control that pullup resistor with a MOSFET, and only activate it during I2C?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.