コード例 #1
0
static void s_hal_spi_periph_disable(hal_spi_t id) 
{
    SPI_TypeDef* SPIx = HAL_spi_id2stmSPI(id);
    while(SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_BSY) == SET);    // wait until it's free	
    //hal_SPI4ENCODER_DISA(SPIx);                                      
    SPI_Cmd(SPIx, DISABLE);
}
コード例 #2
0
ファイル: spi.c プロジェクト: LindaLovelace/stm32doom
/*
 * Write one byte to SPI and read one byte
 *
 * @param[in]	data	Byte to write
 * @return				Byte read
 */
uint8_t spi_send_receive (uint8_t data)
{
	uint8_t value;

	// wait for SPI to be ready
	while (SPI_I2S_GetFlagStatus (SPI, SPI_I2S_FLAG_TXE) == RESET);

	SPI_I2S_SendData (SPI, data);

	// wait for byte to be received
	while (SPI_I2S_GetFlagStatus (SPI, SPI_I2S_FLAG_RXNE) == RESET);

	value = SPI_I2S_ReceiveData (SPI);

	return value;
}
コード例 #3
0
/**
  * @brief  Reset LCD control line(/CS) and Send Start-Byte
  * @param  Start_Byte: the Start-Byte to be sent
  * @retval None
  */
void LCD_nCS_StartByte(uint8_t Start_Byte)
{
	LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_RESET);
	SPI_I2S_SendData(LCD_SPI, Start_Byte);
	while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET) {
	}
}
コード例 #4
0
ファイル: spi.c プロジェクト: yoy52012/LoraSignalSlaveTest
uint8_t SpiInOut( uint8_t outData )
{
    /* Send SPIy data */
    SPI_I2S_SendData( SPI_INTERFACE, outData );
    while( SPI_I2S_GetFlagStatus( SPI_INTERFACE, SPI_I2S_FLAG_RXNE ) == RESET );
    return SPI_I2S_ReceiveData( SPI_INTERFACE );
}
コード例 #5
0
ファイル: spi_api.c プロジェクト: ElAbbassi/mbed
static inline int ssp_writeable(spi_t *obj) {
    int status;
    SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
    // Check if data is transmitted
    status = ((SPI_I2S_GetFlagStatus(spi, SPI_I2S_FLAG_TXE) != RESET) ? 1 : 0);
    return status;
}
コード例 #6
0
    bool SpiPollingWriter::write(uint8_t *dataToSend,uint32_t numBytes,uint8_t *dataReceived) {

        // wait for ready to send

        while(numBytes--) {

            while(!readyToSend())
                if(_peripheral.hasError())
                    return false;

            // send the byte

            SPI_I2S_SendData(_peripheral,*dataToSend++);

            if(_duplex) {

                // in duplex mode and we want data, wait for it to come

                while(SPI_I2S_GetFlagStatus(_peripheral,SPI_I2S_FLAG_RXNE)==RESET)
                    if(_peripheral.hasError())
                        return false;

                // read the byte to clear RXNE and save/discard

                if(dataReceived!=NULL)
                    *dataReceived++=SPI_I2S_ReceiveData(_peripheral);
                else
                    SPI_I2S_ReceiveData(_peripheral);
            }
        }

        return true;
    }
コード例 #7
0
ファイル: D_HaLayer.c プロジェクト: markusk/direcs
/**
  * @brief  Receives 1 Byte that has been send over the SPI Bus
  * @param  None
  * @retval The received Byte
  */
uint8_t D_SPI_ReceiveData(){

	/*!< Wait until the transmit buffer is empty */
	while(SPI_I2S_GetFlagStatus(D_SPI, SPI_I2S_FLAG_TXE) == RESET)
	{
	}

	SPI_I2S_SendData(D_SPI, DUMMYBYTE);

	/*!< Wait to receive a byte*/
	while(SPI_I2S_GetFlagStatus(D_SPI, SPI_I2S_FLAG_RXNE) == RESET)
	{
	}

	return SPI_I2S_ReceiveData(D_SPI);
}
コード例 #8
0
ファイル: drv_spi.c プロジェクト: lit1088/baseflight
bool spiTransfer(uint8_t *out, uint8_t *in, int len)
{
    uint8_t b;
    SPI2->DR;
    while (len--) {
        b = in ? *(in++) : 0xFF;
        while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
        SPI_I2S_SendData(SPI2, b);
        while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);
        b = SPI_I2S_ReceiveData(SPI2);
        if (out)
            *(out++) = b;
    }

    return true;
}
コード例 #9
0
ファイル: ILI9163.c プロジェクト: itsia/LCDDrivers
void SB(uint8_t Data, uint8_t DR){
	if(DR == Dat) GPIO_SetBits(GPIOA, AOPin);
	else GPIO_ResetBits(GPIOA, AOPin);

	SPI_SendData8(SPI1, Data);
	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);
}
コード例 #10
0
ファイル: i2s.c プロジェクト: JiuchengXu/shit
void SPI2_IRQHandler(void)
{
  	if (SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_TXE)!=RESET)
  	{     	
    	SPI_I2S_SendData(SPI2, 0);//??????I2S 
  	}
}
コード例 #11
0
void SPI_SendByte(uint8_t byte)
{
	GPIO_ResetBits(GPIOA,GPIO_Pin_4);
	SPI_SendData8(SPI1,byte);
	while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);
	GPIO_SetBits(GPIOA,GPIO_Pin_4);
}
コード例 #12
0
ファイル: lisa_test_adxl345.c プロジェクト: ljb2208/paparazzi
static uint8_t read_fom_reg(uint8_t addr) {

#warning "Needs porting to libopencm3 or use the real driver!"

#if 0
  AccSelect();
  SPI_I2S_SendData(SPI2, (1<<7|addr));
  while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
  SPI_I2S_SendData(SPI2, 0x00);
  while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
  while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET);
  uint8_t ret = SPI_I2S_ReceiveData(SPI2);
  AccUnselect();
#endif
  return ret;
}
コード例 #13
0
ファイル: SPI1.c プロジェクト: davidhajas/uCOS-II
void SPI1_Set(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint8_t adress, uint8_t data){

	GPIO_ResetBits(GPIOx, GPIO_Pin); //CS->0

	while(!SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE));  //transmit buffer empty?
	SPI_I2S_SendData(SPI1, adress);
	while(!SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE)); //data received?
	SPI_I2S_ReceiveData(SPI1);

	while(!SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE));  //transmit buffer empty?
	SPI_I2S_SendData(SPI1, data);
	while(!SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE)); //data received?
	SPI_I2S_ReceiveData(SPI1);

	GPIO_SetBits(GPIOx, GPIO_Pin); //CS->1
}
コード例 #14
0
static uint8_t spiWriteRead(uint8_t data)
{
  SPI_I2S_SendData(SPI1, data);
  while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET) {}
  data = (uint8_t)SPI_I2S_ReceiveData(SPI1);
  return data;
}
コード例 #15
0
uint8_t uSpiRead( SPI_TypeDef* SPIx )
{
    /* Wait until transmission complete */
    while( !SPI_I2S_GetFlagStatus( SPIx, SPI_I2S_FLAG_RXNE ) );

    return SPI_I2S_ReceiveData( SPIx );
}
コード例 #16
0
void write_command(unsigned char c)
{
  SPI_LCD_RS_LOW();

  SPI_LCD_CS_LOW();

  /* Send "Write Enable" instruction */
#if USE_SPI
  /* Send byte thROTATIONugh the LCD_SPIx peripheral */
  SPI_I2S_SendData(LCD_SPIx, c);
    /* Loop while DR register in not emplty */
  while (SPI_I2S_GetFlagStatus(LCD_SPIx, SPI_I2S_FLAG_TXE) == RESET);
#else
{	
	int i;
	for (i=0; i<8; i++) {
		SPI_LCD_DAT(0x01&(c>>(7-i)));
		SPI_LCD_CLK(0);
		SPI_LCD_CLK(1);	
	}
}
#endif

  /* Deselect the FLASH: Chip Select high */
  SPI_LCD_CS_HIGH();	
}
コード例 #17
0
ファイル: max7456.c プロジェクト: Aeroprobing/Betaflight
void max7456_dma_irq_handler(dmaChannelDescriptor_t* descriptor) {
    if (DMA_GET_FLAG_STATUS(descriptor, DMA_IT_TCIF)) {
#ifdef MAX7456_DMA_CHANNEL_RX
        DMA_Cmd(MAX7456_DMA_CHANNEL_RX, DISABLE);
#else
        //Empty RX buffer. RX DMA takes care of it if enabled
        while (SPI_I2S_GetFlagStatus(MAX7456_SPI_INSTANCE, SPI_I2S_FLAG_RXNE) == SET) {
            MAX7456_SPI_INSTANCE->DR;
        }
#endif
        DMA_Cmd(MAX7456_DMA_CHANNEL_TX, DISABLE);

        DMA_CLEAR_FLAG(descriptor, DMA_IT_TCIF);

        SPI_I2S_DMACmd(MAX7456_SPI_INSTANCE,
#ifdef MAX7456_DMA_CHANNEL_RX
                SPI_I2S_DMAReq_Rx |
#endif
                SPI_I2S_DMAReq_Tx, DISABLE);

        DISABLE_MAX7456;
        for (uint16_t x = 0; x < max_screen_size; x++)
            max7456_screen[x + 3] = MAX7456_CHAR(' ');
        dma_transaction_in_progress = 0;
    }
}
コード例 #18
0
ファイル: spi_api.c プロジェクト: ElAbbassi/mbed
static inline int ssp_readable(spi_t *obj) {
    int status;
    SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
    // Check if data is received
    status = ((SPI_I2S_GetFlagStatus(spi, SPI_I2S_FLAG_RXNE) != RESET) ? 1 : 0);
    return status;
}
コード例 #19
0
ファイル: spi.c プロジェクト: LindaLovelace/stm32doom
void spi_send (uint8_t data)
{
	// wait for SPI to be ready
	while (SPI_I2S_GetFlagStatus (SPI, SPI_I2S_FLAG_TXE) == RESET);

	SPI_I2S_SendData (SPI, data);
}
コード例 #20
0
ファイル: spi.c プロジェクト: eastmoutain/PX4-preph-test
uint8_t SPI_Read_One_Byte(SPI_TypeDef *SPIx)
{
    /* wait untill Receive one byte */
    while (SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_RXNE) == RESET);
    /* Receive a Byte through the SPI peripheral */
    return SPI_I2S_ReceiveData(SPIx);
}
コード例 #21
0
ファイル: decahard.c プロジェクト: Liyuxiang/Test
/*! ------------------------------------------------------------------------------------------------------------------
 * Function: writetospi()
 *
 * Low level abstract function to write to the SPI
 * Takes two separate byte buffers for write header and write data
 * returns 0 for success, or -1 for error
 */
int writetospi
(
    uint16       headerLength,
    const uint8 *headerBuffer,
    uint32       bodylength,
    const uint8 *bodyBuffer
)
{

	int i=0;

    decaIrqStatus_t  stat ;

    stat = decamutexon() ;

    /* Wait for SPIx Tx buffer empty */
    //while (port_SPIx_busy_sending());

	dw_set_device_select();		//cs low

    for(i=0; i<headerLength; i++)
    {
			while (SPI_I2S_GetFlagStatus(DW1000_SPI, SPI_I2S_FLAG_TXE) == RESET){}
			SPI_I2S_SendData(DW1000_SPI, headerBuffer[i]);
    	//port_SPIx_send_data(headerBuffer[i]); //send data on the SPI
			while (SPI_I2S_GetFlagStatus(DW1000_SPI, SPI_I2S_FLAG_RXNE) == RESET){}
			SPI_I2S_ReceiveData(DW1000_SPI);
    }

    for(i=0; i<bodylength; i++)
    {
			while (SPI_I2S_GetFlagStatus(DW1000_SPI, SPI_I2S_FLAG_TXE) == RESET){}
			SPI_I2S_SendData(DW1000_SPI, bodyBuffer[i]);
		//port_SPIx_send_data(bodyBuffer[i]); //send data on the SPI
			while (SPI_I2S_GetFlagStatus(DW1000_SPI, SPI_I2S_FLAG_RXNE) == RESET){}
			SPI_I2S_ReceiveData(DW1000_SPI);
		//while (port_SPIx_no_data()); //wait for rx buffer to fill

		//port_SPIx_receive_data(); //this clears RXNE bit
	}

    dw_reset_device_select();  //CS high

    decamutexoff(stat) ;

    return 0;
} // end writetospi()
コード例 #22
0
ファイル: lcd.c プロジェクト: peterliu2/FreeRTOS
/*******************************************************************************
* Function Name  : LCD_WriteRegIndex
* Description    : Writes index to select the LCD register.
* Input          : - LCD_Reg: address of the selected register.
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_WriteRegIndex(u8 LCD_Reg)
{
    /* Reset LCD control line(/CS) and Send Start-Byte */
    LCD_nCS_StartByte(START_BYTE | SET_INDEX);

    /* Write 16-bit Reg Index (High Byte is 0) */
    SPI_I2S_SendData(SPI3, 0x00);
    while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_BSY) != RESET) {
        vBlockToWait( 1 );
    }
    SPI_I2S_SendData(SPI3, LCD_Reg);
    while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_BSY) != RESET) {
        vBlockToWait( 1 );
    }

    LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);
}
コード例 #23
0
ファイル: platform.c プロジェクト: BackupTheBerlios/elua-svn
spi_data_type platform_spi_send_recv( unsigned id, spi_data_type data )
{
  SPI_I2S_SendData( spi[ id ], data );
  
  while ( SPI_I2S_GetFlagStatus( spi[ id ], SPI_I2S_FLAG_RXNE ) == RESET );
  
  return SPI_I2S_ReceiveData( spi[ id ] );
}
コード例 #24
0
ファイル: spi2.c プロジェクト: tommyleo/speedyflight
// return uint8_t value or -1 when failure
uint8_t spiTransferByte2(uint8_t data)
{
    uint16_t spiTimeout = SPI2_TIMEOUT;

    while (SPI_I2S_GetFlagStatus(SPI_BUSE2, SPI_I2S_FLAG_TXE) == RESET)
        if ((spiTimeout--) == 0)
            return spiTimeoutUserCallback2();

    SPI_SendData(SPI_BUSE2, data);

    spiTimeout = SPI2_TIMEOUT;
    while (SPI_I2S_GetFlagStatus(SPI_BUSE2, SPI_I2S_FLAG_RXNE) == RESET)
        if ((spiTimeout--) == 0)
            return spiTimeoutUserCallback2();

    return ((uint8_t)SPI_ReceiveData(SPI_BUSE2));
}
コード例 #25
0
void LCDTFTConf::LCD_WriteData(uint8_t value)
{
    /* Set WRX to send data */
  LCD_CtrlLinesWrite(LCD_WRX_GPIO_PORT, LCD_WRX_PIN, Bit_SET);

  /* Reset LCD control line(/CS) and Send data */
  LCD_ChipSelect(DISABLE);
  SPI_I2S_SendData(LCD_SPI, value);

  /* Wait until a data is sent(not busy), before config /CS HIGH */

  while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_TXE) == RESET) ;

  while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET);

  LCD_ChipSelect(ENABLE);
}
コード例 #26
0
/**
  * @brief  Writes to the selected LCD register.
  * @param  LCD_Reg: address of the selected register.
  * @param  LCD_RegValue: value to write to the selected register.
  * @retval None
  */
void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue)
{
  /* Write 16-bit Index (then Write Reg) */
  LCD_WriteRegIndex(LCD_Reg);
  /* Write 16-bit Reg */
  /* Reset LCD control line(/CS) and Send Start-Byte */
  LCD_nCS_StartByte(START_BYTE | LCD_WRITE_REG);
  SPI_I2S_SendData(LCD_SPI, LCD_RegValue>>8);
  while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
  {
  }
  SPI_I2S_SendData(LCD_SPI, (LCD_RegValue & 0xFF));
  while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
  {
  }
  LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
}
コード例 #27
0
//Golden function sendata spi1
void mySPI_SendData(uint8_t address, uint8_t data){			// put in address and data to write to

	GPIO_ResetBits(GPIOE, GPIO_Pin_3);

	while(!SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE));  //transmit buffer empty?
	SPI_I2S_SendData(SPI1, address);
	
	while(!SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE)); //data received?
	SPI_I2S_ReceiveData(SPI1);

	while(!SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE));  //transmit buffer empty?
	SPI_I2S_SendData(SPI1, data);
	while(!SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE)); //data received?
	SPI_I2S_ReceiveData(SPI1);

	GPIO_SetBits(GPIOE, GPIO_Pin_3);
	}
コード例 #28
0
ファイル: spi1.c プロジェクト: PaulingZhou/Homework_Sensor
/******************************************************************************* 
* Function Name  : SPI_ReadWriteByte(u8 TxData) 
* Description    : 读写数据	 
* Input          : TxData
* Output         : RxData 
* Return         : RxData 
*******************************************************************************/
uint8_t SPI1_ReadWriteByte(uint8_t TxData)
{
	uint8_t retry = 0;
	while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE) == RESET)
	{
		retry++;
		if(retry>200)return 0;
	}
	SPI_I2S_SendData(SPI1,TxData);
	retry = 0;
	while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_RXNE) == RESET)
	{
		retry++;
		if(retry>200)return 0;
	}
	return SPI_I2S_ReceiveData(SPI1);
}
コード例 #29
0
uint8_t at86rf231_spi_transfer_byte(uint8_t byte)
{
  uint8_t ret;

  // wait for tx buffer to be empty
  while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
  SPI_I2S_SendData(SPI1, byte);

  // wait for rx buffer to be not empty
  while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
  ret = SPI_I2S_ReceiveData(SPI1);

  // wait until it is not busy
  while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);

  return ret;
}
コード例 #30
0
ファイル: rf_spi1.c プロジェクト: fwengineer/STM32-Libraries
/**
 * @brief	Writes data to the SPI
 * @param	Data: data to be written to the SPI
 * @retval	None
 */
void RF_SPI1_Write(uint8_t Data)
{
	/* Loop while DR register is not empty */
	while (SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_TXE) == RESET);

	/* Send byte through the SPIx peripheral */
	SPI_I2S_SendData(SPIx, (uint16_t)Data);
}