How to send 4 bit data from NI8452?

Hello,
I want to send (0xAFF adress + 48bits data) sequence over SPI using NI8452 from Matlab. The write function of SPI object sends unit8 data, which converts above data into (0x0AFF + 48bit data), which changes the functionality of the next connected device.
I looked for the CS pin accessibility from code, so that CS can be enabled after 4 CLK cycles. But, I dont find any control over CS pin in Matlab.
Please let me know how I can code to send (0xAFF adress + 48bits data) sequence.

Réponses (1)

Walter Roberson
Walter Roberson le 18 Jan 2026

0 votes

https://www.mathworks.com/help/matlab/supportpkg/analog-input-using-spi.html implies that you pad out to byte multiples if the device uses something that is not a multiple of 8 bits.

2 commentaires

Pratik
Pratik le 19 Jan 2026
Modifié(e) : Walter Roberson le 19 Jan 2026
Thank you Walter for quick reply.
I have gone throught the links. But, the device which I am connecting with strickly works on the (0xAFF address + 48bits data) data frame. I tried to club the data in 0xabc format. But, the data sent is supporting unit8 format, which value maximize to FF. Please check the trailing code which I have used,
Final_Seq = '00500294a5294a5';
Seq_1 = reshape(Final_Seq,[3,length(Final_Seq)/3])';
Seq_2 = strcat('0x',Seq_1);
hex_seq = str2num(Seq_2)
hex_seq = 5×1
5 2 2378 1321 1189
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
dataToWrite = uint8(hex_seq)
dataToWrite = 5×1
5 2 255 255 255
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
data_read = writeAndRead(Obj,dataToWrite);
Unrecognized function or variable 'Obj'.
Please check and let me know if any solution is possible.
Thank you.
You should be considering using
typecast(hex_seq, 'uint8')
However, the result will be 10 bytes, which is not going to fit the 64 bit buffer.
I do not understand the connection between "0xAFF address + 48bits data" and what you are constructing ?

Connectez-vous pour commenter.

Catégories

Tags

Question posée :

le 17 Jan 2026

Commenté :

le 19 Jan 2026

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by