Description
Describe the bug
SPI transfer16() produces two 8 byte transfers rather than one 16 bit transfer.
To Reproduce
Here is a code that is used for testing SPI transfers. In this instance, the CS pin tells an ADC to convert its input to digital, then 730 nanoseconds later the data is ready for a 16 bit SPI transfer.
With an SPI clock of 50kHz, this should be able to run at close to 1MSPS.
for (int n = 0; n < NKNTS; n++ ) {
// For the ADC
DIGITALWRITE(CSPin,HIGH);
DELAYNANOSECONDS(ADC_WAIT_NANOSECONDS);
DIGITALWRITE(CSPin,LOW);
// For the oscilloscope
DIGITALWRITE(SPAREPIN,HIGH);
// 16 bit transfer
data[n] = SPI.transfer16(0xFFFF);
// For the oscilloscope
DIGITALWRITE(SPAREPIN,LOW);
}
`
And here is the oscilloscope trace. Notice that rather than one 16 bit transfer, we have two 8 bit transfers. And note that they are separated by 400 nsecs, but there is 1200 nsecs before and after.
Here is the implementation, for transfer16() it calls spi_transfer( .... length )
Arduino_Core_STM32/libraries/SPI/src/SPI.cpp
Lines 179 to 195 in 89a2951
And, in utility/spi.c, we find that spi_transfer() simply loops over LL_SPI_TransmitData8( ).
Arduino_Core_STM32/libraries/SPI/src/utility/spi_com.c
Lines 482 to 550 in 89a2951
You already have a LL_SPI_TransmitData16( ), under hardware/stm32/2.8.1/system/Drivers/
What is missing in this implementation is a spi_transfer16() and to change transfer16() to call it.
Thank you