View previous topic :: View next topic |
Author |
Message |
gokulrred
Joined: 22 Nov 2011 Posts: 32 Location: puducherry
|
purpose of spi_data_in(); and SSP ISR |
Posted: Fri Jan 13, 2012 6:49 pm |
|
|
SSP ISR can be used when SPI data is sent to slave from master.
during that time interrupt will be generated and SSP ISR is called and we can read SPI data using spi_read(); in SSP ISR.
i have no doubt in this.
spi_data_in();
Function:
Returns TRUE if data has been received over the SPI.
Example:
if( spi_data_is_in() )
data = spi_read();
here.........................
Can we write the above in main and use instead of SSP ISR????//
For example:
I am using SSP ISR for reading.
Instead can i use the above in main itself and so that whenever data comes will it automatically read at any time? |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Fri Jan 13, 2012 7:17 pm |
|
|
The purpose of an ISR, any ISR, is to 'flag' or inform the 'main' program that 'something' important has occoured, stop whatever you're doing, take appropriate action to that 'flag', then carry on in 'main' doing whatever you were doing before the interrupt happened.
The ISR is a fast,efficient way to program.
Without ISRs, you have to 'poll' or check to see if 'something ' has occoured.This requires a very tight loop or you could miss the 'something' from happening.
It's usually not a problem for say one or two switches, but having to poll say 8 switches, the serial port,check the LCD,etc. takes a LOT of time and you WILL miss something.
There was a great comparison to checking for mail in the mailbox a few days ago, it's well worth reading ! |
|
![](templates/subSilver/images/spacer.gif) |
gokulrred
Joined: 22 Nov 2011 Posts: 32 Location: puducherry
|
|
Posted: Fri Jan 13, 2012 7:45 pm |
|
|
thank you for ur active and rapid answer...
so spi_data_in will not interrupt but we can read data throu that....
right????? |
|
![](templates/subSilver/images/spacer.gif) |
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Sat Jan 14, 2012 4:17 am |
|
|
The PIC hardware peripherals like SPI often do several things. One is they set a flag and two they with post a register and three if given permission to interrupt they will jump to your ISR. The spI data is in is testing the flag that the hardware set when it posted the register with the new data. Without an interrupt the main code must retrieve the value from the hardware register before it is overwritten with new data or that it overflows. This means the main code must have a short loop that varies with the processor speed. |
|
![](templates/subSilver/images/spacer.gif) |
|