LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

NI-8452 How to read the Identification Register of Micron M25P80

I have an M25P80 connected with decoupling, pullup/down resistors connected to the NI8452

 

Using either a script VI or C code, how to simply read the ID register of this e2prom?  

 

The device is first selected by driving S# LOW. Then the 8-bit command code is shifted
in and content is shifted out on DQ1 as follows: the 24-bit device identification that is
stored in the memory, the 8-bit CFD length, followed by 16 bytes of CFD content. Each
bit is shifted out during the falling edge of serial clock (C)

 

Single byte command 0x9F or 0x9E

 

issue this command and about 20 bytes of read data clock out.   Something like this?

 

 

WriteSize = 1;
SendData[0] = 0x9f;
/* issue start condition */
errChk(ni845xSpiScriptCSLow(ScriptHandle, ChipSelect));
/* write the 0x9F command */
errChk(ni845xSpiScriptWriteRead(ScriptHandle, WriteSize, SendData,
&ScriptReadIndex));
/* issue stop condition */
errChk(ni845xSpiScriptCSHigh(ScriptHandle, ChipSelect));
/* issue start condition */
errChk(ni845xSpiScriptCSLow(ScriptHandle, ChipSelect));
/* write data array */
errChk(ni845xSpiScriptWriteRead(ScriptHandle, WriteSize, WriteData,
&ScriptReadIndex));
/* issue stop condition */
errChk(ni845xSpiScriptCSHigh(ScriptHandle, ChipSelect));
//errChk(ni845xDioWritePort(DeviceHandle, 0, 0));
/* disable script logging */
errChk(ni845xSpiScriptDisableSPI(ScriptHandle));
/* run the script */
errChk(ni845xSpiScriptRun(ScriptHandle, DeviceHandle, PortNumber));
/* extract the read data size */
errChk(ni845xSpiScriptExtractReadDataSize(ScriptHandle, ScriptReadIndex,
&ReadSize));
/* extract the read data */
errChk(ni845xSpiScriptExtractReadData(ScriptHandle, ScriptReadIndex,
ReadData));

/* if frames were received, display them */
if (ReadSize >= 1)
{
for (i = 3; i < ReadSize; i++)
{
/* convert returned data into string*/
sprintf_s(CharBuff, sizeof(CharBuff), "%3X", ReadData[i]);
printf("%s\n", CharBuff);
}
}
/* close the script and device handles */
errChk(ni845xSpiScriptClose(ScriptHandle));
errChk(ni845xClose(DeviceHandle));

 

 

 

 

 

 

0 Kudos
Message 1 of 5
(317 Views)

You shouldn't be toggling the CS between command and data read as per the device's timing diagram.

santo_13_0-1724553714637.png

 

Please try this logic,

  1. Set CS to Low
  2. SPI Write Read size 1 : 0x9E or 0x9F 
  3. SPI Write Read size 4 : Write array of four 0x00 and read the 4 bytes
  4. Use the 4th byte (CFD length) value to read the next N bytes of CFD content
    santo_13_1-1724553901338.png
  5. Set CS to High

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
Message 2 of 5
(288 Views)

Thanks for your help.  Modified a little and

 

RESULT

FF

FF

CC

CC

CC

CC

CC

CC

CC                                                                                                                                                                                                                                                                                                                                                                                                                     

 

 

 


#include <stdio.h> // Include file for printf
#include <stdlib.h> // Include file for strtol
#include <string.h>
#include <windows.h> // Include file for Win32 time functions
#include "ni845x.h" // Include file for NI-485x functions and constants

/* the NI 845x handles */
NiHandle DeviceHandle;
NiHandle ScriptHandle;

/* error Function for NI 845x */
#ifndef errChk
#define errChk(fCall) if (Error = (fCall), Error < 0) {goto Error;} else
#endif

int main()
{
int Error = 0;
char FirstDevice[260]; // 260 characters for 845x resource name
uInt8 PortNumber = 0;
uInt32 ChipSelect = 0; // chip select pin (0)
uInt16 ClockRate = 50; // clock rate in KHz
uInt32 NumberToRead = 32; // number of data bytes to read (32)
uInt16 StartingOffset = 0; // start address (0)
uInt8 LowAddressByte = 0;
uInt8 HighAddressByte = 0;
uInt32 WriteSize = 0;
uInt8 WriteData[35]; // write array for bytes to write
uInt32 ReadSize = 0;

uInt8 ReadData[35]; // read array for bytes to read
uInt32 ScriptReadIndex = 0;
uInt8 SendData[512];
uInt32 i;
char CharBuff[10];
char ErrorMsg[1024];

printf("\n\nSearching for Devices\n\n");

/* find first device */
errChk(ni845xFindDevice(FirstDevice, NULL, NULL));

/* open device handle */
errChk(ni845xOpen(FirstDevice, &DeviceHandle));

/* Set the I/O Voltage Level */
errChk(ni845xSetIoVoltageLevel(DeviceHandle, kNi845x33Volts));

 

 


///* create the data array to send */
//LowAddressByte = StartingOffset & 0xFF;
//HighAddressByte = StartingOffset >> 8;

//WriteSize = NumberToRead + 3;
//WriteData[0] = 3; // READ instruction (0x3)
//WriteData[1] = HighAddressByte; // first address byte
//WriteData[2] = LowAddressByte; // second address byte

//for (i = 3; i < (WriteSize); i++)
//{
// WriteData[i] = (uInt8)(i - 3);
//}

/* create script */
errChk(ni845xSpiScriptOpen(&ScriptHandle));

/* enable script logging */
errChk(ni845xSpiScriptEnableSPI(ScriptHandle));

/* configure Polarity and Phase */
errChk(ni845xSpiScriptClockPolarityPhase(ScriptHandle,
kNi845xSpiClockPolarityIdleLow, kNi845xSpiClockPhaseFirstEdge));

/* configure clock rate */
errChk(ni845xSpiScriptClockRate(ScriptHandle, ClockRate));

printf("%s", FirstDevice);
printf(" initialized successfully\n\nData received:\n\n");


WriteSize = 1;
SendData[0] = 0x9e; // the WREN Instruction (0x6)
/* issue start condition */
errChk(ni845xSpiScriptCSLow(ScriptHandle, ChipSelect));
/* write WREN instruction array */
errChk(ni845xSpiScriptWriteRead(ScriptHandle, WriteSize, SendData,
&ScriptReadIndex));
/* issue stop condition */
// errChk(ni845xSpiScriptCSHigh(ScriptHandle, ChipSelect));


///* create the data array to send */
LowAddressByte = StartingOffset & 0xFF;
HighAddressByte = StartingOffset >> 8;

WriteSize = 4; //NumberToRead + 3;
WriteData[0] = 0; // READ instruction (0x3)
WriteData[1] = 0; // HighAddressByte; // first address byte
WriteData[2] = 0; //LowAddressByte; // second address byte
WriteData[3] = 0;
/*for (i = 3; i < (WriteSize); i++)
{
WriteData[i] = (uInt8)(i - 3);
}*/
errChk(ni845xSpiScriptWriteRead(ScriptHandle, WriteSize, WriteData,
&ScriptReadIndex));

/* issue start condition */
// errChk(ni845xSpiScriptCSLow(ScriptHandle, ChipSelect));

/* write data array */
/* errChk(ni845xSpiScriptWriteRead(ScriptHandle, WriteSize, WriteData,
&ScriptReadIndex));*/

/* issue stop condition */
errChk(ni845xSpiScriptCSHigh(ScriptHandle, ChipSelect));

/* disable script logging */
errChk(ni845xSpiScriptDisableSPI(ScriptHandle));

/* run the script */
errChk(ni845xSpiScriptRun(ScriptHandle, DeviceHandle, PortNumber));

/* extract the read data size */
errChk(ni845xSpiScriptExtractReadDataSize( ScriptHandle, ScriptReadIndex,
&ReadSize));

/* extract the read data */
errChk(ni845xSpiScriptExtractReadData(ScriptHandle, ScriptReadIndex,
ReadData));

/* if frames were received, display them FORCE READ SIZE*/
if (1 == 1)
{
for (i = 0; i < 10; i++) //3
{
/* convert returned data into string */
sprintf_s(CharBuff, sizeof(CharBuff), "%3X", ReadData[i]);
printf("%s\n", CharBuff);
}
}

/* close the script and device handles */
errChk(ni845xSpiScriptClose(ScriptHandle));
errChk(ni845xClose(DeviceHandle));

Error:
if (Error < 0)
{
ni845xStatusToString(Error, 1024, ErrorMsg);
printf("\nError %d %s \n", Error, ErrorMsg);
ni845xSpiScriptClose(ScriptHandle);
ni845xClose(DeviceHandle);
exit(1);
}

return 0;
}

0 Kudos
Message 3 of 5
(254 Views)

and it is not the right data. FF FF CC CC CC CC

0 Kudos
Message 4 of 5
(219 Views)

I connected another NI8452  USB to DIO/spi 

 

now the data is something like:

20

42

20

16

CC

CC

CC

CC

 

it was the NI hardware.  This NI8452 is a poorly made, poorly designed unit that goes into some glitch mode and never reports any problem.  This is a hobbyist grade piece of hardware, not for serious applications.

 

I started using National Instruments software/systems in 1997.  they were always good quality and good support.  until now

0 Kudos
Message 5 of 5
(189 Views)