Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

SPI Part 2

2008-09-07 by englsprogeny

Can I program my AVR via SPI and use the SPI port on the AVR
immediately afterword?  It seems all should be OK [because when the
programming is done the SS and reset lines are allowed to go high]  It
seems from that point on, that the AVR should be able to run its SPI
software.  Could the SPI interface [going to my PC] be holding signals
after a download?  I've even tried disconnecting the SPI interface
[coming from the PC] and resetting the processor.  Still, I see no
signal on the clock or MOSI lines.

Here is the code I'm using:



include <avr\io.h>

#include <avr\delay.h>

#define DD_MOSI     PINB3
#define DD_SCK     PINB5
#define DDR_SPI    PORTB

char tx_buff[20] = {10,20,30,40,50,60,70,80,90};


void SendBuffer(void)
{

	//char count = 0;
	
	
	for(char index = 0; index<15; index++)
	{
	
		SPI_MasterTransmit(tx_buff[index]);
	
	}

}

void SPI_MasterInit(void)
{
	
	PORTC = 0x20;
	
	// Set MOSI and SCK output, all others input
	DDR_SPI = (1<<DD_MOSI)|(1<<DD_SCK);
	// Enable SPI, Master, set clock rate fck/16
	SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
}
void SPI_MasterTransmit(char cData)
{
	
	
	/* Start transmission */
	SPDR = cData;
	/* Wait for transmission complete */
	//PORTC |= 0x10;
	while(!(SPSR & (1<<SPIF)));
	//_delay_ms(5);	
	//PORTC = 0x00;
}
int main(void) 
{	

	
	_delay_ms(10);	
	
	//set port c as all output
	DDRC = 0xff;


	
	SPI_MasterInit();
	_delay_ms(10);	
	
	PORTC |= 0x10;
	//SPI_MasterTransmit('A');
	SendBuffer();
	
	
	PORTC = 0x00;
	
	   while(1) { }
}

Thanks for any inputs.

David

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.