Exemplo n.º 1
0
/*************************************************

名称:spi_rw(u8 *data_buff, u8 byte_quantity, u8 reg_address, u8 control_byte)
功能:spi多字节读写
输入参数:
    u8 *data_buff     数据指针
	u8 byte_quantity  读写字节数量
	u8 reg_address    寄存器地址
	u8 control_byte   读写控制标识
输出参数:无
返回值:  无
**************************************************/
void spi_rw(u8 *data_buff, u8 byte_quantity, u8 reg_address, u8 control_byte)
{
  u8 i;
  if(control_byte == 0)  //write
  { 		 
    spi_nss_low();

	spi_rw_byte(reg_address);

	for(i = 0; i < byte_quantity; i++)
	{
	  spi_rw_byte(*data_buff);
	  data_buff++;
	}

	spi_nss_high();
  }
  else if(control_byte == 1)
  {
    spi_nss_low();

	spi_rw_byte(reg_address);

	for(i = 0; i < byte_quantity; i++)
	{
	  *data_buff = spi_rw_byte(0);
	  data_buff++;
	}

	spi_nss_high();
  }
}
Exemplo n.º 2
0
//write buffer
uint8_t spi_write_buf(uint8_t cmd, uint8_t* const data, uint16_t size)
{
    uint8_t status =0;
    uint8_t* pdata = data;
    uint8_t i = 0;
	
    SPI_ENABLE(); //Select chip
    status = spi_rw_byte(cmd);    //write tx payload
    
    for(i = 0 ; i < size; i++)
    {        
        printf("0x%x,",*pdata);
        spi_rw_byte(*pdata++);                        
    }

    SPI_DISABLE(); //Deselect chip

    return status;
}
Exemplo n.º 3
0
//Sends one byte command
uint8_t spi_send_cmd(uint8_t cmd)
{
    uint8_t status;
	
    SPI_ENABLE(); //Select chip
    status = spi_rw_byte(cmd);
    SPI_DISABLE(); //Deselect chip
    
    return(status);
}