no SPI data out with ATtiny861

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

Hello :-)

I am used to SPI peripherals of ATmega8, AT91USB162, AT91SAM9260, etc, but I can't make working the one on the ATtiny861.

Here is my code, which just put low level voltage on MOSI, I am using a scope. SCK signal is ok, with 8 clocks and also SS is ok.

Thanks in advance.

#include 
#include 

void spi_master_init (void)
{
	/* PB0 -> MOSI; PB2 -> SCK; PA6 -> SS */
	DDRB |= (1<<PB0) | (1<<PB2);
	DDRA |= (1<<PA6);
}

void spi_send_byte (uint8_t byte)
{
	/* Enable Chip Select */
	PORTA &= ~(1<<PA6);

	/* Put byte on the sending buffer */
	USIDR = byte;

	/* Send 8 clock pulses */
	uint8_t counter;
	for (counter = 0; counter < 8; counter++)
	{
		USICR = (1<<USIWM0) | (0<<USICS0) | (1<<USITC);
		USICR = (1<<USIWM0) | (0<<USICS0) | (1<<USITC) | (1<<USICLK);
	}

	/* Disable Chip Select */
	PORTA |= (1<<PA6);

	/* Read and discard received byte */
	counter = USIDR;
}

int main (void)
{
	spi_master_init ();

	while (1)
	{
		spi_send_byte (0xde);
		spi_send_byte (0xad);
		spi_send_byte (0xbe);
		spi_send_byte (0xef);
	}
}

JPCasainho,
www.Casainho.net
.Portugal

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

PB0 is the USI input (DI), PB1 is the USI output (DO). The MOSI and MISO labels are for ISP programming, where the AVR is the slave.

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

mrono wrote:
PB0 is the USI input (DI), PB1 is the USI output (DO). The MOSI and MISO labels are for ISP programming, where the AVR is the slave.

I got confused ;-) -- on there is two pins labeled DO and DI :-(

I made as output both of them and I am just getting clock signal on PB2.

Any more ideas?

JPCasainho,
www.Casainho.net
.Portugal

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

Oh, I got it ;-)

PB1 is the DO (Data Out) pin and not the PB0 as I thought.

The PB0 is the labeled as MOSI/DI and PB1 as MISO/DO. MOSI and MISO is then referenced as lines for programmer and that made me make a mistake...

Thank you.

JPCasainho,
www.Casainho.net
.Portugal