// lora.cpp : Defines the entry point for the console application.
//
#include <stdlib.h>
#include "stdafx.h"
#include <afx.h>
#include "lora.h"
#include "usbspi.h"
#include <string>
#include <string.h>
#include "usbio.h"
#include "SPI_RW.h"
#include "stdafx.h"
#include "lora.h"
#include "usbspi.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
//////////////////////////////////////////////////////////////////////////////////////
bool SPI_READ(LPVOID lpComBuffer,BYTE byComSize, LPVOID lpBuffer, WORD wBuffSize)
/*
lpComBuffer, //用来保存在读SPI数据之前要写入的命令
byComSize, //要写入的命令长度,如果不需要写入,设为0
lpBuffer, //写入数据缓存
wBuffSize //请求写入数据长度
*/
{
return USBIO_SPIRead(0,lpComBuffer,byComSize,lpBuffer,wBuffSize);
}
bool SPI_WRITE(LPVOID lpComBuffer,BYTE byComSize,LPVOID lpBuffer,WORD wBuffSize)
//BYTE是自定义的类型
//WORD是微软SDK中的类型,WORD的意思为字,是2byte的无符号整数
//LPVOID是一个没有类型的指针,也就是说你可以将任意类型的指针赋值给LPVOID类型的变量
{
return USBIO_SPIWrite(0,lpComBuffer,byComSize,lpBuffer,wBuffSize);
}
typedef unsigned char uint8_t;
///////////////////////////////////////////////////////////////////////////////////////////
void SX1276ReadBuffer( uint8_t addr, uint8_t *buffer, uint8_t size )
{
LPVOID lpComBuffer = &addr;
LPVOID lpBuffer = (LPVOID)buffer;
SPI_READ(lpComBuffer,2 , lpBuffer, 16);
}
void SX1276WriteBuffer( uint8_t addr, uint8_t *buffer, uint8_t size )
{
LPVOID lpComBuffer = &addr;
LPVOID lpBuffer = buffer;
SPI_WRITE(lpComBuffer,1,lpBuffer,16);
}
////////////////////////////////////////////////////////////////////////////////////////////////
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
USBSPI spi;
spi.USBSPI_INIT();
spi.USBSPI_OPEN();
spi.USBSPI_SET();
///////////////////////////////////////////////////////////////////////////////////
//写
uint8_t addr = 0x82;
uint8_t size = 1;
uint8_t write_buffer = 0x1B;
uint8_t *buffer = &write_buffer;
SX1276WriteBuffer( addr, buffer, size );
printf("写入的结果是:%02x\r\n", *buffer);
//读
uint8_t addr1 = 0x02;
uint8_t size1 = 1;
uint8_t *buffer1 = new BYTE[16];
printf("读之前的结果是:%02x\r\n", (*buffer1));
SX1276ReadBuffer( addr1, buffer1, size1 );
printf("读出的结果是:%02x\r\n", (*buffer1));
delete []buffer1;
/*
char Temp[1] = {0x02};
BYTE comLen = 1;
DWORD dwReadLen = 16;
BYTE* pTmpBuff = new BYTE[dwReadLen];
SPI_READ(Temp,comLen,pTmpBuff,dwReadLen);
printf("读出的结果是:%02x\r\n", (*pTmpBuff));
delete []pTmpBuff;
*/
return 0;
}
|