![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
henzelince
Joined: 14 May 2007 Posts: 3
|
write more than a byte, by SPI !UERGENT please! |
Posted: Mon May 14, 2007 8:58 am |
|
|
I want to write 24 bits by SPI hardware module.
If I write
spi_write(0b01010101);// i loose time
spi_write(0b10101010);//i loose time
spi_write(0b01010101);
there are some latency time between each spi_write.
If i write
spi_write(0b010101011010101001010101);// that write only a byte.
How can I do for write these 24 bits with any timeout, with the hardware SPI only ?? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Mon May 14, 2007 9:42 am |
|
|
At the end of the day, you can't. However the time loss, should be tiny. Basically, you can only load a 'new' value into the SPI output register, once the last value has been sent. (The transmit register is not 'double buffered' like the receive). Hence you need to check either the SSPIF, or the BF bit, to know that the eight clocks have been sent. Once this is seen, you can load another byte. The total time delay, should be reducable to only about 4 instruction tims, but is unavoidable. You could try coding this yourself, to see if this is more efficient than the CCS code (which probably checks for other things like overrun etc.).
Something like (for a 18 chip):
Code: |
#byte SSPBUF=0xFC9
#byte SSPSTAT=0xFC8
#bit BF=SSPSTAT.0
union access {
int8 b[4];
int32 val;
};
void send_24(union access val_to_send) {
int8 dummy;
if (BF) dummy=SSPBUF; //clear buffer full
SSPBUF=val_to_send.b[0]; //hard code, since faster than a variable.
while (!BF) ;
dummy=SSPBUF;
SSPBUF=val_to_send.b[1];
while (!BF) ;
dummy=SSPBUF;
SSPBUF=val_to_send.b[2];
while (!BF) ;
dummy=SSPBUF;
}
|
Called with a 32bit integer value, this sends the LSB first. You would need to change this to suit the order you want. It 'hardcodes' the byte addresses, since this is much quicker than using a variable based array access. It also waits for the last byte to send, which might be not needed.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
henzelince
Joined: 14 May 2007 Posts: 3
|
|
Posted: Mon May 14, 2007 9:54 am |
|
|
thx !!!
I'll try this solution ! |
|
![](templates/subSilver/images/spacer.gif) |
henzelince
Joined: 14 May 2007 Posts: 3
|
|
Posted: Tue May 15, 2007 12:33 am |
|
|
Ok that works !
For another user:
#byte SSPSTAT=0xFC7 // not 0xFC8 |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Wed May 16, 2007 2:07 am |
|
|
Typical of my sort of fault. As you possibly guessed, I typed this 'untested', straight into the thread. Though I try to scan for obvious errors, things like this 'creep by'.
Glad it worked.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|