View previous topic :: View next topic |
Author |
Message |
pebbert9
Joined: 31 Dec 2010 Posts: 39
|
spi_xfer sends one byte at a time |
Posted: Sun Jul 26, 2020 12:06 pm |
|
|
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: 9226 Location: Greensville,Ontario
|
|
Posted: Sun Jul 26, 2020 12:48 pm |
|
|
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
|
Re: spi_xfer sends one byte at a time |
Posted: Sun Jul 26, 2020 1:13 pm |
|
|
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: 19515
|
|
Posted: Mon Jul 27, 2020 12:27 am |
|
|
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: 9226 Location: Greensville,Ontario
|
|
Posted: Mon Jul 27, 2020 4:48 am |
|
|
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. |
|
|
|