Ejemplo n.º 1
0
/**
 * Configures the temperature sensor for continuous read mode and reads the
 *  status register
 *  Utilizes SSI0
 *
 *  \param statusreg - A pointer to store the status information that is read
 **/
void temp_configSensorContinuousRead(uint32_t *statusreg) {
	uint32_t commandWriteConfigReg  = 0x00000C01;
	uint32_t commandReadStatusReg   = 0x00000040; // 0b01000000
	uint32_t commandReadStatusEmpty = 0x00000000;
	uint32_t trashBin[2];

	// Setup Configuration Register (register address: 0x01
	SSIDataPut(SSI0_BASE, commandWriteConfigReg);
	SSIDataPut(SSI0_BASE, commandReadStatusEmpty);
	// SysCtlDelay(4170000); // (3 cycles/loop) * (1/50MHz) * (4170000 loop cycles) = 250.2ms

	// Read any residual data from the SSI port.  This makes sure the receive
	// FIFOs are empty, so we don't read any unwanted junk.  This is done here
	// because the SPI SSI mode is full-duplex, which allows you to send and
	// receive at the same time.  The SSIDataGetNonBlocking function returns
	// "true" when data was returned, and "false" when no data was returned.
	// The "non-blocking" function checks if there is any data in the receive
	// FIFO and does not "hang" if there isn't.
	while(SSIDataGetNonBlocking(SSI0_BASE, &trashBin[0]))
	{
	}

	// Read status register (Address: 0x0)
	SSIDataPut(SSI0_BASE, commandReadStatusReg);
	SSIDataGet(SSI0_BASE, &trashBin[1]);
	SSIDataPut(SSI0_BASE, commandReadStatusEmpty);
	SSIDataGet(SSI0_BASE, statusreg);

	//Need to adjust for different processor frequencies
	SysCtlDelay(4170000); // (3 cycles/loop) * (1/50MHz) * (4170000 loop cycles) = 250.2ms
}
Ejemplo n.º 2
0
//*****************************************************************************
//
//! Write a PDC register.
//!
//! \param ucAddr specifies the PDC register to write.
//! \param ucData specifies the data to write.
//!
//! This function will perform the SSI transfers required to write a register
//! in the PDC on the Stellaris development board.
//!
//! This function is contained in <tt>utils/pdc.c</tt>, with
//! <tt>utils/pdc.h</tt> containing the API definition for use by applications.
//!
//! \return None.
//
//*****************************************************************************
void
PDCWrite(unsigned char ucAddr, unsigned char ucData)
{
    unsigned long ulTemp;

    //
    // Send address and write command.
    //
    SSIDataPut(SSI_BASE, (ucAddr & 0x0F) | PDC_WR);

    //
    // Write the data.
    //
    SSIDataPut(SSI_BASE, ucData);

    //
    // Flush data read during address write.
    //
    SSIDataGet(SSI_BASE, &ulTemp);

    //
    // Flush data read during data write.
    //
    SSIDataGet(SSI_BASE, &ulTemp);
}
Ejemplo n.º 3
0
//SSI0接收数据
uint16_t SSI0_Read(void)
{
		uint32_t dataTmp=0;
		while(SSIBusy(SSI0_BASE));
		SSIDataGet(SSI0_BASE, &dataTmp);
		//SSIDataPut(SSI0_BASE,0x00);
		SSIDataGet(SSI0_BASE, &dataTmp);
		return (uint16_t)dataTmp;
}
Ejemplo n.º 4
0
int main(void)
{
	setup();

	UART_TX_string("XCVR RX:\n\r");

	cc112x_manualReset(GPIO_PORTA_BASE, GPIO_PIN_6);

    	cc112x_write_regs(1, cc112x_regSettings, sizeof(cc112x_regSettings) / (2 * sizeof(uint16_t)));

	SSIDataPut(SSI0_BASE, CC112X_SRX);
	while(SSIBusy(SSI0_BASE));

	_DELAY_MS(1000);

    while(1)
    {

    	SSIDataPut(SSI0_BASE, (uint8_t)((CC112X_NUM_RXBYTES & 0xFF00) >> 8));
    	SSIDataPut(SSI0_BASE, (uint8_t)(CC112X_NUM_RXBYTES & 0x00FF));
    	while(SSIBusy(SSI0_BASE));

    	uint32_t recieved;
    	while(SSIDataGetNonBlocking(SSI0_BASE, &recieved));

    	SSIDataPut(SSI0_BASE, CC112X_SNOP);
    	while(SSIBusy(SSI0_BASE));
    	SSIDataGet(SSI0_BASE, &recieved);

    	char tmp2[100];
    	sprintf(tmp2, "\r\nbytes in rx fifo: %i\r\n", recieved);
    	UART_TX_string(tmp2);

    	int num_bytes = recieved;
    	int i;
    	for(i = 0; i < num_bytes; i++)
    	{
    		recieved = 0;
    		SSIDataPut(SSI0_BASE, CC112X_SINGLE_RXFIFO);
        	while(SSIDataGetNonBlocking(SSI0_BASE, &recieved));
        	SSIDataPut(SSI0_BASE, CC112X_SNOP);
        	SSIDataGet(SSI0_BASE, &recieved);

        	char tmp[10];
        	sprintf(tmp, "%i\r\n", recieved);
        	UART_TX_string(tmp);
    	}
    }
}
Ejemplo n.º 5
0
void
OrbitOledPutBuffer(int cb, char * rgbTx)
	{
	int				ib;
	uint32_t	bTmp;

	/* Bring the slave select line low
	*/
	GPIOPinWrite(nCS_OLEDPort, nCS_OLED, LOW);

	/* Write/Read the data
	*/
	for (ib = 0; ib < cb; ib++) {
		/* Wait for transmitter to be ready
		*/
		while (SSIBusy(SSI3_BASE));

		/* Write the next transmit byte.
		*/
		SSIDataPut(SSI3_BASE, (unsigned int)*rgbTx++);

		/* Wait for receive byte.
		*/
		while (SSIBusy(SSI3_BASE));
		SSIDataGet(SSI3_BASE, &bTmp);

	}

	/* Bring the slave select line high
	*/
	GPIOPinWrite(nCS_OLEDPort, nCS_OLED, nCS_OLED);
	
}
Ejemplo n.º 6
0
/*#####################################################*/
unsigned char _mcspi_SendByte(Mcspi_t *McspiStruct, unsigned char byte)
{
	SSIDataPut(McspiStruct->BaseAddr, byte);
	uint32_t pui32Data;
	SSIDataGet(McspiStruct->BaseAddr, &pui32Data);
	return (unsigned char)pui32Data;
}
Ejemplo n.º 7
0
/**************************************************************************************************
* Function unsigned char SPI0_Read(void)
* -------------------------------------------------------------------------------------------------
* Overview: Function read one byte of data from SPI0 
* Input:  nothing
* Output: data read from SPI
**************************************************************************************************/
unsigned char SPI0_Read(void)
{
	unsigned long temp_result;
	SSIDataPut(SSI0_BASE, 0xff);
	SSIDataGet(SSI0_BASE, &temp_result);
	return (unsigned char)temp_result;
}
Ejemplo n.º 8
0
static uint8_t cc112x_sgl_reg_access(const int xcvr, const bool rw, const uint16_t addr, const uint16_t data)
{
	uint8_t status = 0;

	SSIDataPut(SSI0_BASE, CC112X_SINGLE_REG_ACC(rw, addr));
	while(SSIBusy(SSI0_BASE));
	SSIDataGet(SSI0_BASE, (uint32_t *)&status);
	cc112x_wait_until_ready(xcvr);

	SSIDataPut(SSI0_BASE, data);
	while(SSIBusy(SSI0_BASE));
	SSIDataGet(SSI0_BASE, (uint32_t *)&status);
	cc112x_wait_until_ready(xcvr);

	return status;
}
Ejemplo n.º 9
0
char
Ssi3PutByte(char bVal)
	{
	uint32_t	bRx;

	/* Bring the slave select line low
	*/
	GPIOPinWrite(nCS_OLEDPort, nCS_OLED, LOW);

	/* Wait for transmitter to be ready
	*/
	while (SSIBusy(SSI3_BASE));

	/* Write the next transmit byte.
	*/
	SSIDataPut(SSI3_BASE, (unsigned long)bVal);

	/* Wait for receive byte.
	*/
	while (SSIBusy(SSI3_BASE));

	/* Put the received byte in the buffer.
	*/
	SSIDataGet(SSI3_BASE, &bRx);

	/* Bring the slave select line high
	*/
	GPIOPinWrite(nCS_OLEDPort, nCS_OLED, nCS_OLED);
	
	return (char)bRx;

}
Ejemplo n.º 10
0
static unsigned short xmit_spi (unsigned short dat) {
    unsigned long rcvdat;
    SSIDataPut(UART4_SSI_BASE, dat); /* Write the data to the tx fifo */
    SSIDataGet(UART4_SSI_BASE, &rcvdat); /* flush data read during the write */

    return (unsigned short) rcvdat;
}
Ejemplo n.º 11
0
static uint8_t SPIxfer(int send)
{
    uint32_t result;
    SSIDataPut(SD_BASE_SSI, send);
    SSIDataGet(SD_BASE_SSI, &result);
    return result;
}
Ejemplo n.º 12
0
Archivo: Sensor.c Proyecto: yguo89/RTOS
// *************** Sensor_ReadSPI ***************
int Sensor_ReadSPI( PORT_T *port, unsigned char* data )
{
    unsigned long dataBuff;
    SSIDataGet(SENSOR_SSI_BASE, &dataBuff);
    *data = (unsigned char) dataBuff;
    return SENSOR_SUCCESS;
}
Ejemplo n.º 13
0
/* ------------------------------------------------------------------------------------------------------
 *									CC2520_SPI_TXRX()
 *
 * Description : SPI sysctl init function.
 *
 * Argument(s) : none.
 *
 */
void CC2520_SPI_TX(unsigned char dat)
{
	unsigned long uNull;
	
	SSIDataPut(SSI0_BASE, dat);
	SSIDataGet(SSI0_BASE, &uNull);
}
Ejemplo n.º 14
0
//*****************************************************************************
//
//! Read a PDC register.
//!
//! \param ucAddr specifies the PDC register to read.
//!
//! This function will perform the SSI transfers required to read a register in
//! the PDC on the Stellaris development board.
//!
//! This function is contained in <tt>utils/pdc.c</tt>, with
//! <tt>utils/pdc.h</tt> containing the API definition for use by applications.
//!
//! \return Returns the value read from the PDC.
//
//*****************************************************************************
unsigned char
PDCRead(unsigned char ucAddr)
{
    unsigned long ulTemp;

    //
    // Send address and read command.
    //
    SSIDataPut(SSI_BASE, (ucAddr & 0x0F) | PDC_RD);

    //
    // Dummy write to force read.
    //
    SSIDataPut(SSI_BASE, 0x00);

    //
    // Flush data read during address write.
    //
    SSIDataGet(SSI_BASE, &ulTemp);

    //
    // If the LCD control register or RAM is being read, then an additional
    // byte needs to be transferred.
    //
    if((ucAddr == PDC_LCD_CSR) || (ucAddr == PDC_LCD_RAM))
    {
        //
        // Dummy write to force read.
        //
        SSIDataPut(SSI_BASE, 0x00);

        //
        // Flush read data.
        //
        SSIDataGet(SSI_BASE, &ulTemp);
    }

    //
    // Read valid data.
    //
    SSIDataGet(SSI_BASE, &ulTemp);

    //
    // Return the data read.
    //
    return(ulTemp & 0xFF);
}
Ejemplo n.º 15
0
unsigned char ssi_read(void)
{
  unsigned long r;

  SSIDataGet(SSI0_BASE, &r);

  return (unsigned char)r;
}
Ejemplo n.º 16
0
uint16_t SPIController::writeAndReadBlocking(uint16_t writeData)
{
	uint32_t result;
	SSIDataPut(_base, writeData);
    while(SSIBusy(_base)) {}
    SSIDataGet(_base, &result);
    return result & _read_mask;
}
Ejemplo n.º 17
0
unsigned char tradeByte(unsigned char b) {
    // SSI is configured at 8 bits, so any data pulled in is constrained to the lower 8b
    // Warnings may occur due to casting to unsigned long 
    unsigned char buf = 0;
    SSIDataPut(SPI_BASE, b);
    SSIDataGet(SPI_BASE, &buf);
    return buf; 
}
Ejemplo n.º 18
0
static unsigned short recv_command(unsigned short command) {
    unsigned long rcvdat;

    SSIDataPut(UART4_SSI_BASE, (0x80 | command));
//    SSIDataPut(UART4_SSI_BASE, 0xFF);
    SSIDataGet(UART4_SSI_BASE, &rcvdat); /* flush data read during the write */
    return (unsigned short)rcvdat;
}
Ejemplo n.º 19
0
static unsigned short rcvr_spi (void) {
    unsigned long rcvdat;

//    SSIDataPut(UART4_SSI_BASE, 0xFF); /* write dummy data */
    SSIDataGet(UART4_SSI_BASE, &rcvdat); /* read data frm rx fifo */

    return (unsigned short)rcvdat;
}
Ejemplo n.º 20
0
unsigned char vs_ssi_readwrite(unsigned char c)
{
  unsigned long r;

  SSIDataPut(SSI1_BASE, c);
  SSIDataGet(SSI1_BASE, &r);

  return (unsigned char)r;
}
Ejemplo n.º 21
0
/* ------------------------------------------------------------------------------------------------------
 *									CC2520_SPI_TXRX()
 *
 * Description : SPI sysctl init function.
 *
 * Argument(s) : none.
 *
 */
unsigned char CC2520_SPI_TXRX(unsigned char adr)
{
	unsigned long dat;
	
	SSIDataPut(SSI0_BASE, adr);
	SSIDataGet(SSI0_BASE, &dat);
	
	return (unsigned char) dat;
}
Ejemplo n.º 22
0
/* ------------------------------------------------------------------------------------------------------
 *									CC2520_SPI_RX()
 *
 * Description : SPI sysctl init function.
 *
 * Argument(s) : none.
 *
 */
unsigned char CC2520_SPI_RX(void)
{
	unsigned long dat;
	
	SSIDataPut(SSI0_BASE, 0xFF);
	SSIDataGet(SSI0_BASE, &dat);
	
	return (unsigned char) dat;
}
Ejemplo n.º 23
0
uint8_t cc112x_get_status(const int xcvr)
{
	uint8_t status = 0;

	SSIDataPut(SSI0_BASE, CC112X_SNOP);
	while(SSIBusy(SSI0_BASE));
	SSIDataGet(SSI0_BASE, (uint32_t *)&status);

	return status;
}
Ejemplo n.º 24
0
void Read_ad7705Res(uint32 Register,uint32 *munedata,uint32 size)
{
   uint32 i;
   SSIDataPut(SSI0_BASE,Register);
   for(i=0;i<size;i++)
      {
        SSIDataPut(SSI0_BASE,0x00);
        SSIDataGet(SSI0_BASE,&munedata[i]);
	  }	

}
Ejemplo n.º 25
0
void SPI_receive(uint8_t *data,uint16_t size){
		while(SSIBusy(SSI0_BASE));
		 //TODO: check if compatible uint32_t -->uint8_t
		uint16_t c;
		uint32_t *tempData;
		for(c=0;c<size;c++){
			SSIDataGet(SSI0_BASE,tempData);
			//SSIDataGetNonBlocking(SSI0_BASE,tempData);
			*data = *tempData;
		}

}
Ejemplo n.º 26
0
void Spi::writeByte(uint8_t byte)
{
    uint32_t data;

    // Push a byte
    SSIDataPut(config_.base, byte);

    // Wait until it is complete
    while(SSIBusy(config_.base))
        ;

    // Read a byte
    SSIDataGet(config_.base, &data);
}
Ejemplo n.º 27
0
uint8_t  readStatus(void)
{
	uint32_t tmp;
	GPIOPinWrite(ra8875.base_cs, ra8875.cs, 0);
  //digitalWrite(_cs, LOW);
  /////SPI.transfer(RA8875_CMDREAD);
	mySSIDataPut(ra8875.base_ssi,RA8875_CMDREAD);
	flushSSIFIFO(ra8875.base_ssi);
	mySSIDataPut(ra8875.base_ssi,0);
	SSIDataGet(ra8875.base_ssi, &tmp);
  //uint8_t x = SPI.transfer(0x0);
  //digitalWrite(_cs, HIGH);
	GPIOPinWrite(ra8875.base_cs, ra8875.cs, 0xFF);
  return tmp;
}
Ejemplo n.º 28
0
uint32_t MPU9250_ReadReg(uint32_t address)
{
	uint32_t data;
	while (HWREG(SSI0_BASE + SSI_O_SR) & SSI_SR_RNE)	// clear FIFO
		HWREG(SSI0_BASE + SSI_O_DR);
	GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_7, 0);	// activate CS (low)
	while (SSIBusy(SSI0_BASE)) ;
	SSIDataPut(SSI0_BASE, 0x80 | address);			// send address
    while (SSIBusy(SSI0_BASE)) ;
	HWREG(SSI0_BASE + SSI_O_DR);
    SSIDataPut(SSI0_BASE, 0xFF);					// get the data
    while (SSIBusy(SSI0_BASE)) ;
    SSIDataGet(SSI0_BASE, &data);
	GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_7, GPIO_PIN_7); // deactivate CS (high)
	return data;
}
Ejemplo n.º 29
0
/**
Sends a message over SPI to the Module on USCI_B1.
SPI uses a "write-to-read" approach to read data out, you must write data in.
This is a private method that gets wrapped by other methods, e.g. spiSreq(), spiPoll(), etc.
To Write, set *bytes, numBytes.
To Read, set *bytes only. Don't need to set numBytes because Module will stop when no more bytes read.
@param bytes the data to be sent or received.
@param numBytes the number of bytes to be sent. This same buffer will be overwritten with the received data.
@note Modify this method for other hardware implementations.
@pre SPI port configured for writing
@pre Module has been initialized
@post bytes contains received data, if any
@see Stellaris Application Note spma002.pdf, "Adding 32kB of Serial SRAM to a Stellaris Microcontroller"
*/
void spiWrite(unsigned char *bytes, unsigned char numBytes)
{
    unsigned long ulReadData;
    //SPI_SS_SET();  //assert CS
    //while (SRDY_IS_HIGH()) ;
    while(numBytes--)    // Loop while there are more bytes left to be transferred.
    {
        SSIDataPut(SSI0_BASE, *bytes);              // Write the next byte to the SSI controller with a blocking put.
        SSIDataGet(SSI0_BASE, &ulReadData);         // Read into a long first
        *bytes++ = (unsigned char)ulReadData;       // ...and then convert it to a char
    }

    //while ( (~HWREG(SSI0_BASE + SSI_O_SR)) & SSI_SR_TFE) ;   //wait while Transmit FIFO is NOT empty
    //while ( (HWREG(SSI0_BASE + SSI_O_SR)) & SSI_SR_BSY) ;   //wait while busy   - experimental; works without this!
    //SPI_SS_CLEAR();
}
Ejemplo n.º 30
0
uint8_t Spi::readByte(void)
{
    uint32_t byte;

    // Push a byte
    SSIDataPut(config_.base, 0x00);

    // Wait until it is complete
    while(SSIBusy(config_.base))
        ;

    // Read a byte
    SSIDataGet(config_.base, &byte);

    return (uint8_t)(byte & 0xFF);
}