Esempio n. 1
0
//*****************************************************************************
//
//! \internal
//!
//! Write a sequence of command bytes to the SSD1329 controller.
//!
//! The data is written in a polled fashion; this function will not return
//! until the entire byte sequence has been written to the controller.
//!
//! \return None.
//
//*****************************************************************************
static void
RITWriteCommand(const unsigned char *pucBuffer, unsigned long ulCount)
{
    //
    // Return if SSI port is not enabled for RIT display.
    //
    if(!HWREGBITW(&g_ulSSIFlags, FLAG_SSI_ENABLED))
    {
        return;
    }

    //
    // See if data mode is enabled.
    //
    if(HWREGBITW(&g_ulSSIFlags, FLAG_DC_HIGH))
    {
        //
        // Wait until the SSI is not busy, meaning that all previous data has
        // been transmitted.
        //
        while(SSIBusy(SSI0_BASE))
        {
        }

        //
        // Clear the command/control bit to enable command mode.
        //
        GPIOPinWrite(GPIO_OLEDDC_BASE, GPIO_OLEDDC_PIN, 0);
        HWREGBITW(&g_ulSSIFlags, FLAG_DC_HIGH) = 0;
    }

    //
    // Loop while there are more bytes left to be transferred.
    //
    while(ulCount != 0)
    {
        //
        // Write the next byte to the controller.
        //
        SSIDataPut(SSI0_BASE, *pucBuffer++);

        //
        // Decrement the BYTE counter.
        //
        ulCount--;
    }
}
Esempio n. 2
0
//*****************************************************************************
//
// Internal helper function used by all the functions that need to send bytes.
//
//*****************************************************************************
void
SSITRF79x0DummyWrite(unsigned char const *pucBuffer, unsigned int uiLength)
{
    uint32_t ulDummyData;

    while(uiLength > 0) {
        //
        // Write address/command/data and clear SSI register of dummy data.
        //
        SSIDataPut(TRF79X0_SSI_BASE, (unsigned long)*pucBuffer);
        SSIDataGet(TRF79X0_SSI_BASE, &ulDummyData);

        //
        // Post increment counters.
        //
        pucBuffer++;
        uiLength--;
    }
}
Esempio n. 3
0
uint32_t Spi::writeByte(uint8_t* buffer, uint32_t length)
{
    uint32_t data;

    for (uint32_t i = 0; i < length; i++)
    {
        // Push a byte
        SSIDataPut(config_.base, *buffer++);

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

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

    return 0;
}
Esempio n. 4
0
/* Read one character from SPI */
void 
spi_read(unsigned char *rxData)
{
  uint32_t ui32sendData=0x00000000;
  uint32_t ui32dummyData;
  // Wait until SSI0 is done transferring all the data in the transmit FIFO.
  //
  while(SSIBusy(SSI_BASE))
  {
  }
  //
  // Send the data using the "blocking" put function.  This function
  // will wait until there is room in the send FIFO before returning.
  // This allows you to assure that all the data you send makes it into
  // the send FIFO.
  //
  SSIDataPut(SSI_BASE, ui32sendData);
  while(!((HWREG(SSI_BASE + SSI_O_SR) & SSI_SR_TFE) && ((HWREG(SSI_BASE + SSI_O_SR) & SSI_SR_RNE))));
  //
  // Wait until SSI0 is done transferring all the data in the transmit FIFO.
  // Wait for TX ready
  while(SSIBusy(SSI_BASE))
  {
  }
  //
  // Receive the data using the "blocking" Get function. This function
  // will wait until there is data in the receive FIFO before returning.
  //
  SSIDataGet(SSI_BASE, &ui32sendData);//Need to check with Jonas??????????
  while(SSIBusy(SSI_BASE))
  {
  }

  while(SSIDataGetNonBlocking(SSI_BASE, &ui32dummyData))
  {
  }
  // Since we are using 8-bit data, mask off the MSB.
  //
  ui32sendData &= 0x00FF;
  // transfer to unsigned char
  *rxData = (unsigned char)ui32sendData;
  //printf("spi_read: %d\n",*rxData);
}
// --------------------------------------------------------------------------------------
// SB_ServoSet
// Set 12 Servo positions
// --------------------------------------------------------------------------------------
void SB_ServoSet (ui8 slaveMask, ui8 *positions, ui8 servoOffset, ui8 servoCnt )
{
ui32 tempLong = 0;
ui16 *tempShort ;

	// TODO : Finish this function
	// CS the Slave
	SB_CS_Select( slaveMask );

	SSIDataPutNonBlocking(SSI0_BASE, (ui16)('#'<<8 | SB_SERVO_MOVE));
	SSIDataPutNonBlocking(SSI0_BASE, (ui16)(servoOffset<<8 | servoCnt));
	tempShort = (ui16 *)positions;

	/*
	for (i=0; i<servoCnt; i++)
	{
		SSIDataPut(SSI0_BASE, tempShort[i]);
	}
	*/

	SSIDataPutNonBlocking(SSI0_BASE, tempShort[0]);
	SSIDataPutNonBlocking(SSI0_BASE, tempShort[1]);
	SSIDataPutNonBlocking(SSI0_BASE, tempShort[2]);
	SSIDataPutNonBlocking(SSI0_BASE, tempShort[3]);
	SSIDataPutNonBlocking(SSI0_BASE, tempShort[4]);
	SSIDataPut(SSI0_BASE, tempShort[5]);

	// Make sure it's all sent
	while ( SSIBusy(SSI0_BASE) )
	{
		// TODO : Time out
	}

	// Clear data read in
	while(SSIDataGetNonBlocking(SSI0_BASE, &tempLong))
	{

	}

	// De-select the Slave
	SB_CS_DeSelect( slaveMask );
}
Esempio n. 6
0
uint32_t Spi::readByte(uint8_t* buffer, uint32_t length)
{
    uint32_t data;

    for (uint32_t i =  0; i < length; i++)
    {
        // Push a byte
        SSIDataPut(base_, 0x00);

        // Wait until it is complete
        while(SSIBusy(base_))
            ;

        // Read a byte
        SSIDataGet(base_, &data);

        *buffer++ = (uint8_t) data;
    }
    return 0;
}
Esempio n. 7
0
//*****************************************************************************
//
//! \internal
//!
//! Write a sequence of data bytes to the SSD1329 controller.
//!
//! The data is written in a polled fashion; this function will not return
//! until the entire byte sequence has been written to the controller.
//!
//! \return None.
//
//*****************************************************************************
static void
RITWriteData(const unsigned char *pucBuffer, unsigned long ulCount)
{
    unsigned long ulTemp;

    //
    // Return if SSI port is not enabled for RIT display.
    //
    if(!g_bSSIEnabled)
    {
        return;
    }

    //
    // Set the command/control bit to enable data mode.
    //
    GPIOPinWrite(ulGPIOBase, ulOLEDDC_PIN, ulOLEDDC_PIN);

    //
    // Loop while there are more bytes left to be transferred.
    //
    while(ulCount != 0)
    {
        //
        // Write the next byte to the controller.
        //
        SSIDataPut(SSI0_BASE, *pucBuffer++);

        //
        // Dummy read to drain the fifo and time the GPIO signal.
        //
        SSIDataGet(SSI0_BASE, &ulTemp);

        //
        // Decrement the BYTE counter.
        //
        ulCount--;
    }
}
Esempio n. 8
0
//*****************************************************************************
//
//! \internal
//!
//! Write a sequence of command bytes to the SSD0323 controller.
//!
//! The data is written in a polled fashion; this function will not return
//! until the entire byte sequence has been written to the controller.
//!
//! \return None.
//
//*****************************************************************************
static void
OSRAMWriteCommand(const unsigned char *pucBuffer, unsigned long ulCount)
{
    unsigned long ulTemp;

    //
    // Return iff SSI port is not enabled for OSRAM.
    //
    if(!g_bSSIEnabled)
    {
        return;
    }

    //
    // Clear the command/control bit to enable command mode.
    //
    GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_7, 0);

    //
    // Loop while there are more bytes left to be transferred.
    //
    while(ulCount != 0)
    {
        //
        // Write the next byte to the controller.
        //
        SSIDataPut(SSI0_BASE, *pucBuffer++);

        //
        // Dummy read to drain the fifo and time the GPIO signal.
        //
        SSIDataGet(SSI0_BASE, &ulTemp);

        //
        // Decrement the BYTE counter.
        //
        ulCount--;
    }
}
Esempio n. 9
0
/* Write one character to SPI */
void 
spi_write(unsigned char txData)
{
  uint32_t ui32sendData=0x00000000;
  uint32_t ui32dummyData;
  ui32sendData += txData;
  //
  // Wait until SSI0 is done transferring all the data in the transmit FIFO.
  //
  while(SSIBusy(SSI_BASE))
  {
  }
  //
  // Send the data using the "blocking" put function.  This function
  // will wait until there is room in the send FIFO before returning.
  // This allows you to assure that all the data you send makes it into
  // the send FIFO.
  //
  SSIDataPut(SSI_BASE, ui32sendData);
  //
  // Wait until SSI0 is done transferring all the data in the transmit FIFO.
  // Wait for TX ready
  while(SSIBusy(SSI_BASE))
  {
  }
  //
  // 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(SSI_BASE, &ui32dummyData))
  {
  }
}
Esempio n. 10
0
void init8209(void)
{
    unsigned char i = 0;
    unsigned char j = 0;
 
    printf ( "\r\nRN8209 init..." );
    
    while(initTable[i].Bwidth)
    {
    	//有时写第一通道有问题
		spiWrite(0, initTable[0].add,*(initTable[0].value), initTable[0].Bwidth);
        for(j=0;j<9;j++)
        {
            spiWrite(j, initTable[i].add,*(initTable[i].value+j), initTable[i].Bwidth);
            //data = *(WORD *)&SysParam[SP_RNHFCONST+j*2];
            //spiWrite(j, initTable[i].add,data, initTable[i].Bwidth);
        }
        
        i++;
    }
    for(j=0;j<9;j++)
    {
        while(SSIBusy(SSI0_BASE))
        {
            ;
        }
    
        channelSelect(j);
        SSIDataPut(SSI0_BASE, 0xEA);
        SSIDataPut(SSI0_BASE, 0xE5);
    
        SSIDataPut(SSI0_BASE, 0xEA);
        SSIDataPut(SSI0_BASE, 0x5A);//选择A通道电流用着电能计算
        //SSIDataPut(SSI0_BASE, 0xA5);//选择B通道的电流用着电能计算
    
        SSIDataPut(SSI0_BASE, 0xEA);
        SSIDataPut(SSI0_BASE, 0xDC);
    }
    
}
Esempio n. 11
0
//*****************************************************************************
//
// Configure SSI0 in master Freescale (SPI) mode.  This example will send out
// 3 bytes of data, then wait for 3 bytes of data to come in.  This will all be
// done using the polling method.
//
//*****************************************************************************
int
main(void)
{
    unsigned long ulDataTx[NUM_SSI_DATA];
    unsigned long ulDataRx[NUM_SSI_DATA];
    unsigned long ulindex;

    //
    // Set the clocking to run directly from the external crystal/oscillator.
    // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
    // crystal on your board.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_16MHZ);

    //
    // Set up the serial console to use for displaying messages.  This is
    // just for this example program and is not needed for SSI operation.
    //
    InitConsole();

    //
    // Display the setup on the console.
    //
    UARTprintf("SSI ->\n");
    UARTprintf("  Mode: SPI\n");
    UARTprintf("  Data: 8-bit\n\n");

    //
    // The SSI0 peripheral must be enabled for use.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);

    //
    // For this example SSI0 is used with PortA[5:2].  The actual port and pins
    // used may be different on your part, consult the data sheet for more
    // information.  GPIO port A needs to be enabled so these pins can be used.
    // TODO: change this to whichever GPIO port you are using.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    //
    // Configure the pin muxing for SSI0 functions on port A2, A3, A4, and A5.
    // This step is not necessary if your part does not support pin muxing.
    // TODO: change this to select the port/pin you are using.
    //
    GPIOPinConfigure(GPIO_PA2_SSI0CLK);
    GPIOPinConfigure(GPIO_PA3_SSI0FSS);
    GPIOPinConfigure(GPIO_PA4_SSI0RX);
    GPIOPinConfigure(GPIO_PA5_SSI0TX);

    //
    // Configure the GPIO settings for the SSI pins.  This function also gives
    // control of these pins to the SSI hardware.  Consult the data sheet to
    // see which functions are allocated per pin.
    // The pins are assigned as follows:
    //      PA5 - SSI0Tx
    //      PA4 - SSI0Rx
    //      PA3 - SSI0Fss
    //      PA2 - SSI0CLK
    // TODO: change this to select the port/pin you are using.
    //
    GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3 |
                   GPIO_PIN_2);

    //
    // Configure and enable the SSI port for SPI master mode.  Use SSI0,
    // system clock supply, idle clock level low and active low clock in
    // freescale SPI mode, master mode, 1MHz SSI frequency, and 8-bit data.
    // For SPI mode, you can set the polarity of the SSI clock when the SSI
    // unit is idle.  You can also configure what clock edge you want to
    // capture data on.  Please reference the datasheet for more information on
    // the different SPI modes.
    //
    SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0,
                       SSI_MODE_MASTER, 1000000, 8);

    //
    // Enable the SSI0 module.
    //
    SSIEnable(SSI0_BASE);

    //
    // 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, &ulDataRx[0]))
    {
    }

    //
    // Initialize the data to send.
    //
    ulDataTx[0] = 's';
    ulDataTx[1] = 'p';
    ulDataTx[2] = 'i';

    //
    // Display indication that the SSI is transmitting data.
    //
    UARTprintf("Sent:\n  ");

    //
    // Send 3 bytes of data.
    //
    for(ulindex = 0; ulindex < NUM_SSI_DATA; ulindex++)
    {
        //
        // Display the data that SSI is transferring.
        //
        UARTprintf("'%c' ", ulDataTx[ulindex]);

        //
        // Send the data using the "blocking" put function.  This function
        // will wait until there is room in the send FIFO before returning.
        // This allows you to assure that all the data you send makes it into
        // the send FIFO.
        //
        SSIDataPut(SSI0_BASE, ulDataTx[ulindex]);
    }

    //
    // Wait until SSI0 is done transferring all the data in the transmit FIFO.
    //
    while(SSIBusy(SSI0_BASE))
    {
    }

    //
    // Display indication that the SSI is receiving data.
    //
    UARTprintf("\nReceived:\n  ");

    //
    // Receive 3 bytes of data.
    //
    for(ulindex = 0; ulindex < NUM_SSI_DATA; ulindex++)
    {
        //
        // Receive the data using the "blocking" Get function. This function
        // will wait until there is data in the receive FIFO before returning.
        //
        SSIDataGet(SSI0_BASE, &ulDataRx[ulindex]);

        //
        // Since we are using 8-bit data, mask off the MSB.
        //
        ulDataRx[ulindex] &= 0x00FF;

        //
        // Display the data that SSI0 received.
        //
        UARTprintf("'%c' ", ulDataRx[ulindex]);
    }

    //
    // Return no errors
    //
    return(0);
}
Esempio n. 12
0
/**************************************************************************************************
*Function void SPI0_Write(char)
* -------------------------------------------------------------------------------------------------
* Overview: Function send one byte of data to SPI0 
* Input:  data to send
* Output: Nothing
**************************************************************************************************/
void SPI0_Write(char data)
{
	unsigned long temp_result;
	SSIDataPut(SSI0_BASE, data);
	SSIDataGet(SSI0_BASE, &temp_result);
}
Esempio n. 13
0
File: main.c Progetto: conjam/apa102
void main(void) {
	uint32_t color = 0;
	uint32_t CORD_INDEX;
	uint32_t BRIT = 0xFF000000;
	uint32_t BLU = 0x00FF0000;
	uint32_t GREE =0x0000FF00;
	uint32_t RED = 0x000000FF;


	// We set the system clock to 16 mHZ
	SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_16MHZ);
	// enable the SSIO module with this function
	// we must also enable GPIO module A, because the SSIO module uses pins A2-A5
	SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);


	// Sets the GPIO pins up, due to the fact they're mux'd
	GPIOPinConfigure(GPIO_PA2_SSI0CLK);
	GPIOPinConfigure(GPIO_PA3_SSI0FSS);
	GPIOPinConfigure(GPIO_PA4_SSI0RX);
	GPIOPinConfigure(GPIO_PA5_SSI0TX);

	//Sets up pins 5, 4, 3, 2 in
	GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3 |
                   GPIO_PIN_2);

	// Sets up the SSIO systemcount
	// SSI_FRF_MOTO_MODE_0 is chosen, apposed to any other mode, because in the apa102, data is read
	// on the rising edge, and propegated on the falling edge.
	// This means that data is "loaded" into the register on a rising edge, and set off through the SSI
	// on a falling edge I think.
	SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0,
                       SSI_MODE_MASTER, 1000000, 16);

	SSIEnable(SSI0_BASE);

	SSIDataPut(SSI0_BASE, 0);
	while(SSIBusy(SSI0_BASE)) {}
	SSIDataPut(SSI0_BASE, 0);
	while(SSIBusy(SSI0_BASE)) {}

	for(CORD_INDEX = 0; CORD_INDEX < 120; ++CORD_INDEX){
		if(CORD_INDEX % 2 == 0)
			color |= BRIT;
		switch(CORD_INDEX % 6){
			case(0):
				color |= BLU;
				break;
			case(3):
				color |= GREE;
				break;
			case(5):
				color |= RED;
				break;
			default:
				break;
		}
		SSIDataPut(SSI0_BASE, color);
		//wait for things to finish
		while(SSIBusy(SSI0_BASE)) {}
		if(CORD_INDEX % 2 == 1)
			color = 0;
	}
	for(CORD_INDEX = 0; CORD_INDEX < 2; CORD_INDEX++){
		SSIDataPut(SSI0_BASE, 0);
		while(SSIBusy(SSI0_BASE)) {}
	}
	SSIDisable(SSI0_BASE);
	return;
}
Esempio n. 14
0
spi_data_type platform_spi_send_recv( unsigned id, spi_data_type data )
{
  SSIDataPut( spi_base[ id ], data );
  SSIDataGet( spi_base[ id ], &data );
  return data;
}
Esempio n. 15
0
File: Sensor.c Progetto: yguo89/RTOS
// *************** Sensor_WriteSPI *************** 
int Sensor_WriteSPI( PORT_T *port, unsigned char data )
{
    SSIDataPut(SENSOR_SSI_BASE, data);
	return SENSOR_SUCCESS;
}
// --------------------------------------------------------------------------------------
// SB_Scan
// Internal Function, used to scan the SPI bus for Bridges
// --------------------------------------------------------------------------------------
static void SB_Scan ( bool getResponse )
{
ui32 tempLong = 0;
ui8 i = 0;

	if (! getResponse )
	{
		// CS them all!!
		SB_CS_Select( SB_SPI_SLAVE0 | SB_SPI_SLAVE1 | SB_SPI_SLAVE2 | SB_SPI_SLAVE3 | SB_SPI_SLAVE4 );

		SSIDataPut(SSI0_BASE, (ui16)('#'<<8 | SB_WHOS_THERE));

		//while ( SSIBusy(SSI0_BASE) )
		//{
			// TODO : Time out
		//}

		// Clear data read in
		//while(SSIDataGetNonBlocking(SSI0_BASE, &tempLong))
		//{

		//}

		//SB_CS_DeSelect(SB_SPI_CS_PINS);

		SB_Scanning = true;
	}
	else
	{
		SB_CS_DeSelect(SB_SPI_CS_PINS);

		// Clear any data read in
		while(SSIDataGetNonBlocking(SSI0_BASE, &tempLong))
		{

		}

		for (i=0; i<SB_SPI_CS_COUNT; i++)
		{
			SB_CS_Select( 0x01 << i );
			// Clock out zeros
			SSIDataPut(SSI0_BASE, (ui16)0x0000);

			while ( SSIBusy(SSI0_BASE) )
			{
				// TODO : Time out
			}

			// Read the data read in
			SSIDataGetNonBlocking(SSI0_BASE, &tempLong);

			SolderBridgeList[i] = (ui8)(tempLong >> 8);
			SolderBridgeListVer[i] = (ui8)(0x00FF & tempLong);

			SB_CS_DeSelect(SB_SPI_CS_PINS);
		}

		SB_Scanning = false;
	}

}
Esempio n. 17
0
//SSI0传输数据
void SSI0_Write(uint16_t data)
{
		while(SSIBusy(SSI0_BASE));
		SSIDataPut(SSI0_BASE, data);
}
Esempio n. 18
0
void PUT(unsigned char data)
{
	SSIDataPut(SSI1_BASE, data);
	while(SSIBusy(SSI1_BASE)) {};
}
Esempio n. 19
0
void vs_ssi_write(unsigned char c)
{
  SSIDataPut(SSI1_BASE, c);

  return;
}
Esempio n. 20
0
void Zone_Disable(void)
{
    while(SSIBusy(SSI0_BASE)) {}

    SSIDataPut(SSI0_BASE, ZONE_NONE);
}
Esempio n. 21
0
//--------------------------------
void ssi_peripheral::Put(uint32_t nValue) {
	SSIDataPut(m_rSpecification.m_nSSIBase, nValue);
}
Esempio n. 22
0
void
spi_Tx_TestDebug(void)
{
   uint32_t ui32Index=0x00000018; 
   SSIDataPut(SSI_BASE, ui32Index);
}