Set the I/O Voltage Level for the NI 8452 I2C/SPI Interface?

In LabView there is a way to set the 8452's I/O Voltage Level to values between 3.3 and 1.2V. Is there a way to access this in MATLAB?

1 Commento

I'm looking for the same answer as well, John Hribar did you find a solution for this?
we appreciate if someone could advise ?

Accedi per commentare.

Risposte (2)

Hi Youssif,
I ended up writing a couple of custom scripts to get the job done, using NI's C API. I can send them to you if you'd like.
Sincerely,
John

4 Commenti

Hi John,
I'm also trying to write scripts to access the NI's C API. Can you send me an example of how to access the C functions? They seem to reference the mexNI8452x.mexw64 file which is the compiled code from mathworks.
Thanks!
John
I used the loadlibrary and calllib extensively. If you load the library then call libfunctions MATLAB will spit out all the functions with their expected output. You can then find their equivalent in the NI documentation and from the two figure out how to call them in your program.
Here's how I create a ni845x structure that I can use later to call read and write functions:
function ni845x = openNi845x()
ni845x.ChipSelect = 0;
ni845x.ClockRate = 10;
if not(libisloaded('ni845x_lib'))
loadlibrary('C:\Windows\System32\ni845x.dll','C:\Program Files (x86)\National Instruments\NI-845x\MS Visual C\ni845x.h','alias','ni845x_lib')
end
[error, ni845x.FindDeviceHandle, ni845x.FirstDevice, ni845x.NumberFound] = calllib('ni845x_lib','ni845xFindDevice',blanks(260), 100, 100);
% libfunctions('ni845x','-full')
if error ~= 0
disp('Error')
end
[error, ni845x.DeviceName, ni845x.DeviceHandle] = calllib('ni845x_lib','ni845xOpen', ni845x.FindDeviceHandle, 100);
if error ~= 0
disp('Error')
end
calllib('ni845x_lib','ni845xSetIoVoltageLevel', ni845x.DeviceHandle, 18);
[error, ni845x.SPIHandle] = calllib('ni845x_lib','ni845xSpiConfigurationOpen', 100);
if error ~= 0
disp('Error')
end
calllib('ni845x_lib','ni845xSpiConfigurationSetChipSelect', ni845x.SPIHandle, ni845x.ChipSelect);
calllib('ni845x_lib','ni845xSpiConfigurationSetClockRate', ni845x.SPIHandle, ni845x.ClockRate);
calllib('ni845x_lib','ni845xSpiConfigurationSetClockPolarity', ni845x.SPIHandle, 0);
calllib('ni845x_lib','ni845xSpiConfigurationSetClockPhase', ni845x.SPIHandle, 0);
end
I hope this helps. Pleas reach out again if you have any more questions.
Hi John,
Thank you very much. I'll give this a try and let you know if I have any issues. This saves me a lot of time!
Thanks again,
John
Thanks John, for this wonderfully helpful resource. After a few frustrating days of fiddling with it, thought I'd add a few notes for future people who come upon this page.
In my 64 bit Windows system, the above loadlibrary command fails. I resolved this by editing the ni845x.h file in the above to add the following lines:
#include <stdio.h> // Include file for printf
#include <stdlib.h> // Include file for strtol
#include <conio.h> // Include file for _getch
#include <string.h>
#include <windows.h> // Include file for Win32 time functions
These were taken from one of NI's example scripts. It's possible not all of them are necessary, but it works. On top of that, there seems to be some issue where Matlab compiles the code for a 32 bit system when really my system is 64 bit. As a result, there is a datatype error with the DeviceHandle, relating to 32 bit vs 64 bit unsigned integers. To resolve this, I added to the ni845x.h file the following:
#define WIN64
I admittedly don't fully understand the nuances of it, but this resolves my issues and allows John's above code to work.

Accedi per commentare.

Starting in MATLAB R2023a, this is possible by using the new ni845x interface, which has a VoltageLevel property

Categorie

Scopri di più su MATLAB in Centro assistenza e File Exchange

Prodotti

Release

R2016b

Tag

Richiesto:

il 22 Mag 2019

Risposto:

il 12 Set 2023

Community Treasure Hunt

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

Start Hunting!

Translated by