Post Go back to editing

Missing The Mark for Ending of a Measurement Loop

Category: Hardware
Product Number: emStat pico

Hello

I try to control emstat pico module with stm32 processor. When I check the capturing data, I recognized that there is no '*\n" command in the recording data. Do you what it can be reason for that?

Here is the recorded data, "e\nM0007\nPda8061B74u;ba8030F9Dn,12,28\n", '\0' <repeats 62 times>

Parents Reply Children
  • Hello  

    I agree with you about losing data because when I check the raw data before parsing, it looks like that "e\nM0007\nPda8061B74u;ba8030F9Dn,12,28\n" I recognized that there should be one more digit as well after the last 8. Based on the document, it would be like that "...,288\n*\n\n". Is that correct? Other thing is that when I increase the interval time to 5 s and keep total run time in 10s, I got same problem.

  • Hi,

    If a 10s runtime and a 5s interval time still caused the same issue, I would suggest looking at the communication implementation.

    Are you using interrupt or polling ? Do you have a circular buffer? How big is the receiving buffer? Are you able to grab a complete output of the latest script , I expect only 2 packets followed by the "*\n"

    Cheers,

    Walter

  • Like this:

    M0007
    Pda807A1CAu;ba635FE86p,10,20A
    Pda807A1CAu;ba635FE86p,10,20A
    *

  • I set it in interrupt mode. The circular buffer is in DMA mode, so in my case there is no circular buffer. Receiving buffer size is 100 bytes. 

  • So I understood that you are using DMA in circular mode, am I correct?

    And the DMA generates an interrupt if some threshold is exceeded? 

    So when the data comes in how fast are you parsing the data so the buffer can be overwritten in the buffer?

    Which STM32 do you use? 

    Sorry for al these questions but I have to get a complete picture of this.

  • No worries, thank you for your quick response!

    I use UART in interrupt mode, not DMA mode.

    Actually, I didn't know answer of the question,"when the data comes in how fast are you parsing the data so the buffer can be overwritten in the buffer?". How can I measure the how fast parsing of data?

    STM32F407IEH6

  • Ah okay so you get an interrupt every time you receive a character?

  • Exactly, for example here is my receive call back function,

    UART3 is for emstatpico and STM32 communication; UART2 is for STM32 to PC communication.

    uint8_t RXData[100];

    uint8_t temp_counter = 0;

    uint8_t buffer[100];

    uint8_t RXBuff[100];

    uint16_t mCounter = 0;

    void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

    {

    int i = 0;

    int j = 0;

    int start = -1;

    int end = -1;

    if (huart == &huart3) {

    HAL_UART_Transmit(&huart2, RXData, 1, 1000);

    RXBuff[mCounter++] = RXData[0];

    }

    // Find the start and end indices of the data

    for (i = 0; i < strlen(RXBuff); i++) {

    if (RXBuff[i] == 'P') {

    start = i;

    break;

    }

    }

    for(i = start; i < strlen(RXBuff); i++) {

    if (RXBuff[i] == '\n') {

    end = i;

    break;

    }

    }

    // Copy the data to the buffer

    if (start != -1 && end != -1) {

    for (i = start; i <= end; i++) {

    buffer[j++] = RXBuff[i];

    }

    for(int temp = 0; temp < 100 ; temp++) RXBuff[temp] = 0;

    mCounter = 0;

    buffer[j] = '\0';

    }

    HAL_UART_Receive_IT(&huart3, RXData, 1);

    }

  • Hi , 

    For a number of reasons, I don't want to discuss, I am not allowed to go in depth regarding programming.

    I can give you some tips though which I think will help:

    • Keep the ISR (Callback) as small as possible, so I would suggest implementing a ringbuffer that is pushed in the callback and popped in the mainloop.
    • Do al the parsing in the mainloop and not in the callback.
    • Also retransmitting the characters to the other uart can also be performed in the mainloop.
    • Be aware that HAL functions can be time consuming

    I am convinced these will help.

    Regards,

    Walter

  • Hi Walter,

    Thank you for your comments! I will try to implement your idea. I have one more question. There is /RST pin which is 5th one. Can set it SET in certain periods and send the MethodScript to the sensor for running it again? Do you think it works?  

    Thank you