Exemplo n.º 1
0
/*
 * @brief Writes data into the specified accelerometer register.
 *
 * @param addr specifies where the register is
 * @param data to be written into the register
 * @returns void
 */
void accelerometer_write_register(uint8 addr, uint8 data) {
	uint32 buffer;
	SPISelectDevice(SPI_ACCELEROMETER);
	MAP_SSIDataPut(SSI0_BASE, ACCEL_WRITE_BIT | (addr & 0x3F));
	MAP_SSIDataGet(SSI0_BASE, &buffer);
	MAP_SSIDataPut(SSI0_BASE, data);
	MAP_SSIDataGet(SSI0_BASE, &buffer);
	SPIDeselect();
}
Exemplo n.º 2
0
/*
 * @brief Reads the accelerometer register from the specified address.
 *
 * @param addr specifies where the register is
 * @returns the data contained in the register
 */
uint8 accelerometer_read_register(uint8 addr) {
	uint32 buffer;
	SPISelectDevice(SPI_ACCELEROMETER);
	MAP_SSIDataPut(SSI0_BASE, ACCEL_READ_BIT | (addr & 0x3F));
	MAP_SSIDataGet(SSI0_BASE, &buffer);
	MAP_SSIDataPut(SSI0_BASE, 0x00);//dummy read
	MAP_SSIDataGet(SSI0_BASE, &buffer);
	SPIDeselect();
	return (uint8) buffer;
}
Exemplo n.º 3
0
//*****************************************************************************
//
// Internal helper function that sends a buffer of data to the TRF79x0, used
// by all the functions that need to send bytes.
//
//*****************************************************************************
void
SSITRF79x0GenericWrite(unsigned char const *pucBuffer, unsigned int uiLength)
{
    uint32_t ulDummyData;

    while(uiLength > 0)
    {
        //
        // Write address/command/data and clear SSI register of dummy data.
        //
        MAP_SSIDataPut(TRF79X0_SSI_BASE, (unsigned long)*pucBuffer);
        //
        // Wait until the SSI Module is completed sending uiLength bytes to the SSI module.
        //
        while(SSIBusy(TRF79X0_SSI_BASE) == true);
        MAP_SSIDataGet(TRF79X0_SSI_BASE, &ulDummyData);

        //
        // Post increment counters.
        //
        pucBuffer++;
        uiLength--;
    }


}
Exemplo n.º 4
0
//*****************************************************************************
//
// Internal helper function that receives a buffer of data from the TRF79x0,
// used by all the functions that need to read bytes.
//
//*****************************************************************************
static void
SSITRF79x0GenericRead(unsigned char *pucBuffer, unsigned int uiLength)
{
    uint32_t ulData;

    while(uiLength > 0)
    {
        //
        // Write dummy data for SSI clock and read data from SSI register.
        //
        MAP_SSIDataPut(TRF79X0_SSI_BASE, (unsigned long)SSI_NO_DATA);
        //
        // Wait until the SSI Module is completed sending uiLength bytes to the SSI module.
        //
        while(SSIBusy(TRF79X0_SSI_BASE) == true);
        MAP_SSIDataGet(TRF79X0_SSI_BASE, &ulData);
//        SSIDataGet(TRF79X0_SSI_BASE, &ulData);

        //
        // Read data into buffers and post increment counters.
        //
        *pucBuffer++ = (unsigned char)ulData;

        uiLength--;
    }

}
Exemplo n.º 5
0
inline uint16_t enc28_SPISend(uint16_t ui16_rw) {
  uint32_t ui32_rx_val;
  MAP_SSIDataPut(ui32_SSIx, ui16_rw);
  while(MAP_SSIBusy(SSI0_BASE));
  MAP_SSIDataGet(ui32_SSIx, &ui32_rx_val);
  return (uint16_t)ui32_rx_val;
}
Exemplo n.º 6
0
Arquivo: rfid.c Projeto: mukris/rfid
uint8_t spiTransfer(uint8_t data)
{
	uint32_t ret;
	MAP_SSIDataPut(SSI2_BASE, data);
	MAP_SSIDataGet(SSI2_BASE, &ret);
	return (uint8_t) (ret & 0xFF);
}
uint8_t spi_transferByte(uint8_t data){


	unsigned long rxdata;
	MAP_SSIDataPut(SSI0_BASE,data);
	MAP_SSIDataGet(SSI0_BASE,&rxdata);

	return (rxdata&0xFF);
}
Exemplo n.º 8
0
/*
 * private function
 */
int32 accelerometer_read_register_16(uint8 addr) {
	uint32 data_low;
	uint32 data_high;
	int32 value;

	SPISelectDevice(SPI_ACCELEROMETER);
	MAP_SSIDataPut(SSI0_BASE, ACCEL_READ_BIT | ACCEL_ADDR_INC_BIT | (addr & 0x3F));
	MAP_SSIDataGet(SSI0_BASE, &data_low);
	MAP_SSIDataPut(SSI0_BASE, 0x00);
	MAP_SSIDataGet(SSI0_BASE, &data_low);
	MAP_SSIDataPut(SSI0_BASE, 0x00);
	MAP_SSIDataGet(SSI0_BASE, &data_high);
	SPIDeselect();

	value = (int32)((int16)((uint16)data_high << 8) | ((uint16)data_low));
	// need to manually sign extend because this stupid complier does not
	if (value & 0x8000) {
		value |= 0xFFFF0000;
	}
	return value;
}
Exemplo n.º 9
0
/*
 * @brief Cancels all selections. Then immediately sends a byte of 0xFF.
 *
 * Makes all SPI devices inactive. Then immediately sends a byte of 0xFF.
 * @returns void
 */
void SPIDeselectSynchronous(void) {
    // do the actual deselect
    SPIDeselectISR();

    //Send a 0xFF byte
    //Load up the data and send it
    uint32 rcvdat;
    MAP_SSIDataPut(SSI0_BASE, 0xFF); /* Write the data to the tx fifo */
    MAP_SSIDataGet(SSI0_BASE, &rcvdat); /* flush data read during the write */

    // wait until the last transfer is finished
    volatile uint16 i = 0;

    while (MAP_SSIBusy(SSI0_BASE)) {
        i++;
        if (i > SPI_MAX_XFER_IRQ_DELAY) {
            return;
        }
    }
}
Exemplo n.º 10
0
uint8_t spi_send(uint8_t c) {
  unsigned long val;
  MAP_SSIDataPut(SSI2_BASE, c);
  MAP_SSIDataGet(SSI2_BASE, &val);
  return (uint8_t)val;
}
Exemplo n.º 11
0
spi_data_type platform_spi_send_recv( unsigned id, spi_data_type data )
{
    MAP_SSIDataPut( spi_base[ id ], data );
    MAP_SSIDataGet( spi_base[ id ], &data );
    return data;
}