Skip to main content
Visitor II
May 22, 2024
Question

Reading input at high frequency

  • May 22, 2024
  • 6 replies
  • 2336 views

Hi,

I've encountered a problem with digital input probing. I have two signals connected to my GPIO on the STM32 F411; the first one is the CMD line, and the second is CLK. Based on the CLK, I would like to read incoming bits on CMD, but only for a specific number of times (for example, 50 times). So far, I've implemented external interrupts on both pins, and up to 400kHz, it works fine. I would like to increase the speed to a few MHz or at least 1 MHz. Moreover, I would like to send the collected data over USB FS. Please let me know if it is possible to achieve this and guide me on how to do it.

Thanks for your responses.

    This topic has been closed for replies.

    6 replies

    Graduate II
    May 22, 2024

    1 MHz interrupts: bad idea

    Can't you use a protocol supported by hardware, like SPI or I2C?

    Super User
    May 22, 2024

    Hi,

    1. to read your cmd, you need only 1 INT , on clk.

    2. you do it in a INT, so show your program, to talk about ; but dont expect wonders...1us action is about the limit.

    3. what is your signal coming from ? Show it. Maybe "capture" by uart or spi is possible .

    tjakAuthor
    Visitor II
    May 23, 2024

    I'm trying to listen to SDIO protocol. The aim is to recognize data coming on DATA0. I'm probing now on CMD line as a starter before going deep with DATA. Here is my code (note that I'm a beginner):

    void EXTI9_5_IRQHandler(void)

    {

    /* USER CODE BEGIN EXTI9_5_IRQn 0 */

    // czyszczenie flagi w kolejce przerwan

    // zeby nie wykonywalo sie w kolko

    // if(__HAL_GPIO_EXTI_GET_IT(CLK_Pin) != RESET)

    // {

    // __HAL_GPIO_EXTI_CLEAR_IT(CLK_Pin);

    // }

    // Check whether hardware set the flag in pending register (GPIO_PIN_5 = 0x0020)

    if(EXTI->PR & 0x0020)

    {

    EXTI-> PR = 0x0020;

    }

     

    if(runClkCode)

    {

    if(counter>0)

    {

    set = (GPIOC->IDR & GPIO_IDR_IDR_15) ? '1' : '0'; // czytaj wartosc pinu CMD i

    buffer[counter-1] = set; // zapisz w bufforze

    counter--; // zliczaj kolejne przerwania

    }

    else

    {

    runClkCode = 0;

    runCommandCode = 1;

    howmany++;

    //HAL_NVIC_DisableIRQ(EXTI9_5_IRQn); // wylacz przerwania od zegara

    //HAL_NVIC_EnableIRQ(EXTI15_10_IRQn); // wlacz przerwania od CMD

    readyToSend = 1;

     

    //sendOverUsb("%s", buffer);

    }

     

    }

    }

    /* USER CODE END EXTI9_5_IRQn 0 */

     

    /* USER CODE BEGIN EXTI9_5_IRQn 1 */

     

    /* USER CODE END EXTI9_5_IRQn 1 */

     

     

    /**

    * @brief This function handles EXTI line[15:10] interrupts.

    */

    void EXTI15_10_IRQHandler(void)

    {

    /* USER CODE BEGIN EXTI15_10_IRQn 0 */

    // if(__HAL_GPIO_EXTI_GET_IT(CMD_Pin) != RESET)

    // __HAL_GPIO_EXTI_CLEAR_IT(CMD_Pin);

    // {

    // check pending flag in PR, and set it again to clear the interrupt flag (GPIO_PIN_15 = 0x8000)

    // PINS are directly mapped to EXTI line

    if(EXTI->PR & 0x8000)

    {

    EXTI->PR = 0x8000;

    }

     

    if(runCommandCode){

    runCommandCode = 0;

    runClkCode = 1;

    counter = 48;

    }

    }

    /* USER CODE END EXTI15_10_IRQn 0 */

     

    /* USER CODE BEGIN EXTI15_10_IRQn 1 */

     

     

    /* USER CODE END EXTI15_10_IRQn 1 */

    Super User
    May 23, 2024

    @tjak wrote:

    I'm trying to listen to SDIO protocol. /


    So you're basically trying to make a DIY logic analyser?

    There's a number of STM32-based logic analyser projects described on the interwebs - try a search...

    Or, as others have suggested, perhaps SPI can be pressed into service ... ?

     

    Please use this button to properly post source code:

    AndrewNeil_0-1716454504449.png

     

     

    tjakAuthor
    Visitor II
    May 23, 2024

    How SPI can be used here? Could you give me a short introduction? I don't get an idea

    Super User
    May 23, 2024

    Read in rm of your cpu, what SPI can do:

    AScha3_0-1716456958332.png

    So if you know the format (like 8bit words, clocked at rising clock) you could set the SPI to slave mode (= just "listen") and get the bytes clocked in at up to 50Mbit :

    AScha3_1-1716457193370.png

     

    Graduate II
    May 23, 2024

    Or look for an STM32 with an integrated SDIO / SDMMC peripheral.

    And learn about DMA, the best option for most high data rate interfaces. That way a DMA controller handles the data transfer from a peripheral into a memory buffer, and that mostly in the "background" without much CPU load.

    Super User
    May 23, 2024

    @LCE  , he has a F411 : with SDIO...

    AScha3_0-1716463151935.png

    So its more "just playing around" . :)

    tjakAuthor
    Visitor II
    May 23, 2024

    Thank you for your answers. I'll dig into it