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); }
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; }
void MPU9250_WriteReg(uint32_t address, uint32_t data) { GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_7, 0); // activate CS (low) while (SSIBusy(SSI0_BASE)) ; SSIDataPut(SSI0_BASE, address); // send address while (SSIBusy(SSI0_BASE)) ; HWREG(SSI0_BASE + SSI_O_DR); SSIDataPut(SSI0_BASE, data); // send the data while (SSIBusy(SSI0_BASE)) ; HWREG(SSI0_BASE + SSI_O_DR); GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_7, GPIO_PIN_7); // deactivate CS (high) }
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); } } }
/* Write one character to SPI - will not wait for end useful for multiple writes with wait after final */ void spi_write_fast(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); // // 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)) { } }
//***************************************************************************** // // 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--; } }
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; }
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; }
//***************************************************************************** // // 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--; } }
int main(void) { uint32_t ui32Index; uint32_t ui32Data; SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinConfigure(GPIO_PA2_SSI0CLK); GPIOPinConfigure(GPIO_PA3_SSI0FSS); GPIOPinConfigure(GPIO_PA5_SSI0TX); GPIOPinTypeSSI(GPIO_PORTA_BASE,GPIO_PIN_5|GPIO_PIN_3|GPIO_PIN_2); SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 10000, 16); SSIEnable(SSI0_BASE); while(1) { for(ui32Index = 0; ui32Index < NUM_SSI_DATA; ui32Index++) { ui32Data = (Reverse(pui8DataTx[ui32Index]) << 8) + (1 << ui32Index); SSIDataPut(SSI0_BASE, ui32Data); while(SSIBusy(SSI0_BASE)) { } } } }
void EEPROM_Write(int addr,unsigned char* pdata,int len) { int i; unsigned long tmp; volatile unsigned char c1; volatile unsigned char c2; volatile unsigned char c3; volatile unsigned char* pd = pdata; c1 = 0x02; // Write command if (addr>0xFF) c1|=8; // address 9th bit c2 = addr; CS_ON(); PUT(0x06);//// Send WREN (Enable Write Operations) CS_OFF(); CS_ON(); while( SSIDataGetNonBlocking(SSI1_BASE, &tmp)) {} ; while(SSIBusy(SSI1_BASE)) {}; PUT(c1); PUT(c2); for(i=0;i<len;i++) { c3 = *(pd+i); PUT(c3); } CS_OFF(); DELAY(); }
void EEPROM_Read(int addr,unsigned char* pdata,int len,unsigned char ischar) { int i=0; volatile unsigned long tmp=0; volatile unsigned char c1=0; volatile unsigned char c2=0; c1 = 0x03; // Read command if (addr>0xFF) c1|=8; // address 9th bit c2 = addr ; CS_ON(); while(SSIBusy(SSI1_BASE)) {}; PUT(c1); PUT(c2); while( SSIDataGetNonBlocking(SSI1_BASE,(unsigned long*) &tmp)) {} ; for(i=0;i<len;i++) { PUT(0x00);//// Send dummy Byte command while(SSIDataGetNonBlocking(SSI1_BASE, (unsigned long*) &tmp))// Fetch data from RX buffer { DELAY(); } if ((ischar) && (tmp==UNINITIALIZED)) tmp = ZERO; *(pdata+i) = tmp; } CS_OFF(); DELAY(); }
void Zone_Init(void) { SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_5); GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_5, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD_WPU); SSIDisable(SSI0_BASE); SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 2000000, 8); GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_3); GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_3, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD_WPU); SSIEnable(SSI0_BASE); while(SSIBusy(SSI0_BASE)) {} SSIDataPut(SSI0_BASE, ZONE_NONE); }
// -------------------------------------------------------------------------------------- // // SB_ServoSet // // -------------------------------------------------------------------------------------- void SB_ZeroToTenOutput (ui8 slaveMask, ui8 *outputLevels ) { ui32 tempLong = 0; // CS the Slave SB_CS_Select( slaveMask ); SSIDataPutNonBlocking(SSI0_BASE, (ui16)('#'<<8 | SB_ZEROTEN_UPDATE)); // Pack the update SSIDataPutNonBlocking(SSI0_BASE, (ui16)(outputLevels[0]<<8 | outputLevels[1])); SSIDataPutNonBlocking(SSI0_BASE, (ui16)(outputLevels[2]<<8 | outputLevels[3])); SSIDataPutNonBlocking(SSI0_BASE, (ui16)(outputLevels[4]<<8 | outputLevels[5])); SSIDataPutNonBlocking(SSI0_BASE, (ui16)(outputLevels[6]<<8 | 0x00)); // Make sure it's all sent while ( SSIBusy(SSI0_BASE) ) { // TODO : Time out } // Clear data read in while(SSIDataGetNonBlocking(SSI0_BASE, &tempLong)) { } // Deselect the Slave SB_CS_DeSelect( slaveMask ); }
uint16_t SPIController::writeAndReadBlocking(uint16_t writeData) { uint32_t result; SSIDataPut(_base, writeData); while(SSIBusy(_base)) {} SSIDataGet(_base, &result); return result & _read_mask; }
static uint8_t spiWriteReadByte(uint8_t val) { uint32_t retVal = 0x00; // ivalid value SSIDataPut(SSI0_BASE, val); while (SSIBusy(SSI0_BASE)) {} while (SSIDataGetNonBlocking(SSI0_BASE, &retVal)); return (uint8_t)retVal; }
void Zone_Enable(int zone) { int val; while(SSIBusy(SSI0_BASE)) {} val = 0x01 << (zone - 1); SSIDataPut(SSI0_BASE, val); }
//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; }
/* 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); }
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; }
// -------------------------------------------------------------------------------------- // SolderBridge_Task // // -------------------------------------------------------------------------------------- void SolderBridge_Task ( void ) { if (SB_Scanning) { if (! SSIBusy(SSI0_BASE) ) { SB_Scan( SB_Scanning ); } } }
/* * Send data to SDI pin - for SSI0 (); * Description: send data on one of the channel of POT. Channel value vary from 0 to 3. Data will be 8-bit value * control here is used to select channel */ void spi_senddata(uint8_t control,uint8_t data) { spidataframe = ((control << 8) | (data)); // GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0); // set CS pin low before sending bit SSIDataPut(SSI0_BASE,spidataframe); while(SSIBusy(SSI0_BASE)) { } delay(4); // 4s // GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,8); // set CS pin HIGH after sending bit }
//***************************************************************************** // //! \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) { OS_bWait(&oLEDFree); // // Return if SSI port is not enabled for RIT display. // if(!HWREGBITW(&g_ulSSIFlags, FLAG_SSI_ENABLED)) { OS_bSignal(&oLEDFree); return; } // // See if command mode is enabled. // if(!HWREGBITW(&g_ulSSIFlags, FLAG_DC_HIGH)) { // // Wait until the SSI is not busy, meaning that all previous commands // have been transmitted. // while(SSIBusy(SSI0_BASE)) { } // // Set the command/control bit to enable data mode. // GPIOPinWrite(GPIO_OLEDDC_BASE, GPIO_OLEDDC_PIN, GPIO_OLEDDC_PIN); HWREGBITW(&g_ulSSIFlags, FLAG_DC_HIGH) = 1; } // // 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--; } OS_bSignal(&oLEDFree); }
//Transfer 8bit each time void SPI_transfer(uint8_t *data,uint16_t size){ uint16_t c; uint32_t cleanSpace = 0x00000000; //cleanSpace = *data; while(SSIBusy(SSI0_BASE)); for(c=0;c<size;c++){ cleanSpace = *(data+c); SSIDataPut(SSI0_BASE,cleanSpace); //SSIDataPutNonBlocking(SSI0_BASE,*(((uint8_t*)data)+c)); //SSIDataPutNonBlocking(SSI0_BASE,*(data+c)); } }
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; } }
// -------------------------------------------------------------------------------------- // // SB_DmxUpdate // // -------------------------------------------------------------------------------------- void SB_DmxUpdate(ui8 slaveMask, ui16 offset, ui16 channelCnt, ui8 *updatedVal) { ui32 tempLong = 0; ui16 i = 0; // TODO : Buffer check, channelCnt Limit // TODO : offset check with channel cant exceed 512 // CS the Slave SB_CS_Select( slaveMask ); SSIDataPut(SSI0_BASE, (ui16)('#'<<8 | SB_DMX_UPDATE)); SSIDataPut(SSI0_BASE, offset); SSIDataPut(SSI0_BASE, channelCnt); // pack 2 bytes into each 16bit value // accounting for an odd number to send for (i=0; i<(channelCnt/2); i++) { tempLong = updatedVal[i*2]; //tempLong <<= 8; if ( (i*2)+1 >= channelCnt) { // clear the bottom byte out tempLong &= ~0xFF00; } else { tempLong |= (updatedVal[(i*2)+1] << 8) & 0xFF00; } SSIDataPut(SSI0_BASE, tempLong); } // Make sure it's all sent while ( SSIBusy(SSI0_BASE) ) { // TODO : Time out } // Clear data read in while(SSIDataGetNonBlocking(SSI0_BASE, &tempLong)) { } // Deselect the Slave SB_CS_DeSelect( slaveMask ); }
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); }
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); }
uint16_t AnalogADDASPItransfer(uint8_t chip, uint16_t data) { volatile uint16_t delay; GPIOPinWrite(GPIO_PORTA_BASE, chip, 0); //delay = 0xFF; //while (delay){delay--;}; //temp = (1<<5)|1; // 24 bit, LJ, without mute SSIDataPut(SSI0_BASE,data); while(SSIBusy(SSI0_BASE)){}; //delay = 0x0F; //while (delay){delay--;}; GPIOPinWrite(GPIO_PORTA_BASE, chip, chip); delay = 0xFF; while (delay){delay--;}; return (0); }
uint8_t cc112x_write_regs(const int xcvr, const uint16_t const regSettings[][2], const int arrLen) { while(SSIBusy(SSI0_BASE)); SysCtlDelay(SysCtlClockGet() / (3*1000)); int i; for(i = 0; i < arrLen; i++) { //cc112x_print_status_byte(cc112x_sgl_reg_access(xcvr, REG_WRITE, regSettings[i][0], regSettings[i][1])); cc112x_sgl_reg_access(xcvr, REG_WRITE, regSettings[i][0], regSettings[i][1]); //UART_TX_string("\n\r"); } SysCtlDelay(SysCtlClockGet() / (3*100)); return 0; }