code to read device ID of MachXo2 with FTDI -JTAG - ftdi

In my project I am working on MachX02 programming with FTDI master using JTAG functionality. I am trying to read device ID of MachX02, but not working, here is my sample code to read device ID of MachX02:
cmd_buffer[0] = 0xE0;
cmd_buffer[1] = (byte)((operand & 0xFF0000) >> 16);
cmd_buffer[2] = (byte)((operand & 0x00FF00) >> 8);
cmd_buffer[3] = (byte)(operand & 0x0000FF);
JTAG_WriteRead(fthandle, false, 32, cmd_buffer, 4, m_readbuffer, ref operand, RUN_TEST_IDLE_STATE);
Where I went wrong could not able to identify, for MachX02 before sending device ID opcode, do I need to send any another opcode? Please help to overcome this problem, thanks in advance.

Related

Issue sending/receiving data over serial connection using MATLAB

I recently connected a reactor control tower through a serial 'COMMS' port to my computer (serial to USB). It seems to create a connection on the COM4 port (as indicated on the control panel 'devices and printers' section). However, it always gives me the following message when i try to 'fwrite(s)' or 'fscanf(s)'.
Warning: Unsuccessful read: The specified amount of data was not returned within the Timeout period..
%My COM4
s = serial('COM4');
s.BaudRate = 9600;
s.DataBits = 8;
s.Parity ='none';
s.StopBits = 1;
s.FlowControl='none';
s.Terminator = ';';
s.ByteOrder = 'LittleEndian';
s.ReadAsyncMode = 'manual';
% Building write message.
devID = '02'; % device ID
cmd = 'S'; % command read or write; S for write
readM = cell(961,3);% Read at most 961-by-3 values filling a 961–by–3 matrix in column order
strF = num2str(i);
strF = '11'; %pH parameter
strP = '15'; %pH set point
val = '006.8'; %pH set value
msg_ = strcat('!', devID, cmd, strF, strP, val);%output the string
chksum = dec2hex(mod(sum(msg_),256)); %conversion to hexdec
msg = strcat(msg_,':', char(chksum), ';');
fopen(s); %connects s to the device using fopen , writes and reads text data
fwrite(s, uint8(msg)); %writes the binary data/ Convert to 8-bit unsigned integer (unit8) to the instrument connected to s.
reply=fscanf(s); %reads ASCII data from the device connected to the serial port object and returns it to reply, for binary data use fread
fclose(s); %Disconnect s from the scope, and remove s from memory and the workspace.
This leads me to believe that the device is connected but is not sending or receiving information and I am unsure as to how I can configure this or even really check if there is communication occurring between the tower and my computer.

AES GCM mechanism parameters in C

I am having problem setting the parameters for the AES GCM mechanism.
I am receving the following error
#define CKR_MECHANISM_PARAM_INVALID 0x00000071UL
What am I doing wrong?
CK_BYTE iv[12] = { 0 };
CK_MECHANISM mechanismAES = { CKM_AES_GCM, NULL_PTR, 0 };
CK_GCM_PARAMS params = {
.pIv=iv,
.ulIvLen=12,
.ulIvBits=96,
.pAAD=NULL,
.ulAADLen=0,
.ulTagBits=0
};
mechanismAES.pParameter = &params;
mechanismAES.ulParameterLen = sizeof(params);
C_EncryptInit(hSession, &mechanismAES, hKey);
.ulTagBits=0 is very likely the issue. The tag size is the size of the authentication tag. You would not have an authenticated mode of encryption if you left it out.
Valid tag sizes of GCM are 128, 120, 112, 104 or 96 bits. Smaller tag sizes such as 64 bits may be acceptable by some API's. You are however strongly encouraged to keep to the 128 bit tag size, as the security of GCM strongly depends on it.
You may also want to specify either the IV len or the IV bits if the error doesn't go away.

Lost, trying to connect Intel Edison SPI to ADC using the intel XDC and node

I am using the intel XDK for the first time and I am trying to get a reading from this SPI ADC ADS7951SRGER 12 Bit Analog to Digital Converter 8 Input 1 SAR 24-VQFN (4x4) http://www.ti.com/lit/ds/symlink/ads7950.pdf
its connected like so
SPI_2_RXD -> MISO
SPI_2_TXD -> MOSI
SPI_2_CLK -> SCLK
SPI_2_FS0 -> ADC_CS
I have never used SPI before, I am very lost. I've been searching for 24 hours now and I'm not much closer to understanding what I'm supposed to do here.
here is the current hail mary code I'm trying. all I get back is ffffffff
var x = new m.Spi(0);
x.bitPerWord=12;
x.frequency = 20;
var buf = new Buffer(4);
buf[0] = char('0x0b');
buf[1] = char('0x11');
buf[2] = char('0x11');
buf[3] = char('0x11');
var buf2 = x.write(buf);
console.log("Sent: " + buf.toString('hex') + ". Received: " + buf2.toString('hex'));
Any help is appreciated
In the end, I had to pull the CS (SPI_2_FS0 -> ADC_CS) manually, pulling low before each write/read then high again.

How to write a 16bit data to I2c protocol

I am making a program in which I am interfacing INA226 with atmega8 using I2C. I need to write its register with value 4127h . Following is the code I have done. when I am reading the register, I am getting 41 FF. That means I am able to write 41 but not 27. How can I do this.?
Also when I try to change the value like from 4127h to 3637h (just to check), it doesnt get change and display the older value 41 Ff.
Please help, thanks.
CODE
i2c_init();
i2c_start();
i2c_write(0b10000000); //slave address
i2c_write(0x00); //register address
i2c_write(0x41); // data
i2c_write(0x27); // data
i2c_stop();
i2c_start();
i2c_write(0b10000001);
temp1 = i2c_read(1);
temp2 = i2c_read(0);
i2c_stop();
enter code here
unsigned int_16 DATA=4127
i2c_init();
i2c_start();
i2c_write(0b10000000); //slave address
i2c_write(0x00); //register address
i2c_write((int)DATA>>8); // data OF MSB
i2c_write((int)DATA & 0XFF); // data OF LSB
i2c_stop();

VB6 RS232 not receiving full data from device using MSCOMM Controll

I have a clinical device that sends data on com port, I want to receive data from device
it also received First Frame (254) character after send ACK on ENQ
it receive [ETB] [CR][LF] characters
then I again send ACK for next frame, but not receive data
only receiving EOT char
Device Communication as per device is:
<-[ENQ]
->[ACK]
<-[STX]1H|**********************-[ETB]21[CR][LF]
->[ACK]
<-[STX]1H|**********************-[ETX]8E[CR][LF]
->[ACK]
<-[EOT]
my code is:
'MSComm1.Settings = "9600,n,8,1"
'MSComm1.InputLen = 1
Private Sub MSComm1_OnComm()
Dim InBuff As String
InBuff = MSComm1.Input
if Chr$(5)=InBuff then 'ENQ received
MSComm1.Output=Chr$(6) & VbCr
elseif Chr$(10)=InBuff then 'LF received
MSComm1.Output=Chr$(6) & VbCr
else
text1.text=text1.text & InBuff
end if
End Sub
Device sending full data because 1 software comes with device which receive full data as
but I didn't receive next frame after send ACK again,
if any one have idea what output have to send FOR next ACK, please advice me
thanks in advance
Do something like this...
MSComm1.InputLen = 1 ' for sending single character from device
MSComm1.RThreshold = 1 ' for firing events on receiving a single character
Dim InBuff As String
if MSComm1.CommEvent = comEvReceive then
do
InBuff = MSComm1.Input
Loop Until MSComm1.InBufferCount < 1
Firstly receive all the data and after that use that in your own way.