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.

GIO setup

Other Parts Discussed in Thread: HALCOGEN

Hello,

I am using TMDSRM48USB,  CCS  Version: 5.4.0.00091 , and  HalcoGen 03.06.00

I apologize, I'm a novice working with micro-controllers but I have learned quite a bit by reading this forum as well as reading the manuals. I am working on a project that has timing requirements in regards to output. Below is the timing sequence for a sensor. I am using mibspi1 to communicate with the sensor. When SDO goes high after ADC conversion, I would like to immediately be “notified”. A solution I’m working with is to use GIO to check the state of SDO. Included is the code snippet as well as the HalcoGen configuration. I would really appreciate some feedback to know whether this is the right idea or not. And also if gioSetDirection() will have to be used.

Thank you

#include "gio.h"

       

        gioInit();

        state = gioGetBit(mibspiPORT1, PIN_SOMI);

        if (state == 1)

                     {

                    // do calculations

                    }

 

  • Albert,

    Your example above won't work I think because you are not looping on this code:

           state = gioGetBit(mibspiPORT1, PIN_SOMI);

            if (state == 1)

                         {

                        // do calculations

                        }

     

    So you will only check the SOMI pin one time.

    You could change the code to something like this:

    while (gioGetBit(mibspiPORT1, PIN_SOMI) != 1) {}

    And that's polling but there's no timeout feature... (You could put a time-out counter inside the {}).

    Also you are basically stalling the processor / keeping it from doing anything useful during the time SOMI is low.

    And you need to consider this:  SOMI will be high according to your diagram until the last bit of the SPI transfer.
    If you simply precede this test by the call to the SPI to initiate the transfer, then you'll probably test PIN_SOMI before it even goes low the first time, so you'll likely fall through right away. 

    You might want to make a test that first looks for SOMI to be low, and then looks for it to be high, and then continues on into the calculations.

    A more elegant way to handle this would be to use the edge detection capability of the GIO module and generate an interrupt on SDO going high.  But if you're really new to micro controllers this might not be the right next step for you so we'll just mention it as an option but not get into details.

  • Anthony,

    Thank you so much  for your quick reply. I over simplified things a bit . I am communicating with 12 sensors via mibSPI1 using a decoder. According to the data sheet, the sensors have a ADC conversion time ranging from approx 7 ms - 9 ms. The conversion command is sent to all the sensors down the line, then it's a matter of waiting until conversions are complete in order to send the read command. A while loop and timeout counter are implemented.

    But it sounds like your saying that using this concept "while (gioGetBit(mibspiPORT1, PIN_SOMI) != 1) {}" should work with a possible modification. Is there anything additional I need to do in HalcoGen besides what is shown in the picture.  For SOMI(1) I just selected GIO and also checked the dir box. Is this correct?  No need to use the gioSetDirection function?

    I will start looking up information on the edge detection capability but if you have a link or example code, it would be greatly appreciated.

    Thank you

    Albert Martinez

  • Hi Albert.

    The SPI requires that at least SOMI, SIMO, and CLK are configured for SPI mode or else it won't operate.

    So you can't configure SOMI as GIO you need it set to SOMI. 

    But even when it is configured as SOMI you can read the status of the pin from the SPIPC2 register so it's ok to configure SOMI this way and still check the value on the pin.

    I think your concept will work to start out with anyway.   If you have a Mib unit available then it might be a good fit for this applicaiton;  you can setup all the transfers ahead of time and trigger them based on pin edges, or based on a time delay.  But that's more complex to implement, just like interrupts would be more complex.