5 years, 7 months ago.

The data word length of the SPI format is not changed in NUCLEO-F446RE

Hi,

Referring to the official document, it is possible to specify the data word length from 4 to 16 bits in format function. /media/uploads/StMaaO/ws000928.jpg https://os.mbed.com/docs/latest/reference/spi.html

However, according to the sample code, we set the data word length (10 bits) and measured with an oscilloscope, it was the default setting of 8 bits.

Even if I tried several different data word lengths for testing, it was still 8 bits. However, since "Polarity" and "Phase" settings are correctly reflected by "mode" in format, I think that coding is not wrong ...

Has anyone experienced a similar problem? Thank you.

My Code

#include "mbed.h"

//Control Field(10bit):0b00_1000_0001


//SPI name(MOSI,MISO,SCLK)
SPI enc(D11,D12,D13);

//debug
//Serial pc(USBTX, USBRX);

int main()
{
    //Clock:2.5Mbps
    enc.frequency(2500000);
    enc.format(10,2);
    //loop//
    while(1) {

        //Send CF
        enc.write(0b0010000001);
        //wait_us(0.5);

    }//end:while
}//end:main+

1 Answer

5 years, 7 months ago.

Hello Mao-san,

Some time ago I faced the same problem. Then a realised that because MBED supports a lot of boards (MCUs) with various SPI frame bit length capabilities they designed a common function to cover all of them. However, if the requested transfer bit length is not supported by the given MCU then it does not take effect. For example, the LPC1768 suports 8 to 16 bits per transfer (10 bits included) but the NUCLEO-F446RE supports only either 8 bits or 16 bits frame length.

Accepted Answer

Dear Zoltan Hudak,

Thank you so much for your lucid instructions. I confirmed the data sheet of NUCLEO-F446RE and it was certainly written as "8bit" or "16bit". When checking the data sheet of the device in hand, NUCLE-F302R8 seems to correspond to "4 bit- to-16 bit", so I will try it. Thank you very much.

posted by Mao St 24 Sep 2018

Hi,

You're right that on F3 (but also on F7 and L4 series) the range 4bits to 16bits is available.

But today in mbed only 8bits or 16bits are supported on STM32 devices.

There is no plan to support additional number of bits for the moment.

Thanks!

posted by bco stm 24 Sep 2018

Dear bco stm,

Thank you so much for letting me know. I just tried it with NUCLEO-F302R8 but I was in trouble because it did not become 10 bits.

When I tried with CubeMX, I was able to change the setting to 10 bits (check the waveform with the oscilloscope), so can I set it for CubeMX? Or,if it is LPC1768, is it possible to set it to 10 bits with "mbed online compiler" ?

Please let me know your opinion if you like. Thank you.

posted by Mao St 27 Sep 2018