|
|
View previous topic :: View next topic |
Author |
Message |
mpfj
Joined: 09 Sep 2003 Posts: 95 Location: UK
|
Using spi_write() with SSP interrupts in Master mode |
Posted: Thu Jan 26, 2006 4:19 am |
|
|
I am using SPI Master mode on an 18F8722.
My code uses an interrupt routine to handle the *outgoing* transfers. To initiate the transfer, I use the code ...
Code: | /* Routine to send / receive io poll message */
void io_poll(void) {
int8 i;
// create transmit data in poll message
io.buffer[REG_DIGOUT] = digio.digouts;
io.buffer[REG_CARD_BITS] = cardreader.num_bits;
// set # bytes to transfer
io.buff_count = REG_MAX - 1;
// init buffer index
io.buff_index = 0;
// send first byte (REG_VERSION)
spi_write(0x00);
// now just wait for the int_ssp irq ...
} |
Howevert, looking at the listing file, the spi_write() command generates the following code ...
Code: | .................... // send first byte (REG_VERSION)
.................... spi_write(0x00);
0A476: MOVF FC9,W
0A478: CLRF FC9
0A47A: BTFSS FC7.0
0A47C: BRA A47A
|
As you can see, the SSP1BUF is read (to clear any pending received data), then the SSP1BUF is written with 0x00 (as required).
*But* then the code sits in a tight loop waiting for the BF (buffer full) bit to be set in the SSP1STAT register.
I don't want this tight loop to happen, since the hardware will generate an interrupt when the byte transfer is complete.
I know I can write my own code to do this, but why can't the compiler acknowledge the fact that I'm using the SSP interrupt, and hence only do the "write" portion of the code ? |
|
|
Ttelmah Guest
|
|
Posted: Thu Jan 26, 2006 4:45 am |
|
|
Realistically, the easy answer is just to write your own functions. The I2C/SPI function in CCS, are not that well implemented for many uses (as you say, the SPI functions do not suit interrupt applications), and if they try to make the functions 'smarter', so they recognise the 'mode' you are working in, it'd be more likely to lead to problems. An 'optional' second variable, that allows wait to be enabled/disabled, would be the ideal solution. I'd suggest you ask them for this!. However in the meantime DIY is 'trivial'. I used:
Code: |
#byte SSPBUF = 0xFC9
#byte SSPCON = 0xFC6
#byte SSPSTAT = 0xFC7
#bit SSP_DATA_IN = SSPSTAT.0
#DEFINE READ_SSP() (SSPBUF)
#DEFINE WAIT_FOR_SSP() while((SSP_DATA_IN)==0)
#DEFINE WRITE_SSP(x) SSPBUF=(x)
#DEFINE CLEAR_WCOL() SSPCON=SSPCON & 0x3F
|
These give byte read/wite, and code to wait for the data to arrive, or be sent, as required.
Best Wishes |
|
|
|
|
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
|