[TM4C123] SPI word length

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
ExXec
Posts: 83
Joined: Sat Oct 20, 2018 4:02 pm

[TM4C123] SPI word length

Post by ExXec » Sun May 05, 2019 2:22 pm

Hey,

my controller supports up to 16bit words for SPI, but the transfer functions only accept byte arrays.
Is there a way to send larger words?

Thanks,

-ExXec

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: [TM4C123] SPI word length

Post by jimmo » Mon May 06, 2019 12:08 am

Just to make sure I understand your question, can you give an example of what you'd like this to look like in Python? i.e. it sounds like you want more things like bytearray, i.e. `uint16array` etc?

The way it works currently on ports that allow configuring the SPI transfer width to 16 bits (via the `bits` param to the constructor/init, e.g. on stm32) is that the bytearray you pass it will be interpreted as pairs of bytes making up the 16-bit transfer size.

i.e. this is from the stm32 HAL in the non-DMA path, pData is essentially the contents of the buffer passed to spi.write(), DR is a 16-bit register but whether the top byte is used is configured in CR1.

Code: Select all

          hspi->Instance->DR = *((uint16_t *)pData);
          pData += sizeof(uint16_t);
          hspi->TxXferCount--;
So if you want to transmit 16-bit words from Python, then you just need a way to stash them into a bytearray. (e.g. struct.pack, manually shifting, etc).

ExXec
Posts: 83
Joined: Sat Oct 20, 2018 4:02 pm

Re: [TM4C123] SPI word length

Post by ExXec » Mon May 06, 2019 1:47 pm

I didn't know if bytestitching was the only way to achieve this, maybe there would have been a better solution.
Thanks for your reply!

Post Reply