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

Question about #INT_SSP

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



Joined: 31 May 2007
Posts: 11

View user's profile Send private message

Question about #INT_SSP
PostPosted: Wed May 27, 2009 2:07 pm     Reply with quote

Hi:

I have to interface a device with a PC. Said device outputs it's data thru a Sync Serial Port, requiring to be provided with a clock signal. I'm using a PIC18 to provide the interface, reading data from the device via SPI and sending it to the PC via UART.

The data reading process starts with a pushbutton, which is read thru the INT_RB interrupt. Currently, I'm using the TIMER1 interrupt to force reading of the device.

This is the code I'm using:
Code:

#include <18F252.h>
#fuses HS,NOPROTECT,NOWDT,PUT
#use delay(clock=20000000)
#use rs232(baud=2400, parity=N, bits=8, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#use standard_io(A)
#use standard_io(B)
#use standard_io(C)

/////////////
// DEFINES //
/////////////

#define SPI_MODE_0 (SPI_L_TO_H|SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L|SPI_XMIT_L_TO_H)
#define PRESET 63869

/////////////
// GLOBALS //
/////////////

#byte PORTB = 0x0F81
int1 flag = 0;
int data, changes, last_b;

//////////////////////
// PORT_B INTERRUPT //
//////////////////////

#INT_RB
void portb_isr()
{
   changes = last_b ^ PORTB;
   last_b = PORTB;

   //////////////////////////////////////
   /////////////// PIN_B7 ///////////////
   //////////////////////////////////////

   //Detect falling edge on PIN_B7
   if (bit_test(changes,7)&& !bit_test(last_b,7))
   {
      flag = 1;
   }

   //Detect rising edge on PIN_B7
   if (bit_test(changes,7)&& bit_test(last_b,7))
   {
      flag = 0;
   }
}

////////////////////
// TMR1 INTERRUPT //
////////////////////

#INT_TIMER1
void timer1_isr()
{
   if(flag)
   {
      data = spi_read(0xAA);
      putc(data);
   }

   set_timer1(PRESET);
}

//////////////////
// MAIN ROUTINE //
//////////////////

void main(void)
{

   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
   set_timer1(PRESET);

   setup_timer_2(T2_DIV_BY_16, 129, 1);
   setup_spi(SPI_MASTER|SPI_MODE_1|SPI_CLK_T2);

   enable_interrupts(GLOBAL);
   enable_interrupts(INT_RB);
   enable_interrupts(INT_TIMER1);
   
   while(1)
   {   
   }
}

So far it works alright, but I'd like to know if there's a way to use the #INT_SSP interrupt in a similar way to the #INT_RDA interrupt. I've used the UART quite a bit, but the SPI is something of a mystery to me. Also, I think that using a timer interrupt for this uses more resources than if I was reading SPI activity directly.

BTW, the code I tried for #INT_SSP was this:
Code:


#INT_SSP
void spi_isr()
{
   if(flag&&spi_data_is_in())
   {      
      data = spi_read(0xAA);
      putc(data);
   }
}


I haven't had much luck with #INT_SSP, so if anyone can give me a pointer on how to implement it, I'd really appreciate it.

Best regards, and thank you in advance!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 27, 2009 3:12 pm     Reply with quote

Why do you need #int_ssp for an SPI Master ? The master generates
the clock (SCLK). The master controls when the slave device sends
its data to the master.

Quote:
data = spi_read(0xAA);

When you do this, you are clocking out 0xAA to the slave device and
you're also clocking in a byte (to the master) from the slave. The byte
from the slave will be placed in 'data'.
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