//***************************************************************************** // //! SPI Master mode main loop //! //! This function configures SPI modelue as master and enables the channel for //! communication //! //! \return None. // //***************************************************************************** void MasterMain() { // unsigned long ulUserData; uint8_t ulUserData; uint8_t ulDummy; // unsigned long ulDummy; // // Initialize the message // // memcpy(g_ucTxBuff,MASTER_MSG,sizeof(MASTER_MSG)); // // Set Tx buffer index // ucTxBuffNdx = 0; ucRxBuffNdx = 0; // // Reset SPI // MAP_SPIReset(GSPI_BASE); // // Configure SPI interface // MAP_SPIConfigSetExpClk(GSPI_BASE,MAP_PRCMPeripheralClockGet(PRCM_GSPI), SPI_IF_BIT_RATE,SPI_MODE_MASTER,SPI_SUB_MODE_3, (SPI_SW_CTRL_CS | SPI_4PIN_MODE | SPI_TURBO_OFF | SPI_CS_ACTIVELOW | SPI_WL_8)); // // Enable SPI for communication // MAP_SPIEnable(GSPI_BASE); // // Print mode on uart // Message("Enabled SPI Interface in Master Mode\n\r"); // // User input // Report("Press any key to transmit data...."); // // Read a character from UART terminal // // ulUserData = MAP_UARTCharGet(UARTA0_BASE); // // Send the string to slave. Chip Select(CS) needs to be // asserted at start of transfer and deasserted at the end. // // MAP_SPITransfer(GSPI_BASE,g_ucTxBuff,g_ucRxBuff,50, // SPI_CS_ENABLE|SPI_CS_DISABLE); // // Report to the user // Report("\n\rSend %s",g_ucTxBuff); Report("Received %s",g_ucRxBuff); // // Print a message // Report("\n\rType here (Press enter to exit) :"); // // Initialize variable // ulUserData = 0x0F; //address of WHO AM I register of the sensor from which i am trying to read the data // // Enable Chip select // MAP_SPICSEnable(GSPI_BASE); // // Loop until user "Enter Key" is // pressed // // while(ulUserData != '\r') // { // // // // Read a character from UART terminal // // // ulUserData = MAP_UARTCharGet(UARTA0_BASE); // // // // // Echo it back // // // MAP_UARTCharPut(UARTA0_BASE,ulUserData); // // Push the character over SPI // MAP_SPIDataPut(GSPI_BASE,ulUserData); // // Clean up the receive register into a dummy // variable // MAP_SPIDataGet(GSPI_BASE,(unsigned long *)&ulDummy); // } // // Disable chip select // MAP_SPICSDisable(GSPI_BASE); } //***************************************************************************** // //! Board Initialization & Configuration //! //! \param None //! //! \return None // //***************************************************************************** static void BoardInit(void) { /* In case of TI-RTOS vector table is initialize by OS itself */ #ifndef USE_TIRTOS // // Set vector table base // #if defined(ccs) MAP_IntVTableBaseSet((unsigned long)&g_pfnVectors[0]); #endif #if defined(ewarm) MAP_IntVTableBaseSet((unsigned long)&__vector_table); #endif #endif // // Enable Processor // MAP_IntMasterEnable(); MAP_IntEnable(FAULT_SYSTICK); PRCMCC3200MCUInit(); } //***************************************************************************** // //! Main function for spi demo application //! //! \param none //! //! \return None. // //***************************************************************************** void main() { // // Initialize Board configurations // BoardInit(); // // Muxing UART and SPI lines. // PinMuxConfig(); // // Enable the SPI module clock // MAP_PRCMPeripheralClkEnable(PRCM_GSPI,PRCM_RUN_MODE_CLK); // // Initialising the Terminal. // InitTerm(); // // Clearing the Terminal. // ClearTerm(); // // Display the Banner // Message("\n\n\n\r"); Message("\t\t ********************************************\n\r"); Message("\t\t CC3200 SPI Demo Application \n\r"); Message("\t\t ********************************************\n\r"); Message("\n\n\n\r"); // // Reset the peripheral // MAP_PRCMPeripheralReset(PRCM_GSPI); #if MASTER_MODE MasterMain(); #else SlaveMain(); #endif while(1) { } }