AnsweredAssumed Answered

Help with ADuC845 SPI

Question asked by jwanja on Apr 19, 2012
Latest reply on Apr 20, 2012 by sd3198922

Is there any way to test if this SPI code is even working? I have watched my global "count" variable, but it doesn't increase at all, where I think it should finish the program at 2.  I have tried watching the signals (P2.0 and P2.1) in the debugger, but that has even proved useless. I think it must be a simple mistake I am not catching, but am not sure what is the issue is. Could someone please help me?!?

 

#include <ADuC845.h>
#include <math.h>


int count = 0;


void spiInterrupt(void) interrupt 7
{
          count ++;
          ISPI = 0;  
}


main ()
{
       //Configure SPI - Enable SPI interface, master mode, SCLK idles low, transfer data on the 1-0 transition, 9600 baud rate
          SPE = 1;
          SPIM = 1;
          CPOL = 0;
          CPHA = 1;
          SPR1 = 1;
          SPR0 = 1;
  
       //Enable Global Interrupts
          EA = 1;
  
       //Clear SPI Interrupt bit if it was set before
          ISPI = 0; 
       //Load up SPIDAT to begin transfer
          SPIDAT = 0x4B;
       //Busy wait until byte is transferred 
          while (!ISPI) {} // I BELIEVE AN INTERRUPT SHOULD OCCUR AFTER THIS BUT DOES NOT
  
       //Repeat with some other data
          ISPI = 0;
          SPIDAT = 0xD3;
          while (!ISPI) {}
  
          while(1)
          {
  
          }
}

Outcomes