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

write more than a byte, by SPI !UERGENT please!

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



Joined: 14 May 2007
Posts: 3

View user's profile Send private message

write more than a byte, by SPI !UERGENT please!
PostPosted: Mon May 14, 2007 8:58 am     Reply with quote

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 ??
Ttelmah
Guest







PostPosted: Mon May 14, 2007 9:42 am     Reply with quote

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
henzelince



Joined: 14 May 2007
Posts: 3

View user's profile Send private message

PostPosted: Mon May 14, 2007 9:54 am     Reply with quote

thx !!!

I'll try this solution !
henzelince



Joined: 14 May 2007
Posts: 3

View user's profile Send private message

PostPosted: Tue May 15, 2007 12:33 am     Reply with quote

Ok that works !

For another user:
#byte SSPSTAT=0xFC7 // not 0xFC8
Ttelmah
Guest







PostPosted: Wed May 16, 2007 2:07 am     Reply with quote

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
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