[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] SPI problem

From: Jack Valmadre
Subject: [avr-gcc-list] SPI problem
Date: Thu, 19 Aug 2004 09:52:59 +1000

I am trying to make my AT90S8535 communicate with a V2Xe compass module via
an SPI interface.
I have an LED attached to pin 5 on port D, but the LED does not light up, so
the program doesn't seem to make it past the second transmit.
This must be because SPIF is not rising, which it should be doing at the end
of a transmission.  So I'm guessing the transmission is not being completed.
I've tried putting a small delay between each transmission but that did not
change anything.
How can this be fixed?
I've pasted my program below.

#include <avr/io.h>

#define SS  4
#define MOSI 5
#define MISO 6
#define SCK  7

int main(void) {

 unsigned char i;

 //set in/out
 DDRA = 0x00;
 DDRB = (1<<MOSI)|(1<<SCK)|(1<<SS);
 DDRC = (1<<PC7);
 DDRD = (1<<PD5);

 //pull-ups on all inputs, 0 on all outputs

 SPCR = (1<<SPE)|(1<<MSTR);  //enable SPI, master mode, ck/4

 DDRB &= ~(1<<SS);  //clear SS bit

 SPDR = 0xAA; //sync byte
 while(!(SPSR & (1<<SPIF)));

 SPDR = 0x01; //getmodinfo
 while(!(SPSR & (1<<SPIF)));
 PORTD |= (1<<PD5);

 SPDR = 0x00; //terminator byte
 while(!(SPSR & (1<<SPIF)));

 for(i=0; i<11; i++) {  //clock 11 bytes out of module
  SPDR = 0x00;
  while(!(SPSR & (1<<SPIF)));

 DDRB |= (1<<SS);  //set SS bit



reply via email to

[Prev in Thread] Current Thread [Next in Thread]