Other Parts Discussed in Thread: EK-TM4C123GXL, , TMS320F28377D
Tool/software: Code Composer Studio
Hello All,
I am trying to (want to) send an array of float datatype through SPI communication. I have started with the "TivaWare_C_Series-2.1.3.156" ssi example,which is in master mode and enables user to communicate the data in uint32 datatype.
Here is my code which I am working on
float pui32DataTx[4] = {0000,1001,768,1010}; float pui32DataRx[4]; uint32_t ui32Index; int i; int main(void) { // // 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); // // 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, &pui32DataRx)); // // Send n bytes of data. // for(ui32Index = 0; ui32Index < 4; ui32Index++) { for(i=0;i<4;i++) { // // 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, pui32DataTx[ui32Index]>>(i*8)); // // Wait until SSI0 is done transferring all the data in the transmit FIFO. // while(SSIBusy(SSI0_BASE)); // // SSIDataGet(SSI0_BASE, &pui32DataRx); // // Wait until SSI0 is done transferring all the data in the transmit FIFO. // //while(SSIBusy(SSI0_BASE)); //} SysCtlDelay(2000); // I had to add this delay to avoid missing the communication in between } while(1); }
The ssi library is used from tivaware mentioned above in which the transmission is handled with this function
void SSIDataPut(uint32_t ui32Base, uint32_t ui32Data) { // // Check the arguments. // ASSERT(_SSIBaseValid(ui32Base)); ASSERT((ui32Data & (0xfffffffe << (HWREG(ui32Base + SSI_O_CR0) & SSI_CR0_DSS_M))) == 0); // // Wait until there is space. // while(!(HWREG(ui32Base + SSI_O_SR) & SSI_SR_TNF)) { } // // Write the data to the SSI. // HWREG(ui32Base + SSI_O_DR) = ui32Data; }
*Please check the "driverlib/ssi.c" for details
This code is in Master mode and uint32 datatype -> I want to use TM4C123 in Slave mode & float datatype
Kindly suggest the required changes. I have tried a few like changing the datatype manually in the "driverlib/ssi.c" file in the function mentioned above. BUT FAILED
For slave mode - I did not try anything as of yet - but will
"SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 1000000, 8);"
changed to
"SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0, SSI_MODE_SLAVE, 1000000, 8);"
help do the needful?