Esempio n. 1
0
File: SPI.c Progetto: SecretTank/ARM
uint8_t spi_transfer(uint8_t data) 
{
	SPI_CHECK_ENABLED_RESP(SPI2); //check if spi is enabled
	SPI_WAIT(SPI2);
	SPI2->DR = data;
	SPI_WAIT(SPI2);
	loop_until_bit_is_set(SPI2->SR,SPI_SR_RXNE); //wait to recieve data
	return SPI2->DR;
}
uint16_t TM_SPI_Send16(SPI_TypeDef* SPIx, uint16_t data) {
	/* Wait for previous transmissions to complete if DMA TX enabled for SPI */
	SPI_WAIT(SPIx);
	
	/* Fill output buffer with data */
	SPIx->DR = data;
	/* Wait for SPI to end everything */
	SPI_WAIT(SPIx);
	/* Return data from buffer */
	return SPIx->DR;
}
Esempio n. 3
0
static int
spi_bus_write
(
    struct s3c2410_spi  *device,
    uint8_t             cmd,
    uint16_t            data,
    enum jbt_write_mode mode
)
{
    int         i;
    uint16_t    buf[3];

    dprintf("%s: writing %2.2x : %4.4x (mode %d)\n",
            __func__, cmd, data, mode);

    switch (mode)
    {
    default:
        printf("%s: warning! unknown spi write mode %d\n", __func__, mode);
        return 1;

    case JBT_WRITE_16:
        buf[2] = JBT_DATA | (data & 0xff);
        data >>= 8;
        /* FALL THROUGH */
    case JBT_WRITE_8:
        buf[1] = JBT_DATA | (data & 0xff);
        /* FALL THROUGH */
    case JBT_WRITE_NODATA:
        buf[0] = JBT_COMMAND | cmd;
        break;
    }

    /* write data to reg */
    spi_nCS(0);                 /* chip-select the slave */

    for (i = 0; i < mode; i++)
    {
        dprintf("%s: writing byte %2.2x on wire\n", __func__, buf[i] & 0xff);

        SPI_WAIT();
        sptdat_set_txdata(buf[i] & 0xff);

        dprintf("%s: writing byte %2.2x on wire\n", __func__, buf[i] >> 8);

        SPI_WAIT();
        sptdat_set_txdata(buf[i] >> 8);
    }

    spi_nCS(1);                 /* un-select the slave */

    return 0;
}
void TM_SPI_ReadMulti16(SPI_TypeDef* SPIx, uint16_t* dataIn, uint16_t dummy, uint16_t count) {
	uint16_t i;
	
	/* Wait for previous transmissions to complete if DMA TX enabled for SPI */
	SPI_WAIT(SPIx);
	
	for (i = 0; i < count; i++) {
		/* Fill output buffer with data */
		SPIx->DR = dummy;
		/* Wait for SPI to end everything */
		SPI_WAIT(SPIx);
		/* Save data to buffer */
		dataIn[i] = SPIx->DR;
	}
}
void TM_SPI_WriteMulti16(SPI_TypeDef* SPIx, uint16_t* dataOut, uint16_t count) {
	uint16_t i;
	
	/* Wait for previous transmissions to complete if DMA TX enabled for SPI */
	SPI_WAIT(SPIx);
	
	for (i = 0; i < count; i++) {
		/* Fill output buffer with data */
		SPIx->DR = dataOut[i];
		/* Wait for SPI to end everything */
		SPI_WAIT(SPIx);
		/* Read data register */
		SPIx->DR;
	}
}
Esempio n. 6
0
void SPI_Write_Block(uint8_t* data, uint8_t len)
{
    uint8_t i;
    for (i = 0; i < len; i++) {
          SPDR = data[i];
          SPI_WAIT();
    }
}
Esempio n. 7
0
void SPI_ReadWrite_Block(uint8_t* data, uint8_t* buffer, uint8_t len)
{
    uint8_t i;
    for (i = 0; i < len; i++) {
          SPDR = data[i];
          SPI_WAIT();
          buffer[i] = SPDR;
    }
}
Esempio n. 8
0
uint8_t SPI_Send(SPI_TypeDef* SPIx, uint8_t data) {
	/* Check if SPI is enabled */
	SPI_CHECK_ENABLED_RESP(SPIx, 0);

	/* Wait for previous transmissions to complete if DMA TX enabled for SPI */
	SPI_WAIT(SPIx);

	/* Fill output buffer with data */
	//SPIx->DR = data;
	SPI_SendData8(SPIx, data);

	/* Wait for transmission to complete */
	SPI_WAIT(SPIx);

	/* Return data from buffer */
	//return SPIx->DR;
	return SPI_ReceiveData8(SPIx);
}
void TM_SPI_SendMulti16(SPI_TypeDef* SPIx, uint16_t* dataOut, uint16_t* dataIn, uint32_t count) {
	uint32_t i;	
	
	/* Check if SPI is enabled */
	SPI_CHECK_ENABLED(SPIx);
	
	/* Wait for previous transmissions to complete if DMA TX enabled for SPI */
	SPI_WAIT(SPIx);
	
	for (i = 0; i < count; i++) {
		/* Fill output buffer with data */
		SPIx->DR = dataOut[i];
		
		/* Wait for SPI to end everything */
		SPI_WAIT(SPIx);
		
		/* Read data register */
		dataIn[i] = SPIx->DR;
	}
}
Esempio n. 10
0
void SPI_WriteMulti(SPI_TypeDef* SPIx, uint8_t* dataOut, uint32_t count) {
	uint32_t i;

	/* Check if SPI is enabled */
	SPI_CHECK_ENABLED(SPIx);

	/* Wait for previous transmissions to complete if DMA TX enabled for SPI */
	SPI_WAIT(SPIx);

	for (i = 0; i < count; i++) {
		/* Fill output buffer with data */
		//SPIx->DR = dataOut[i];
		SPI_SendData8(SPIx, dataOut[i]);

		/* Wait for SPI to end everything */
		SPI_WAIT(SPIx);

		/* Read data register */
		//(void)SPIx->DR;
		SPI_ReceiveData8(SPIx);
	}
}
Esempio n. 11
0
void SPI_ReadMulti(SPI_TypeDef* SPIx, uint8_t* dataIn, uint8_t dummy, uint32_t count) {
	uint32_t i;

	/* Check if SPI is enabled */
	SPI_CHECK_ENABLED(SPIx);

	/* Wait for previous transmissions to complete if DMA TX enabled for SPI */
	SPI_WAIT(SPIx);

	for (i = 0; i < count; i++) {
		/* Fill output buffer with data */
		//SPIx->DR = dummy;
		SPI_SendData8(SPIx, dummy);

		/* Wait for SPI to end everything */
		SPI_WAIT(SPIx);

		/* Save data to buffer */
		//dataIn[i] = SPIx->DR;
		dataIn[i] = SPI_ReceiveData8(SPIx);
	}
}
Esempio n. 12
0
void TM_SPI_ReadMulti(SPI_TypeDef* SPIx, uint8_t* dataIn, uint8_t dummy, uint32_t count) {
	uint32_t i;

	/* Check if SPI is enabled */
	if (!((SPIx)->CR1 & SPI_CR1_SPE)) {
			return;
	}

	/* Wait for previous transmissions to complete if DMA TX enabled for SPI */
	SPI_WAIT(SPIx);

	for (i = 0; i < count; i++) {
		/* Fill output buffer with data */
		SPIx->DR = dummy;

		/* Wait for SPI to end everything */
		SPI_WAIT(SPIx);

		/* Save data to buffer */
		dataIn[i] = SPIx->DR;
	}
}
Esempio n. 13
0
void TM_SPI_WriteMulti(SPI_TypeDef* SPIx, uint8_t* dataOut, uint32_t count) {
	uint32_t i;

	/* Check if SPI is enabled */
	if (!((SPIx)->CR1 & SPI_CR1_SPE)) {
			return;
	}

	/* Wait for previous transmissions to complete if DMA TX enabled for SPI */
	SPI_WAIT(SPIx);

	for (i = 0; i < count; i++) {
		/* Fill output buffer with data */
		SPIx->DR = dataOut[i];

		/* Wait for SPI to end everything */
		SPI_WAIT(SPIx);

		/* Read data register */
		(void)SPIx->DR;
	}
}
Esempio n. 14
0
uint8_t SPI_Write_Byte(uint8_t byte)
{
    SPDR = byte;
    SPI_WAIT();
    return SPDR;
}
Esempio n. 15
0
static uint8_t max1168_xfer_byte(uint8_t tx)
{
    SPDR = tx;
    SPI_WAIT();
    return SPDR;
}