Hi there,
I'm trying to communicate to SRAM(http://ww1.microchip.com/downloads/en/DeviceDoc/20005142C.pdf) using MSP430F5529LP over SPI(MSP_EXP430F5529LP_SPIB1). Proper communication is not happening.
Please review the code and help me.
/* XDCtools Header files */ #include <xdc/std.h> #include <xdc/cfg/global.h> #include <xdc/runtime/System.h> /* BIOS Header files */ #include <ti/sysbios/BIOS.h> /* TI-RTOS Header files */ #include <gpio.h> #include <ti/drivers/SPI.h> /* Example/Board Header files */ #include "Board.h" SPI_Handle spiHandle; uint8_t rxBuffer[10]; uint8_t txBuffer[10]; uint8_t dummyBuffer[1]; SPI_Transaction spiTransaction; SPI_Params SPIparams; Void taskFxn (UArg arg0, UArg arg1) { System_printf("Starting the SPI loop-back example\nSystem provider is set to"); /* INITIALISE SRAM */ GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN0); txBuffer[0] = 0x01; txBuffer[1] = 0x40; spiTransaction.count = 2; spiTransaction.rxBuf = dummyBuffer; spiTransaction.txBuf = txBuffer; if ( !SPI_transfer(spiHandle, &spiTransaction) ) { while(1); } GPIO_setOutputHighOnPin(GPIO_PORT_P4, GPIO_PIN0); /* WRITE TO SRAM */ GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN0); txBuffer[0] = 2; txBuffer[1] = 0; txBuffer[2] = 0; txBuffer[3] = 0; txBuffer[4] = 5; txBuffer[5] = 6; txBuffer[6] = 2; txBuffer[7] = 1; spiTransaction.count = 8; spiTransaction.rxBuf = dummyBuffer; spiTransaction.txBuf = txBuffer; if ( !SPI_transfer(spiHandle, &spiTransaction) ) { while(1); } GPIO_setOutputHighOnPin(GPIO_PORT_P4, GPIO_PIN0); /* REAM FROM SRAM */ GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN0); txBuffer[0] = 3; txBuffer[1] = 0; txBuffer[2] = 0; txBuffer[3] = 0; spiTransaction.count = 4; spiTransaction.rxBuf = dummyBuffer; spiTransaction.txBuf = txBuffer; if ( !SPI_transfer(spiHandle, &spiTransaction) ) { while(1); } spiTransaction.count = 4; spiTransaction.rxBuf = rxBuffer; spiTransaction.txBuf = dummyBuffer; if ( !SPI_transfer(spiHandle, &spiTransaction) ) { while(1); } GPIO_setOutputHighOnPin(GPIO_PORT_P4, GPIO_PIN0); /* Deinitialize SPI */ SPI_close(spiHandle); System_printf("Done\n"); System_flush(); } /* * ======== main ======== */ int main(void) { /* Call board init functions. */ Board_initGeneral(); Board_initGPIO(); Board_initSPI(); /* Turn on user LED */ // GPIO_write(Board_LED0, Board_LED_ON); System_printf("Starting the SPI loop-back example\nSystem provider is set to" " SysMin. Halt the target to view any SysMin contents in ROV.\n"); /* SysMin will only print to the console when you call flush or exit */ System_flush(); SPIparams.frameFormat = SPI_POL0_PHA1; SPIparams.bitRate = 1000000; SPIparams.mode = SPI_MASTER; SPIparams.transferCallbackFxn = NULL; SPIparams.dataSize = 8; SPIparams.transferMode = SPI_MODE_BLOCKING; SPIparams.transferTimeout = SPI_WAIT_FOREVER; /* Initialize SPI handle as default master */ spiHandle = SPI_open(Board_SPI1, &SPIparams); if (spiHandle == NULL) { System_abort("Error initializing SPI\n"); } else { System_printf("SPI initialized\n"); } /* Start BIOS */ BIOS_start(); return (0); }
I'm using CCSv6.1 with latest TI-RTOS for MSP430.
Thank you...