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 CCS Technical Support

spi_xfer sends one byte at a time

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



Joined: 31 Dec 2010
Posts: 39

View user's profile Send private message

spi_xfer sends one byte at a time
PostPosted: Sun Jul 26, 2020 12:06 pm     Reply with quote

When I try to send 24 bits using spi_xfer I get three 8 bit transfers with a 1us delay between them instead of just 24 bits in a row. Is there any way to eliminate this or would a different command send the 24 bits as a continuous stream?

Code:
spi_xfer(ADC_SPI, reg, 24);


gives this result

https://imgur.com/a/ysrPoTP
temtronic



Joined: 01 Jul 2010
Posts: 9240
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jul 26, 2020 12:48 pm     Reply with quote

My understanding is that 'SPI' was and is an 8 bit (1 byte) peripheral. As such the internal hardware for MSSP (SPI/I2C) of a PIC will be a byte wide...
If you need 24 bits 'in a row' you'll need to code your own 'driver' or 'function' and probably use 'bit bang' for timing. I do this for a custom 22 bit @ 24 baud serial interface. It's been reliable for 2 decades so I'm fairly confident it's working.

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: spi_xfer sends one byte at a time
PostPosted: Sun Jul 26, 2020 1:13 pm     Reply with quote

pebbert9 wrote:

I get three 8 bit transfers with a 1us delay between them instead.

Why is that a problem for your application ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Mon Jul 27, 2020 12:27 am     Reply with quote

At the end of the day, this is what the hardware can do.....

The SPI hardware supports 8bit transfers (actually PIC24's and up do offer
16bit transfers), but not 24bit transfers. So any 24bit transfer has got to
involve multiple 8bit transfers.
SPI is synchronous (this is what the 'S' stands for), so the pauses should
not matter. If for some reason you have hardware that requires unbroken
clock sequences, then you would have to write this in software at a much
lower speed than SPI supports.
temtronic



Joined: 01 Jul 2010
Posts: 9240
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jul 27, 2020 4:48 am     Reply with quote

Please post the SPI device you're using.That way we can have a look at the datasheet and see is required. Also which PIC are you using ?
Creating your own 'driver' is not that hard, you just need to think like a PIC and code one line at a time.
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