/***************************************************************************//**
 * @brief Writes data to AD5160
 *
 * @param RegValue - The value to be written to AD5160.
 *
 * @return None.
*******************************************************************************/
void Exosite_AD5160_Set(unsigned char value)
{
	unsigned char data[2] = {0x00, 0x00};
	data[0] = 0x1;	// SPI chip select
	data[1] = value;
	SPI_Write(data,1);		
}
Beispiel #2
0
/**
   @brief Write data to register

   @param ui8address - register address
   @param ui32data - data to write

   @return none
**/
void AD7793_WriteRegister( uint8_t ui8address, uint32_t ui32data)
{
   uint8_t ui8reg_adrr = (AD7793_COMM_WRITE | AD7793_COMM_ADR(ui8address));   /* Set value (write command + register address) to write in COMM register */

   SPI_Write(ui8reg_adrr, ui32data,  reg_size[ui8address]);  /* Write register value */

}
Beispiel #3
0
/**
   @brief ADC converter reset

   @return none
**/
void AD7793_Reset(void)
{

   SPI_Write(0, 0, 4);    /* Write 4 bytes = 0xFF */

   timer_sleep(0.05);   /* Wait time before accessing any registers after reset */
}
Beispiel #4
0
unsigned int send0(unsigned char *buf,unsigned int buflen){
    unsigned int ptr,offaddr,realaddr,txsize,timeout;
	//printf("send0 %d\n",buflen);
    if (buflen <= 0) return 0;
    // Make sure the TX Free Size Register is available
    txsize=SPI_Read(SO_TX_FSR);
    txsize=(((txsize & 0x00FF) << 8 ) + SPI_Read(SO_TX_FSR + 1));
    timeout=0;
    while (txsize < buflen) {
      delay(1);
     txsize=SPI_Read(SO_TX_FSR);
     txsize=(((txsize & 0x00FF) << 8 ) + SPI_Read(SO_TX_FSR + 1));
     // Timeout for approx 1000 ms
     if (timeout++ > 1000) {
       printf("TX Free Size Error!\n");
       // Disconnect the connection
       disconnect0();
       return 0;
     }
   }

   // Read the Tx Write Pointer
   ptr = SPI_Read(S0_TX_WR);
   offaddr = (((ptr & 0x00FF) << 8 ) + SPI_Read(S0_TX_WR + 1));

    while(buflen) {
      buflen--;
      // Calculate the real W5100 physical Tx Buffer Address
      realaddr = TXBUFADDR + (offaddr & TX_BUF_MASK);
      // Copy the application data to the W5100 Tx Buffer
      SPI_Write(realaddr,*buf);
      offaddr++;
      buf++;
    }

    // Increase the S0_TX_WR value, so it point to the next transmit
    SPI_Write(S0_TX_WR,(offaddr & 0xFF00) >> 8 );
    SPI_Write(S0_TX_WR + 1,(offaddr & 0x00FF));

    // Now Send the SEND command
    SPI_Write(S0_CR,CR_SEND);

    // Wait for Sending Process
    while(SPI_Read(S0_CR));

    return 1;
}
Beispiel #5
0
uchar SPIRD(uchar rs)   //写SPI移入数据, RS=0输入指令, RS=1输入数据
{
uchar rdata;
	SPI_Write(0xf8+(1<<2)+(rs<<1));		//数据格式:11111 | RW | RS | 0 |
	rdata=SPI_Read()&0xf0;			//读取数据字高4位,数据格式: D7-D4| 0000 |
	rdata=rdata|((SPI_Read()&0xf0)>>4);		//读取数据字低4位,数据格式:  D3-D0| 0000 |
return rdata;
}
Beispiel #6
0
// Writes multple bytes to a given register over SPI.
unsigned char SPI_Write_Buf(unsigned char reg, unsigned char *pBuf, unsigned char bytes)
{
    unsigned char status,i;

    PIO_Clear(&CSN);                                 // Set CSN low, init SPI tranaction
    SPI_Write(AT91C_BASE_SPI0, 0, reg);              // Select register to write to and read status unsigned char
    while(!SPI_IsFinished(AT91C_BASE_SPI0));         // Wait for write to complete
    status = SPI_Read(AT91C_BASE_SPI0);              // read status of the 24l01
    for(i=0;i<bytes; i++)                            // then write all unsigned char in buffer(*pBuf)
    {
        SPI_Write(AT91C_BASE_SPI0, 0, *pBuf++);
        while(!SPI_IsFinished(AT91C_BASE_SPI0));     // Wait for write to complete
    }
    PIO_Set(&CSN);                                   // Set CSN high again
  
    return(status);                // return nRF24L01 status unsigned char
}
Beispiel #7
0
/***************************************************************************//**
 * @brief Writes a value to the selected register.
 *
 * @param registerAddress - The address of the register to write to.
 * @param registerValue - The value to write to the register.
 *
 * @return None.
*******************************************************************************/
int32_t ad9122_write(uint8_t registerAddress,
				     uint8_t registerValue)
{
	uint8_t regAddr = 0;
	
	regAddr = (0x7F & registerAddress);
	return SPI_Write(SPI_SEL_AD9122, regAddr, registerValue);
}
Beispiel #8
0
/***************************************************************************//**
 * @brief Sends data to AD7303.
 *
 * @param controlReg - Value of control register.
 *                     Example: 
 *                     AD7303_INT | AD7303_LDAC | AD7303_A  - enables internal
 *                     reference and loads DAC A input register from shift 
 *                     register and updates both DAC A and DAC B DAC registers.
 * @param dataReg    - Value of data register.
 *
 * @return None.
*******************************************************************************/
void AD7303_Write(unsigned char controlReg, unsigned char dataReg)
{
    static unsigned char writeData[2] = {0, 0};
    
    writeData[0] = controlReg;
    writeData[1] = dataReg;
    SPI_Write(AD7303_SLAVE_ID, writeData, 2);
}
/**
 * \brief Send single command to ILI9488
 * \param cmd  command.
 */
static void ILI9488_SendCmd(uint8_t cmd)
{
	uint32_t i;
	PIO_Clear(&lcd_spi_cds_pin);
	SPI_Write(ILI9488_SPI, SMC_EBI_LCD_CS, cmd);

	for (i = 0; i < 0x18; i++);
}
Beispiel #10
0
/**
   @brief Initialization the accelerometer sensor

   @return none

**/
void Sensor_Init(void)
{
   DioPulPin(CSACC_PORT, CSACC_PIN_NUMBER, 0);          /* Disable the internal pull up on CSACC pin */
   DioOenPin(CSACC_PORT, CSACC_PIN_NUMBER, 1);          /* Set CSACC pin as output */

   DioPulPin(INT1ACC_PORT, INT1ACC_PIN_NUMBER, 0);         /* Disable the internal pull up on INT1ACC pin */
   DioOenPin(INT1ACC_PORT, INT1ACC_PIN_NUMBER, 0);         /* Set INT1ACC pin as input */

   DioPulPin(INT2ACC_PORT, INT2ACC_PIN_NUMBER, 0);         /* Disable the internal pull up on INT2ACC pin */
   DioOenPin(INT2ACC_PORT, INT2ACC_PIN_NUMBER, 0);         /* Set INT2ACC pin as input */

   SPI_Write(SOFT_RESET_REG, 0x52, SPI_WRITE_REG);  /* Soft reset accelerometer */

   timer_sleep(100);                         /* Wait at least 0.5 ms */

   /* Set activity threshold */
   SPI_Write(THRESH_ACT_L, ACT_VALUE & 0xFF, SPI_WRITE_REG);
   SPI_Write(THRESH_ACT_H, ACT_VALUE >> 8, SPI_WRITE_REG);

   SPI_Write(TIME_ACT, (ACT_TIMER / 10), SPI_WRITE_REG);          /* Set activity time at 100Hz data rate */

   /* Set inactivity threshold */
   SPI_Write(THRESH_INACT_L, INACT_VALUE & 0xFF, SPI_WRITE_REG);
   SPI_Write(THRESH_INACT_H, INACT_VALUE >> 8, SPI_WRITE_REG);

   /* Set inactivity time at 100Hz data rate */
   SPI_Write(TIME_INACT_L, ((INACT_TIMER * 100) & 0xFF), SPI_WRITE_REG);
   SPI_Write(TIME_INACT_H, ((INACT_TIMER * 100) >> 8), SPI_WRITE_REG);

   SPI_Write(ACT_INACT_CTL, 0x3F, SPI_WRITE_REG);         /* Set Loop mode, referenced mode for activity and inactivity, enable activity and inactivity functionality */

   SPI_Write(INTMAP1, 0x40, SPI_WRITE_REG);                  /* Map the awake status to INT1 pin */
}
Beispiel #11
0
/***************************************************************************//**
 * @brief Resets the serial interface with the ADT7310.
 *
 * @param None.
 *
 * @return None.
*******************************************************************************/
void ADT7310_Reset(void)
{
    unsigned char bytesNumber = 5;
    unsigned char txBuf[5]    = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF};

    ADT7310_CS_LOW;
    SPI_Write(1, (unsigned char*)txBuf, bytesNumber);
    ADT7310_CS_HIGH;
}
Beispiel #12
0
/***************************************************************************//**
 * @brief Reset the serial interface with the AD7193.
 *
 * @param None.
 *
 * @return None.
*******************************************************************************/
void AD7193_Reset(void)
{
    unsigned char bytesNumber = 6;
    unsigned char txBuf[6]    = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};

    AD7193_CS_LOW;
    SPI_Write(1, (unsigned char*)txBuf, bytesNumber);
    AD7193_CS_HIGH;
}
Beispiel #13
0
/*
*********************************************************************************************************
*                                           AD7799_CMD_Read()
*
* Description : Read AD7799 registers via SPI interface.
*
* Argument(s) : None. 
*
* Return(s)   : Byte return from AD7799
* 
* Caller(s)   : 
*
* Note(s)     : None.
*********************************************************************************************************
*/
static unsigned char AD7799_CMD_Read( void ) 
{  
    unsigned char ReadData;    
   
    SPI_Write(spi_adc, NPCS_AD7799, 0x00);   
    ReadData = SPI_Read(  spi_adc  );
     
    return ReadData;
}
/***************************************************************************//**
 * @brief Writes data to AD5541A   PMODDA3
 *
 * @param RegValue - The value to be written to AD5541A.
 *
 * @return None.
*******************************************************************************/
void Exosite_AD5541_Set(unsigned short value)
{
    unsigned char registerWord[3] = {0, 0, 0};
    //unsigned char  = (unsigned char*)&value;

    registerWord[0] = 0x01;
    registerWord[1] = value / 0xFF;
    registerWord[2] = value % 0xFF;
    SPI_Write(registerWord,2);	
}
Beispiel #15
0
void SPI_Read_Burst_Reg(uint8_t addr, uint8_t *buffer, uint8_t count)
{
	uint8_t i;
	RF_CS_PORT->ODR &=~ RF_CS_PIN;
	while (RF_MISO_PORT->IDR & RF_MISO_PIN);
	SPI_Write(addr | READ_BURST);
	for (i = 0; i < count; i++)
		buffer[i] = SPI_Read();
	RF_CS_PORT->ODR |= RF_CS_PIN;
}
Beispiel #16
0
uint8_t SPI_Read_Status(uint8_t addr)
{
	uint8_t x;
	RF_CS_PORT->ODR &=~ RF_CS_PIN;
	while (RF_MISO_PORT->IDR & RF_MISO_PIN);
	x = SPI_Write(addr | READ_BURST);
	x = SPI_Read();
	RF_CS_PORT->ODR |= RF_CS_PIN;
	return x;
}
Beispiel #17
0
/***************************************************************************//**
 * @brief Updates the state of the ADG1414's switches.
 *
 * @param None.
 *
 * @return None.
*******************************************************************************/
void ADG1414_State(unsigned char switches)
{
    SPI_Init(0, 1000000, 0, 0);
    TIME_DelayMs(100);
    ADG1414_CS_LOW;
    SPI_Write(1, &switches, 1);
    ADG1414_CS_HIGH;
    SPI_Init(0, 1000000, 1, 0);
    TIME_DelayMs(100);
}
Beispiel #18
0
// Reads response of a multi-byte SPI transaction.
unsigned char SPI_Read_Buf(unsigned char reg, unsigned char *pBuf, unsigned char bytes)
{
    unsigned char status,i;

    PIO_Clear(&CSN);                           // Set CSN low, init SPI tranaction
    SPI_Write(AT91C_BASE_SPI0, 0, reg);        // Select register to write to and read status unsigned char
    while(!SPI_IsFinished(AT91C_BASE_SPI0));   // Wait for write to complete
    status = SPI_Read(AT91C_BASE_SPI0);        // read status of the 24l01
  
    for(i=0;i<bytes;i++)
    {
        SPI_Write(AT91C_BASE_SPI0, 0, 0);             // write dummy byte
            while(!SPI_IsFinished(AT91C_BASE_SPI0));  // Wait for write to complete
        pBuf[i] = SPI_Read(AT91C_BASE_SPI0);          // Read unsigned char from nRF24L01
    }

    PIO_Set(&CSN);                                    // Set CSN high again

    return(status);                  // return nRF24L01 status unsigned char
}
Beispiel #19
0
/**
   @brief Puts the accelerometer into standby mode.

   @return none

**/
void Sensor_Stop(void)
{
   uint8_t ui8temp;

   ui8temp = (uint8_t)SPI_Read(POWER_CTL_REG, SPI_READ_ONE_REG);        /*Read POWER_CTL register, before modifying it */

   ui8temp = ui8temp & 0xFC;                                      /* Clear measurement bit in POWER_CTL register */

   SPI_Write(POWER_CTL_REG, ui8temp, SPI_WRITE_REG);                 /* Write the new value to POWER_CTL register */

}
Beispiel #20
0
/***************************************************************************//**
* @brief Resets the device.
*
* @param device - The handler of the instance of the driver.
*
* @return Returns 0 for success or negative error code.
*******************************************************************************/
int32_t AD7124_Reset(struct ad7124_device *device)
{
	int32_t ret = 0;
	uint8_t wrBuf[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};

	if(!device)
		return INVALID_VAL;

	ret = SPI_Write(device->slave_select_id, wrBuf, 8);

	return ret;
}
Beispiel #21
0
void __attribute((interrupt(SPI_VECTOR)))ISR_SPI() {
  SPI_Data[SPI_Pos] = SPI_Read();
  SPI_Pos++;
  if (SPI_Pos < SPI_Len) {
    // send one more byte
    SPI_Write(SPI_Data[SPI_Pos]);
  } else {
    ADT7310_CS_OUT |= ADT7310_CS_PIN;   // low active --> deactivate
    // Exit the low power mode
    LPM1_EXIT;
  }
}
Beispiel #22
0
uint8_t SST25_Read(uint32_t addr, uint8_t *buf, uint32_t count)
{
	uint16_t timeout = 10000;
	while((SST25__Status() & 0x01) && timeout)
	{
		timeout--;
	}

	SST_CS_Assert();
	SPI_Write(CMD_READ80);
	SPI_Write(addr >> 16);
	SPI_Write(addr >> 8);
	SPI_Write(addr);
	SPI_Write(0); // write a dummy byte
	while(count--)
		*buf++ = SPI_Write(0);

	SST_CS_DeAssert();

	return 0;
}
Beispiel #23
0
/**
   @brief Turns on accelerometer measurement mode.

   @return none

**/
void Sensor_Start(void)
{
   uint8_t ui8temp;

   Sensor_Delay(1, &ui32ScanSensorCounter, SCAN_SENSOR_TIME);       /* Perform a sensor delay */

   ui8temp = (uint8_t)SPI_Read(POWER_CTL_REG, SPI_READ_ONE_REG);       /* Read POWER_CTL register, before modifying it */

   ui8temp = ui8temp | 0x02;                                          /* Set measurement bit in POWER_CTL register */

   SPI_Write(POWER_CTL_REG, ui8temp, SPI_WRITE_REG);                    /* Write the new value to POWER_CTL register */
}
Beispiel #24
0
//------------------------------------------------------------------------------
void Mez_TR_init(mezonin *MezStruct)
{
	uint32_t CS_configuration;
	Mezonin_TR[MezStruct->Mez_ID - 1].Channel.flDAC = 0;
	CS_configuration = AT91C_SPI_BITS_8  | 0x30 << 8  |  0<<24| 0<<16  | AT91C_SPI_NCPHA;
	SPI_ConfigureNPCS(AT91C_BASE_SPI0, MezStruct->Mez_ID-1, CS_configuration);
	if (xSPISemaphore != NULL) {
		if (xSemaphoreTake( xSPISemaphore, portMAX_DELAY ) == pdTRUE) {
			SPI_Write(AT91C_BASE_SPI0, MezStruct->Mez_ID-1, 0b01010101);//control register
			SPI_Read(AT91C_BASE_SPI0);
			SPI_Write(AT91C_BASE_SPI0, MezStruct->Mez_ID-1, 0b10000);//output enable
			SPI_Read(AT91C_BASE_SPI0);
			SPI_Write(AT91C_BASE_SPI0, MezStruct->Mez_ID-1, 0b110);// от 0 до 20 mA
			SPI_Read(AT91C_BASE_SPI0);
			SPI_Write(AT91C_BASE_SPI0, MezStruct->Mez_ID-1, 0b1);//data register
			SPI_Read(AT91C_BASE_SPI0);
			SPI_Write(AT91C_BASE_SPI0, MezStruct->Mez_ID-1, 0);
			SPI_Read(AT91C_BASE_SPI0);
			SPI_Write(AT91C_BASE_SPI0, MezStruct->Mez_ID-1, 0);
			SPI_Read(AT91C_BASE_SPI0);
			xSemaphoreGive(xSPISemaphore);
		}
	}

}
Beispiel #25
0
void Mp3Reset(void)
{
    P7 = 0x60;  // P7.4 is RESET
    Delay(100);
    P7 = 0x70;  // DCS = XCS = RESET = 1
    wr_cmd(0x00, 0x08, 0x04);
    Delay(10);
    P6 = 0x40;  // DREQ = 1;
    while ((P6 & 0x40) == 0);
    wr_cmd(0x03, 0x98, 0x00);
    Delay(10);
    wr_cmd(0x05, 0xbb, 0x81);
    Delay(10);
    wr_cmd(0x02, 0x00, 0x55);
    Delay(10);
    wr_cmd(0x0b, 0x04, 0x04);  // Volumn
    Delay(10);
    SPI_Write(0);
    SPI_Write(0);
    SPI_Write(0);
    SPI_Write(0);
}
Beispiel #26
0
static uint8_t SST25__GlobalProtect(uint8_t enable)
{
	uint8_t status = enable ? 0x3C : 0x00;
	uint32_t timeout = 10000;
	while((SST25__Status() & 0x01) && timeout)
	{
		timeout--;
	}

	SST_CS_Assert();
	SPI_Write(CMD_WRITE_STATUS_ENABLE);
	SST_CS_DeAssert();

	SST_CS_Assert(); // assert CS

	SPI_Write(CMD_WRITE_STATUS); // WRITE STATUS command
	SPI_Write(status); //

	SST_CS_DeAssert(); // de-assert cs

	return 0;
}
/***************************************************************************//**
 * @brief Initiates conversion and reads data.
 *
 * @return receivedData - Data read from the ADC.
*******************************************************************************/
unsigned short Exosite_AD7980_Conversion(void)
{
	unsigned short receivedData = 0;
	unsigned char txData[2] = { 0, 0};
	
	txData[0] = 0xFF;
	txData[1] = 0xFE;
	SPI_Write(txData,2);
	ADI_CS_LOW;
	SPI_Read(&receivedData);
	ADI_CS_HIGH;
	
	return(receivedData);		
}
/*********************************************
 功能:第一个字节写入的是命令值,剩余的是参数,
 在配置阶段使用

 *********************************************/
static void EPD_W21_Write(unsigned char *value, unsigned char datalen) {
	unsigned char i = 0;
	unsigned char *ptemp;

	ptemp = value;

	EPD_W21_CS_0;
	EPD_W21_DC_0;		// command write

	SPI_Write(*ptemp);
	ptemp++;

	EPD_W21_DC_1;		// data write

	for (i = 0; i < datalen - 1; i++)	// sub the command
			{
		SPI_Write(*ptemp);
		ptemp++;
	}

	EPD_W21_CS_1;

}
Beispiel #29
0
void LedsShifter_b(){
  static char data=0x20;
  
  SPI_Write(data);
  if (elapsedTimeFlag==SET){
    elapsedTimeFlag=CLEAR;
    if ((data&0x3F) == 0x01){
      ready_b=SET;
      data=0x20;
    }else{
      data=(data>>1);
    }  
    timeCount=timeValue;                
  }           
bool ADXL345_SPI_Init(alt_u32 device_base){
    bool bSuccess;
    
    // clear fifo
    SPI_Init(device_base);
   
    // 3-wire spi
    bSuccess = SPI_Write(device_base, ADXL345_REG_DATA_FORMAT, XL345_SPI3WIRE);
 
    // clear fifo   
    SPI_Init(device_base);
        
    //Output Data Rate: 40Hz
    if (bSuccess){
        bSuccess = SPI_Write(device_base, ADXL345_REG_BW_RATE, XL345_RATE_400); // 400 MHZ
    }
    
        
    //INT_Enable: Data Ready
    if (bSuccess){   
        bSuccess = SPI_Write(device_base, ADXL345_REG_INT_ENALBE, XL345_DATAREADY);
    }
    
    // stop measure
    if (bSuccess){
        bSuccess = SPI_Write(device_base, ADXL345_REG_POWER_CTL, XL345_STANDBY);
    }

    // start measure
    if (bSuccess){
        bSuccess = SPI_Write(device_base, ADXL345_REG_POWER_CTL, XL345_MEASURE);
        
    }
    
            
    return bSuccess;
}