Here is how I plan to initialize 2 SPI buses on SSI0 and SSI2
First: is this the right way to do this!
- I plan to open 2 SPI ports on init and keep them open through the lifetime of the board. Do I need to check if the connection is open after a while?
- I plan to use CA_SPI_WRITE to read and write using one of those 2 SPI ports
- Because I used syscfg GUI to set up SPI I don't have access to the CS pin of either SPI port DIRECTLY
- Is there a way of toggling those CS pins from another function? rephrase (how can I access those CS pins without affecting the way I wrote (spiBus_Init)?
void spiBus_Init() { /* Initialize SPI handle as default master */ SPI_init(); SPI_Params_init(&masterSpiParamsCa); SPI_Params_init(&masterSpiParamsEis); memset(masterRxBufferCa, 0, sizeof(masterRxBufferCa)); memset(masterTxBufferCa, 0, sizeof(masterTxBufferCa)); memset(masterRxBufferEis, 0, sizeof(masterRxBufferEis)); memset(masterTxBufferEis, 0, sizeof(masterTxBufferEis)); masterSpiParamsCa.frameFormat = SPI_POL0_PHA1; masterSpiParamsCa.bitRate = 10000000; masterSpiParamsCa.mode = SPI_MASTER; masterSpiParamsCa.dataSize = 8; masterSpiParamsCa.transferCallbackFxn = CatransferCompleteFxn; masterSpiParamsEis.frameFormat = SPI_POL0_PHA1; masterSpiParamsEis.bitRate = 10000000; masterSpiParamsEis.mode = SPI_MASTER; masterSpiParamsEis.dataSize = 8; masterSpiParamsEis.transferCallbackFxn = EistransferCompleteFxn; masterSpiCa = SPI_open(CONFIG_SPI_CA, &masterSpiParamsCa); if (masterSpiCa == NULL) System_abort("Error initializing CA master SPI\n"); else printf("Master CA SPI initialized\n"); masterSpiEis = SPI_open(CONFIG_SPI_EIS, &masterSpiParamsEis); if (masterSpiEis == NULL) System_abort("Error initializing EIS master SPI\n"); else printf("Master EIS SPI initialized\n"); //SPI_control(spiHandle, SPICC26XXDMA_RETURN_PARTIAL_ENABLE, NULL); // ?? }
Here is the block to Readorwrite using the handle from above:
uint8_t CA_SPI_WRITE(uint8_t nBytes, uint8_t* txBufferPointer, uint8_t* rxBufferPointer, uint8_t CS_pin){ /* Copy message to transmit buffer */ strncpy((char *)masterTxBufferCa, MASTER_MSG, SPI_MSG_LENGTH); uint8_t i; for (i = 0; i < MAX_LOOP; i++) { // Initialize master SPI transaction structure masterTxBufferCa[sizeof(MASTER_MSG) - 1] = (i % 10) + '0'; memset((void *) masterRxBufferCa, 0, SPI_MSG_LENGTH); masterTransactionCa.count = SPI_MSG_LENGTH; masterTransactionCa.txBuf = (void *)masterTxBufferCa; masterTransactionCa.rxBuf = (void *)masterRxBufferCa; // Turn on user LED, indicating a SPI transfer is in progress GPIO_write(CONFIG_LED_ORANGE_GPIO, CONFIG_GPIO_LED_ON); // Initiate SPI transfer bool transferOK = SPI_transfer(masterSpiCa, &masterTransactionCa); if (transferOK) printf("Master: %s\n", masterRxBufferCa); else printf("Unsuccessful master SPI transfer"); // Sleep a short time to allow the LED to flash usleep(500000); // Turn off user LED, indicating the SPI transfer is done GPIO_write(CONFIG_LED_ORANGE_GPIO, CONFIG_GPIO_LED_OFF); // Sleep for a bit before starting the next SPI transfer sleep(3); // should i close the spi ? } return 0; }