当前位置: 首页>>代码示例>>C++>>正文


C++ SPI函数代码示例

本文整理汇总了C++中SPI函数的典型用法代码示例。如果您正苦于以下问题:C++ SPI函数的具体用法?C++ SPI怎么用?C++ SPI使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SPI函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: wait_initV2

int wait_initV2()
{
    int i=20000;
    int r;
    spi_spin();
    while(--i)
    {
        if((r=cmd_CMD55())==1)
        {
//			printf("CMD55 %d\n",r);
            SPI(0xff);
            if((r=cmd_CMD41())==0)
            {
//				printf("CMD41 %d\n",r);
                SPI(0xff);
                return(1);
            }
//			else
//				printf("CMD41 %d\n",r);
            spi_spin();
        }
//		else
//			printf("CMD55 %d\n",r);
    }
    return(0);
}
开发者ID:robinsonb5,项目名称:ZPUTest,代码行数:26,代码来源:spi.c

示例2: rda1846RX

void rda1846RX(unsigned char useSq)
{
  SPI(0x1F, 0);
  if (useSq)
    SPI(0x30, 0x302E); //2E RX
  else
    SPI(0x30, 0x3026); //2E RX
}
开发者ID:madberry,项目名称:UV3RMod,代码行数:8,代码来源:rda.c

示例3: init

// The init procedure is executed once when the REXLANG function block initializes.
long init(void)
{
    spi_bus_handle = OpenSPI(spi_dev); // open SPI device
    
		// SPI data modes:
		//	SPI_MODE0 = 0,  // CPOL = 0, CPHA = 0, Clock idle low, data is clocked in on rising edge, output data (change) on falling edge
		//	SPI_MODE1 = 1,  // CPOL = 0, CPHA = 1, Clock idle low, data is clocked in on falling edge, output data (change) on rising edge
		//	SPI_MODE2 = 2,  // CPOL = 1, CPHA = 0, Clock idle high, data is clocked in on falling edge, output data (change) on rising edge
		//	SPI_MODE3 = 3,  // CPOL = 1, CPHA = 1, Clock idle high, data is clocked in on rising, edge output data (change) on falling edge

    spi_bufTx[0] = 0; //SPI data mode (0-3 mode, | 4=CS_HIGH | 8=LSB_FIRST | 16=3WIRE | 32=LOOP | 64=NO_CS | 128=READY)
		spi_bufTx[1] = 8; //bits per word
		spi_bufTx[2] = 1000000; //clock frequency [Hz]
		SetOptions(spi_bus_handle, spi_bufTx);

    // Verification of SPI bus settings
		GetOptions(spi_bus_handle, spi_bufRx);
		Trace(0, spi_bufRx[0]);  //	SPI mode
		Trace(1, spi_bufRx[1]);  //	bits per word
		Trace(2, spi_bufRx[2]);  //	clock frequency
	
    // Addressing the device
    spi_opcode_write = 0x40; // ( 0 | 1 | 0 | 0 | A2 | A1 | A0 | R/W ), write=0
    spi_opcode_read  = 0x41; // ( 0 | 1 | 0 | 0 | A2 | A1 | A0 | R/W ), read=1

    // !!!!!!!!!!!!!
    // By default, IOCON.BANK=0, therefore see Table 1-6 in the datasheet for register mapping
    //
    // Table 1-5, which confusingly appears sooner in the datasheet, displays register addresses 
    // for IOCON.BANK=1, which are significantly different 
    // !!!!!!!!!!!!!
    
    //Setting PORTA to output
    spi_bufTx[0] = spi_opcode_write;
    spi_bufTx[1] = 0x00; //register no. (IODIRA) 
    spi_bufTx[2] = 0x00; //IODIRA data, bitmask, 0=output, 1=input
    spi_write_count = 3;
    spi_read_count = 0;
    spi_ret_fun = SPI(spi_bus_handle, 0, spi_bufTx, spi_write_count, spi_bufRx, spi_read_count);

    //Setting PORTB to input
    spi_bufTx[0] = spi_opcode_write;
    spi_bufTx[1] = 0x01; //register no. (IODIRB) 
    spi_bufTx[2] = 0xFF; //IODIRB data, bitmask, 0=output, 1=input
    spi_write_count = 3;
    spi_read_count = 0;
    spi_ret_fun = SPI(spi_bus_handle, 0, spi_bufTx, spi_write_count, spi_bufRx, spi_read_count);

    //Enabling pull-up resistors on PORTB
    spi_bufTx[0] = spi_opcode_write;
    spi_bufTx[1] = 0x0D; //register no. (GPPUB) 
    spi_bufTx[2] = 0xFF; //GPPUB data, bitmask, 0=no pull-up, 1=pull-up enabled
    spi_write_count = 3;
    spi_read_count = 0;
    spi_ret_fun = SPI(spi_bus_handle, 0, spi_bufTx, spi_write_count, spi_bufRx, spi_read_count);

    return 0;
}
开发者ID:rexcontrols,项目名称:REXexamples,代码行数:59,代码来源:mcp23s17.c

示例4: tos_set_video_adjust

void tos_set_video_adjust(char axis, char value) {
  config.video_adjust[axis] += value;

  EnableFpga();
  SPI(MIST_SET_VADJ);
  SPI(config.video_adjust[0]);
  SPI(config.video_adjust[1]);
  DisableFpga();
}
开发者ID:wsoltys,项目名称:mist-board,代码行数:9,代码来源:tos.c

示例5: rda1846TXDTMF

void rda1846TXDTMF(unsigned char* values, unsigned int len, unsigned short delay)
{
  int i=0;
  //Set tx mode
  SPI(0x1F, 0xC000);
  SPI(0x63, 0x01F0 ); //00000001 00010001
  SPI(0x30, 0x3046); //TX
  
  for(i=0; i<len; i++)
  {
    if (values[i] < 0x10)
    {
      //Get data from dtmf table
      SPI(0x35, dtmfTone[values[i]][0]); 
      SPI(0x36, dtmfTone[values[i]][1]); 
      msDelay(delay);
      SPI(0x35, 0); 
      SPI(0x36, 0); 
    }
  }

  //Switch back to RX mode
  SPI(0x30, 0x302E); //RX
  SPI(0x1F, 0x0000);
}
开发者ID:madberry,项目名称:UV3RMod,代码行数:25,代码来源:rda.c

示例6: mist_memory_read

static void mist_memory_read(char *data, unsigned long words) {
  EnableFpga();
  SPI(MIST_READ_MEMORY);

  // transmitted bytes must be multiple of 2 (-> words)
  while(words--) {
    *data++ = SPI(0);
    *data++ = SPI(0);
  }

  DisableFpga();
}
开发者ID:UIKit0,项目名称:mist-firmware,代码行数:12,代码来源:tos.c

示例7: SPI_PUMP

int SPI_PUMP()
{
	int r=0;
	SPI(0xFF);
	r=SPI_READ();
	SPI(0xFF);
	r=(r<<8)|SPI_READ();
	SPI(0xFF);
	r=(r<<8)|SPI_READ();
	SPI(0xFF);
	r=(r<<8)|SPI_READ();
	return(r);
}
开发者ID:mrdudz,项目名称:FPGAPCE,代码行数:13,代码来源:spi.c

示例8: sd_read_sector

int sd_read_sector(unsigned long lba,unsigned char *buf)
{
	int result=0;
	int i;
	int r;
//	printf("sd_read_sector %d, %d\n",lba,buf);
	SPI(0xff);
	SPI_CS(1|(1<<HW_SPI_FAST));
	SPI(0xff);

	r=cmd_read(lba);
	if(r!=0)
	{
		puts("Read failed\n");
//		printf("Read command failed at %d (%d)\n",lba,r);
		return(result);
	}

	i=1500000;
	while(--i)
	{
		int v;
		SPI(0xff);
//		SPI_WAIT();
		v=SPI_READ();
		if(v==0xfe)
		{
//			puts("Reading sector data\n");
//			spi_readsector((long *)buf);
			int j;
//			SPI(0xff);

			for(j=0;j<128;++j)
			{
				int t,v;

				t=SPI_PUMP();
				*(int *)buf=t;
//				printf("%d: %d\n",buf,t);
				buf+=4;
			}

			i=1; // break out of the loop
			result=1;
		}
	}
	SPI(0xff);
	SPI(0xff); 	// Discard Two CRC bytes
	SPI_CS(0);
	return(result);
}
开发者ID:mrdudz,项目名称:FPGAPCE,代码行数:51,代码来源:spi.c

示例9: mist_memory_set_address

static void mist_memory_set_address(unsigned long a, unsigned char s, char rw) {
  //  iprintf("set addr = %x, %d, %d\n", a, s, rw);

  a |= rw?0x1000000:0;
  a >>= 1;

  EnableFpga();
  SPI(MIST_SET_ADDRESS);
  SPI(s);
  SPI((a >> 16) & 0xff);
  SPI((a >>  8) & 0xff);
  SPI((a >>  0) & 0xff);
  DisableFpga();
}
开发者ID:UIKit0,项目名称:mist-firmware,代码行数:14,代码来源:tos.c

示例10: rda1846GetStatus

//Get the signal stength indications
void rda1846GetStatus(short* rssi, short* vssi) //, short* dtmf, short* flags)
{
  *rssi = SPI(0x5F | 0x80, 0x0000) & 0x03FF;
  *rssi >>= 3; //devide by 8
  *rssi -= 135; //Per datasheet
  *rssi *= -1;

  *vssi = SPI(0x60 | 0x80, 0x0000) & 0x7FFF; 

  //*dtmf = SPI(0x6C | 0x80, 0x0000);

  //*flags = SPI(0x5C | 0x80, 0x0000);

}
开发者ID:madberry,项目名称:UV3RMod,代码行数:15,代码来源:rda.c

示例11: spi_init

int spi_init()
{
	int j;
	int i;
	int r;
	SDHCtype=1;
	j=5;
	while(--j)
	{
		SPI_CS(0);	// Disable CS
		spi_spin();
		puts("SD init...\n");
	//	puts("SPI Init()\n");
		DBG("Activating CS\n");
		SPI_CS(1);
		i=50;
		while(--i)
		{
			if(cmd_reset()==1) // Enable SPI mode
			{
				i=1;
				j=1;
			}
			DBG("Sent reset command\n");
			if(i==2)
			{
				puts("SD card reset failed!\n");
				return(0);
			}
		}
	}
	DBG("Card responded to reset\n");
	SDHCtype=is_sdhc();
	if(SDHCtype)
		DBG("SDHC card detected\n");
	else 	// Not SDHC? Set blocksize to 512.
	{
		DBG("Sending cmd16\n");
		cmd_CMD16(1);
	}
	SPI(0xFF);
	SPI_CS(0);
	SPI(0xFF);
	DBG("Init done\n");

	return(1);
}
开发者ID:mrdudz,项目名称:FPGAPCE,代码行数:47,代码来源:spi.c

示例12: mist_memory_write_block

static void mist_memory_write_block(char *data) {
  EnableFpga();
  SPI(MIST_WRITE_MEMORY);

  spi_block_write(data);

  DisableFpga();
}
开发者ID:UIKit0,项目名称:mist-firmware,代码行数:8,代码来源:tos.c

示例13: mist_memory_read_block

static void mist_memory_read_block(char *data) {
  EnableFpga();
  SPI(MIST_READ_MEMORY);

  spi_block_read(data);

  DisableFpga();
}
开发者ID:UIKit0,项目名称:mist-firmware,代码行数:8,代码来源:tos.c

示例14: OsdClear

// clear buffer <c>
void OsdClear(void)
{
	unsigned short n;

	// select OSD SPI device
	EnableOsd();

	// select buffer to write to
	SPI(OSDCMDWRITE|0x18);

	// clear buffer
	for(n=0; n < (OSD_LINE_BYTES * OSD_NO_LINES); n++)
	{	SPI(0x00);	}

	// deselect OSD SPI device
	DisableOsd();
}
开发者ID:Automatisa,项目名称:minimig,代码行数:18,代码来源:osd.c

示例15: spi_spin

void spi_spin()
{
//	puts("SPIspin\n");
    int i;
    for(i=0; i<200; ++i)
        SPI(0xff);
//	puts("Done\n");
}
开发者ID:robinsonb5,项目名称:ZPUTest,代码行数:8,代码来源:spi.c


注:本文中的SPI函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。