busLab posted on 2017-12-21 08:42:24

SPI adapter host computer underlying function code



This program is used to read and write test 25AA020A memory, the test code is as follows:
[*]#include <stdio.h>
[*]#include <Windows.h>
[*]// Define a function pointer to the underlying function of the SPI adapter
[*]typedef int (* SPI_Funtion) (char * in, char * out);
[*]// define command for memory operation
[*]#define CMD_READ_DATA 0X03
[*]#define CMD_PAGE_PROGRAM 0X02
[*]#define CMD_WRITE_ENABLE 0X06
[*]// data store
[*]unsigned char inString ;
[*]unsigned char outString ;
[*]// main function
[*]int main (void)
[*]{
[*]      // Load DLL
[*]      HINSTANCE hDLL; // DLL handle
[*]      hDLL = LoadLibrary ("VT_SPI_Driver.dll");
[*]      // Get SPI initialization function pointer address
[*]      SPI_Funtion SPI_Init = (SPI_Funtion) GetProcAddress (hDLL, "VTIF_SPI_Init");
[*]      // Get SPI write data function pointer address
[*]      SPI_Funtion SPI_WriteData = (SPI_Funtion) GetProcAddress (hDLL, "VTIF_SPI_WriteData");
[*]      // Get SPI read data function pointer address
[*]      SPI_Funtion SPI_ReadData = (SPI_Funtion) GetProcAddress (hDLL, "VTIF_SPI_ReadData");
[*]      // Get SPI write data function pointer address
[*]      SPI_Funtion SPI_WriteReadData = (SPI_Funtion) GetProcAddress (hDLL, "VTIF_SPI_WriteReadData");
[*]      // Get SPI device selection function pointer address
[*]      SPI_Funtion SPI_SelectDevice = (SPI_Funtion) GetProcAddress (hDLL, "VTIF_SPI_SelectDevice");
[*]      // Select SPI adapter
[*]      printf ("Select SPI Adapter \ n");
[*]      SPI_SelectDevice ("0", (char *) outString); // Select the SPI adapter
[*]      printf ("% s \ n \ n", outString);
[*]      // Initialize the SPI adapter
[*]      // Data Format: "Control Mode | Clock Polarity | Clock Phase | Master-Slave Mode | Data Width | Shift Direction | Chip Select Polarity | Clock Frequency"
[*]      printf ("initialize SPI adapter \ n");
[*]      SPI_Init ("1 | 0 | 0 | 1 | 8 | 0 | 0 | 1000000", (char *) outString); // Initialize the SPI adapter
[*]      printf ("% s \ n \ n", outString);
[*]
[*]      // Control SPI adapter write data 0x06 (enable SPI memory write command)
[*]      printf ("Control SPI adapter write data 0x06 (enable SPI memory write command) \ n");
[*]      SPI_WriteData ("0x06", (char *) outString);
[*]      printf ("% s \ n \ n", outString);
[*]      Sleep (1);
[*]
[*]      // Control the SPI adapter to write data (write data to SPI memory, the first two bytes are memory control commands)
[*]      printf ("controls the SPI adapter to write data (writes data to SPI memory with the first two bytes being memory control commands) \ n");
[*]      SPI_WriteData ("0x02 | 0x00 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29", (char *) outString);
[*]      printf ("% s \ n \ n", outString);
[*]      Sleep (1);
[*]
[*]      // Control the SPI adapter to read 10 bytes of data from the SPI memory (first two bytes for memory control commands)
[*]      printf ("controls the SPI adapter to read 10 bytes of data (the first two bytes are memory control commands) from SPI memory \ n");
[*]      SPI_WriteReadData ("0x03 | 0x00 | 0x0A", (char *) outString);
[*]      printf ("% s \ n \ n", outString);
[*]      Sleep (1);
[*]
[*]      FreeLibrary (hDLL);
[*]      system ("pause");
[*]      return 0;
[*]}

Copy the code






Adapter , PC

This topic is moved by admin on 2017-7-3 14:46
http://www.viewtool.com/bbs/static/image/common/fav.gifFavorite 0http://www.viewtool.com/bbs/xwb/images/bgimg/icon_logo.pngForward to microblogging
Related Posts
[*]• ViewTool (Wisp) I2C Adapter / USB to I2C
[*]• ViewTool WIP Ginkgo SPI Adapter / Controller / adapter USB to SPI
[*]• Ginkgo I2C Adapter Brief
[*]• Read and write control of 25AA020A memory chips using SPI adapters
[*]• Ginkgo Adapter Firmware Upgrade Tutorial
[*]• Read and write control AT45DBXX memory chip with SPI adapter
[*]• Debug the STM32 CAN program using the Ginkgo 2 USB to CAN adapter
[*]• GVIgo adapter-based CVI application source code download
[*]• Quickly use the Ginkgo CAN adapter tutorial
[*]• Ginkgo USB-SPI Adapter Slave Mode Usage Considerations


      

cherry posted on 2017-12-22 10:05:55


Have not learned the serial port, think C + + are dizzy

cherry posted on 2017-12-22 10:06:39


There is no jar written in jar?
Page: [1]
View full: SPI adapter host computer underlying function code