This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3220SF: SERIAL data from OpenMV H7 to TI 3220 SF launchpad

Part Number: CC3220SF


Hello,

I am trying to send SERIAL data from OpneMV H7 to TI 3220 SF launchpad. 

I have this simple code in OpenMV, where I an sending the number 5 as a test

        from pyb import SPI

        spi = SPI(2, SPI.MASTER, baudrate=115200, polarity=1, phase=0, crc=0x7)

        spi.send(b'5')

In CCCT (TI IDE) the code snippet is included below

#define SPI_MSG_LENGTH  (30)

#define SLAVE_MSG       ("Hello from slave, msg#: ")

#define MAX_LOOP        (10)

unsigned char slaveRxBuffer[SPI_MSG_LENGTH];

unsigned char slaveTxBuffer[SPI_MSG_LENGTH];

/* Semaphore to block slave until transfer is complete */

sem_t slaveSem;

static Display_Handle display;

void transferCompleteFxn(SPI_Handle handle, SPI_Transaction *transaction)

{

    sem_post(&slaveSem);

}

       LOG_INFO("Starting SPI Code\r\n");

    // BEGIN SPI SLAVE CODE

       SPI_Handle      slaveSpi;

       SPI_Params      spiParams;

       SPI_Transaction transaction;

       uint32_t        i;

       bool            transferOK;

       int32_t         status;

          GPIO_setConfig(CONFIG_SPI_SLAVE_READY, GPIO_CFG_OUTPUT | GPIO_CFG_OUT_LOW);

          GPIO_setConfig(CONFIG_SPI_MASTER_READY, GPIO_CFG_INPUT);

          LOG_INFO("setconfig done\r\n");

          GPIO_write(CONFIG_SPI_SLAVE_READY, 1);

          while (GPIO_read(CONFIG_SPI_MASTER_READY) == 0) {}

          status = sem_init(&slaveSem, 0, 0);

          if (status != 0) {

              //Display_printf(display, 0, 0, "Error creating slaveSem\n");

              LOG_INFO("Error creating slaveSem\r\n");

              while(1);

          }

          while (GPIO_read(CONFIG_SPI_MASTER_READY)) {}

          LOG_INFO("SPI is ready to receive messages\r\n");

          SPI_Params_init(&spiParams);

          spiParams.frameFormat = SPI_POL0_PHA1;

          spiParams.mode = SPI_SLAVE;

          spiParams.transferCallbackFxn = transferCompleteFxn;

          spiParams.transferMode = SPI_MODE_CALLBACK;

          slaveSpi = SPI_open(CONFIG_SPI_SLAVE, &spiParams);

          if (slaveSpi == NULL) {

              //Display_printf(display, 0, 0, "Error initializing slave SPI\n");

              LOG_INFO("Error initializing slave SPI\r\n")

              while (1);

          }

          else {

              //Display_printf(display, 0, 0, "Slave SPI initialized\n");

              LOG_INFO("Slave SPI initialized\r\n")

          }

          /* Copy message to transmit buffer */

          strncpy((char *) slaveTxBuffer, SLAVE_MSG, SPI_MSG_LENGTH);

The challenge I am facing is that the code does not come out of this loop

          while (GPIO_read(CONFIG_SPI_MASTER_READY)) {}

The statement below does not get executed:

          LOG_INFO("SPI is ready to receive messages\r\n");

This seem to imply that the serial data is not coming from OpenMV to TI board. 

The pins that are connected in between two boards are:

OpenMV: 

P0 (MOSI)

P1 (MISO)

P2 (SLCK)

P3 (SS)

TI board 

MOSI (P7)

MISO (P6)

CLK (P5)

SS (P8)

Thanks,

  • Have you referred to the SPI Slave example?

  • Yes, The code above is based on the SPI Slave example.

  • Check the Readme of the example. The example uses MASTER READY line (and SLAVE READY line) to sync between the master and slave devices.

    This is not standard. You are not using this line so you need to update the code accordingly. 

  • Thanks for the help. I made some edits in the code. It appears to work better. At the last step there is a statement

           sem_wait(&slaveSem);

    This statement does not get completed. This is highlighted in the bold below. All the prior statements appear to work correctly. Does it mean that the connection of pins is correct. I need to receive a number sent from the OpenMV board to the TI board, and dont need to send anything from TI board to OpenMV. Appreciate any ideas and help.

    What could be the possible cause of the problem. 
     

    LOG_INFO("before GPIO set config %s\r\n", SSID_NAME);

    GPIO_setConfig(CONFIG_SPI_SLAVE_READY, GPIO_CFG_OUTPUT | GPIO_CFG_OUT_LOW);
    GPIO_setConfig(CONFIG_SPI_MASTER_READY, GPIO_CFG_INPUT);

    LOG_INFO("GPIO Config done\r\n");

    /*
    * Handshake - Set CONFIG_SPI_SLAVE_READY high to indicate slave is ready
    * to run. Wait for CONFIG_SPI_MASTER_READY to be high.
    */
    GPIO_write(CONFIG_SPI_SLAVE_READY, 1);
    while (GPIO_read(CONFIG_SPI_MASTER_READY) == 0) {}
    LOG_INFO("Received handshake from Master.\r\n");

    status = sem_init(&slaveSem, 0, 0);
    if (status != 0) {
                     Display_printf(display, 0, 0, "Error creating slaveSem\n");

                     while(1);
    }


    LOG_INFO("Sem init done\r\n");

    while (GPIO_read(CONFIG_SPI_MASTER_READY)) {}

    LOG_INFO("Ready to receive messages\r\n");

    /*
    * Open SPI as slave in callback mode; callback mode is used to allow us to
    * configure the transfer & then set CONFIG_SPI_SLAVE_READY high.
    */
    SPI_Params_init(&spiParams);
    spiParams.frameFormat = SPI_POL0_PHA1;
    spiParams.mode = SPI_SLAVE;
    spiParams.transferCallbackFxn = transferCompleteFxn;
    spiParams.transferMode = SPI_MODE_CALLBACK;
    slaveSpi = SPI_open(CONFIG_SPI_SLAVE, &spiParams);

    if (slaveSpi == NULL) {
        LOG_INFO("Error initializing slave SPI\r\n");
        Display_printf(display, 0, 0, "Error initializing slave SPI\n");
        while (1);
    }
    else {
        LOG_INFO("Slave SPI initialized\r\n");
        Display_printf(display, 0, 0, "Slave SPI initialized\n");
    }

    /* Copy message to transmit buffer */
    strncpy((char *) slaveTxBuffer, SLAVE_MSG, SPI_MSG_LENGTH);

    for (i = 0; i < MAX_LOOP; i++) {
        /* Initialize slave SPI transaction structure */
        transaction.count = SPI_MSG_LENGTH;
        transaction.txBuf = NULL;
        transaction.rxBuf = (void *) slaveRxBuffer;

        /* Toggle on user LED, indicating a SPI transfer is in progress */
        GPIO_toggle(CONFIG_GPIO_LED_1);

        transferOK = SPI_transfer(slaveSpi, &transaction);
        if (transferOK) {
            LOG_INFO("Inside transfer OK\r\n");
            LOG_INFO("Slave received %s\r\n",slaveRxBuffer);

            GPIO_write(CONFIG_SPI_SLAVE_READY, 0);

            LOG_INFO("GPI write done\r\n");

            /* Wait until transfer has completed */
           sem_wait(&slaveSem);
           //THE NEXT STATEMENT DOES NOT GET PRINTED
           LOG_INFO("SEM wait done\r\n");

    /*
    * Drive CONFIG_SPI_SLAVE_READY high to indicate slave is not ready
    * for another transfer yet.
    */
            GPIO_write(CONFIG_SPI_SLAVE_READY, 1);


            Display_printf(display, 0, 0, "Slave received: %s", slaveRxBuffer);
            LOG_INFO("Slave received\r\n");
        }
        else {
            Display_printf(display, 0, 0, "Unsuccessful slave SPI transfer");
            LOG_INFO("Unsuccessful slave SPI transfer\r\n");
        }
    }

    SPI_close(slaveSpi);

    /* Example complete - set pins to a known state */
    GPIO_setConfig(CONFIG_SPI_MASTER_READY, GPIO_CFG_OUTPUT | GPIO_CFG_OUT_LOW);
    GPIO_write(CONFIG_SPI_SLAVE_READY, 0);

  • Seems like the transaction is not completed.

    The slaveSem is posted from the TransferComplete callback - so seems it is not being called by the driver.

    You will need to check the lines.

  • Thanks I checked the connections. The clock was set to P3 instead of P5. So the new pins on TI side is

    MOSI P07

    MISO P06

    SCLK P05

    SS P08

    And Gnd 

    The above are connected to the corresponding pins of OpenMV. I added a statement  spiParams.bitRate = 115200; in TI code, and changed the phase to 1 in OpenMV: 

            spi = SPI(2, SPI.MASTER, baudrate=115200, polarity=0, phase=1)

    The new TI code is included below. The problem remains the same, TransferComplete callback does not get called.

    status = sem_init(&slaveSem, 0, 0);
    if (status != 0) {
        while(1);
    }
    LOG_INFO("Sem init done\r\n");

    SPI_Params_init(&spiParams);
    spiParams.bitRate = 115200;
    spiParams.frameFormat = SPI_POL0_PHA1;
    spiParams.mode = SPI_SLAVE;
    spiParams.transferCallbackFxn = transferCompleteFxn;
    spiParams.transferMode = SPI_MODE_CALLBACK;
    slaveSpi = SPI_open(CONFIG_SPI_SLAVE, &spiParams);

    if (slaveSpi == NULL) {
        LOG_INFO("Error initializing slave SPI\r\n");
        while (1);
    }
    else {
        LOG_INFO("Slave SPI initialized\r\n");
    }

    /* Copy message to transmit buffer */
    strncpy((char *) slaveTxBuffer, SLAVE_MSG, SPI_MSG_LENGTH);

    for (i = 0; i < MAX_LOOP; i++) {
        /* Initialize slave SPI transaction structure */
        transaction.count = SPI_MSG_LENGTH;
        transaction.txBuf = NULL;
        transaction.rxBuf = (void *) slaveRxBuffer;

        /* Toggle on user LED, indicating a SPI transfer is in progress */
        GPIO_toggle(CONFIG_GPIO_LED_1);

        transferOK = SPI_transfer(slaveSpi, &transaction);
        if (transferOK) {
            LOG_INFO("Inside transfer OK\r\n");
            LOG_INFO("Slave received %s\r\n",transaction.rxBuf);

            /* Wait until transfer has completed */
           sem_wait(&slaveSem);
           LOG_INFO("SEM wait done\r\n");

            GPIO_write(CONFIG_SPI_SLAVE_READY, 1);


            LOG_INFO("Slave received\r\n");
    }
        else {
            LOG_INFO("Unsuccessful slave SPI transfer\r\n");
        }
    }

  • Please check the lines (you can send a logic analyzer output) during the transaction. 

    Please compare to a successful transaction when using SPI slave and SPI master examples.

    br,

    Kobi