cancel
Showing results for 
Search instead for 
Did you mean: 

Changing SPI modes with HAL

Matt G
Associate II

Hi,

I am using a DAC which takes data in 24 bit format, 8 control bits and 16 data.

I currently have two seperate large 8 bit and 16 bit arrays.

I want to change between modes on the fly before each transfer using SPI_DATASIZE_8BIT / 16BIT, but it stays in the first declared mode. I.e I am trying to send 8,16.8,16... alternately as a means of sending 24bit messages with 24 clocks. 

I am working with others unfamiliar to coding so would like to stick with using the HAL unless it is impossible for this. 

Thanks 

2 REPLIES 2

Isn't 2x 24-bit words the same as 3x 16-bit.

Writing three consective 8-bit bytes will generate 24 clocks on the bus.

Manage this as a single buffer in memory and mux the bytes/words in software as you fill the pattern buffer.

Going to be very hard playing games with the peripheral settings as the unit is shifting data onto the wire, and going to be significantly more effort than just building the buffer content.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Matt G
Associate II

Thanks for the reply Clive.

This line was ambiguous - I have rewritten as "I currently have two separate large 8 bit and 16 bit arrays.". So not 3x 16 bit but 3x 8 bit.

If I understand correctly you are saying to keep my first 8 bit control array as it and split the 16 bit data array into two separate 8 bit arrays, then send as A1 B1 C1, A2 B2 C2..?

I considered this but thought it was a bit messy especially since there will be 3 SPI send commands for one complete frame and condition loops. Perhaps it is as clean as the code can be while using HAL though.