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.

Answers (1)

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.

4 Comments

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 ?
Pratik
Pratik on 11 Mar 2026 at 7:42
Moved: Walter Roberson on 11 Mar 2026 at 18:39
Thank you Walter for the reply.
I am driving an BF-IC having SPI control. The data to be sent for commanding is (2bit preamble + 10bit address + 48bit word). Hence, the requirment is to generate such bit stream.
Please let me know any solution to generate such bit stream using NI-8452.
Thank you.
data64 = uint64(Preamble) * 2^62 + uint64(Address)*2^52 + uint64(Word);
data8 = typecast(data64, 'uint8');
Now transmit data8. The individual parts of it are each 8 bit integers and so will have no problem with the SPI.

Sign in to comment.

Categories

Tags

Asked:

on 17 Jan 2026

Commented:

on 11 Mar 2026 at 18:47

Community Treasure Hunt

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

Start Hunting!