-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Description
I'm attempting to use 16bit SPI frames. When I use the single frame write method (virtual int write(int value);), everything works as expected. But when I attempt to use the multi-frame read-write method (virtual int write(const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length);) each byte in the buffer I pass is sent as a 16bit SPI frame.
As an example in the image below, when I attempt to send the same 16bit value 0x8003 first using the single frame method, and then using the multi-frame method, the results are different.
The cause is that in spi_master_block_write the tx buffer is split into bytes which are passed to spi_master_write one by one. spi_master_write then sends them as 16bit frames.
It's easily fixed, but I'm wondering if this is the intended behavior? Would a PR be welcome?
Tested on NUCLEO_F767ZI, but after a quick look this behavior seems to exist in at least multiple targets.
Steps to reproduce:
#include "mbed.h"
mbed::SPI _mbed_spi(PB_5, PB_4, PB_3);
mbed::DigitalOut cs(PA_4, 1);
int main() {
_mbed_spi.format(16, 3);
_mbed_spi.frequency(1e6);
uint16_t frame = 0x8003;
while (true) {
Thread::wait(500);
cs = 0;
_mbed_spi.write(frame);
_mbed_spi.write((char *)&frame, 2, nullptr, 0);
cs = 1;
}
}
Issue request type
[ ] Question
[ ] Enhancement
[X] Bug
