CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

How to Readout SPI

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
richi-d



Joined: 28 Aug 2007
Posts: 106

View user's profile Send private message

How to Readout SPI
PostPosted: Wed Mar 05, 2008 7:00 am     Reply with quote

Hi all,

my problem is that the SPI BUS is hanging in the write_spi() Command...after enable the SSP interrupt

I first send the command to the other part that I want to read out, and then I send some dummy data to force a clock output...

Whats wrong?

Compiler 4.038
Code:



#INT_SSP
void SPI_int()
   {
   SPI_IN = spi_read ();
   SPI_GELESEN = 1;
   }
   
....


void main()
   {
   SETUP_OSCILLATOR( OSC_32MHZ );

   SET_TRIS_C(0x10);
   
   *0xFC6 = 0x21;   //SPI Clock/4
   *0xFC7 = 0x40;   //SPI ein


   ENABLE_INTERRUPTS(GLOBAL);

.....




void Schreibe_SPI (KOMMANDO,DATEN)
   {
   output_low(CS);
   NOP;
   SPI_WRITE(KOMMANDO);
   NOP;
   SPI_WRITE(DATEN);
   NOP;
   output_high(CS);
   }

void Lese_SPI (KOMMANDO, i)
   {
   output_low(CS);
   NOP;
   SPI_WRITE(KOMMANDO);
   ENABLE_INTERRUPTS(INT_SSP);
   for (x=0; x<=i; ++x)
      {
      SPI_WRITE(0xAA);      //DUMMY - here the programm is hanging!!!!
      }
   output_high(CS);
   while (SPI_GELESEN == 0)
      {
      NOP;
      }
   SPI_GELESEN = 1;
   DISABLE_INTERRUPTS(INT_SSP);
   }


......



   Lese_SPI (0x0D,1);
   IO_CONFIG = SPI_IN;
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 05, 2008 12:40 pm     Reply with quote

Are you trying to create an SPI slave ?

Look at these two CCS example files:
Quote:

c:\Program Files\picc\Examples\Ex_spi_slave.c
c:\Program Files\picc\Examples\Ex_spi.c


This thread has code that demonstrates an SPI slave
but it's done using one board (just because it's a demonstration).
http://www.ccsinfo.com/forum/viewtopic.php?t=26888
richi-d



Joined: 28 Aug 2007
Posts: 106

View user's profile Send private message

PostPosted: Wed Mar 05, 2008 4:01 pm     Reply with quote

Hi PCM-

no I want to create a master:

I send a command to read out a register in the slave part. The master must create the clock for the slave... am I wrong?
I had a look to the examples- they are not very helpful because I cantĀ“find the include file: 9356spi.c ???
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 05, 2008 4:03 pm     Reply with quote

What's the manufacturer and part number of the SPI slave chip ?
Ttelmah
Guest







PostPosted: Wed Mar 05, 2008 4:50 pm     Reply with quote

There is very little point, in using the SPI interrupt, in a master device. This interrupt occurs, whenever a byte is clocked in. On a master, this occurs whenvever a byte is clocked. So each time you are writing the 0xAA 'out', you will immediately get an interrupt, to say a byte has been received. You might as well simply read the byte clocked immediately in the main code, after writing the 0xAA out. SPI_GELESEN, can never equal zero after this bit of code (since you have generated clocks, bytes will have been received...).
You _always_ receive the byte back, when you send a byte, even if it is garbage. It is up to the designers, to build the protocol, so that you know which byte in the sequence, is significant. Normally, you send initialisation bytes, and simply throw away the returns,and only after you have completed the initialisation, start reading returned data.

Best Wishes
richi-d



Joined: 28 Aug 2007
Posts: 106

View user's profile Send private message

PostPosted: Thu Mar 13, 2008 1:05 am     Reply with quote

I found it out for myself:

in_data = spi_read(0);


Thats what I needed to know...
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group