uranyumx
Advanced Member level 4
Hello,
On my custom design PCB, I record analog data through emStat pico module. The controller on my board is STM32F4. Current problem is that the sensor keeps reading data whenever I run again the system. Based on the C application manual of the sensor (https://github.com/PalmSens/emstatpico/blob/master/MethodSCRIPTExample_C/MethodSCRIPT_Example_C.pdf), after reading some certain amount of data, I should get 'measurement completed..." message. But in my case, the results file looks attached files (ADCVals3 is the first run, ADCVals4 is the second run). In the same manual page 6, the raw data should have *\n characters. When I check the buffer, it doesn't have the *\n characters. Maybe the problem is related with that but I didn't understand why I couldn't get these characters. Any suggestions would be helpful.
I use UART3 interrupt mode for communicating sensor and the controller. I emulated Arduino application to the STM version of the code, https://github.com/PalmSens/MethodSCRIPT_Examples/tree/master/MethodSCRIPTExample_Arduino
Here is my callback function,
Here is the code for reading the buffer,
On my custom design PCB, I record analog data through emStat pico module. The controller on my board is STM32F4. Current problem is that the sensor keeps reading data whenever I run again the system. Based on the C application manual of the sensor (https://github.com/PalmSens/emstatpico/blob/master/MethodSCRIPTExample_C/MethodSCRIPT_Example_C.pdf), after reading some certain amount of data, I should get 'measurement completed..." message. But in my case, the results file looks attached files (ADCVals3 is the first run, ADCVals4 is the second run). In the same manual page 6, the raw data should have *\n characters. When I check the buffer, it doesn't have the *\n characters. Maybe the problem is related with that but I didn't understand why I couldn't get these characters. Any suggestions would be helpful.
I use UART3 interrupt mode for communicating sensor and the controller. I emulated Arduino application to the STM version of the code, https://github.com/PalmSens/MethodSCRIPT_Examples/tree/master/MethodSCRIPTExample_Arduino
Here is my callback function,
Code:
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);
}
Here is the code for reading the buffer,
Code:
RetCode ReadBuf(MSComm * msComm, char * buf)
{
int i = 0;
//int j = 0; // CHECK
int k = 0;
char *data = (char *)buffer; // CHECK
do {
// Read a character from the device
int tempChar = data[k++]; // CHECK
//int tempChar = msComm->readCharFunc(); // ADDED
if (tempChar > 0) {
// Store character into buffer
buf[i++] = tempChar;
if (tempChar == '\n') {
buf[i] = '\0'; // ADDED
if (buf[0] == REPLY_VERSION_RESPONSE) {
return CODE_VERSION_RESPONSE;
} else if ((buf[0] == REPLY_MEASURING) || (buf[0] == REPLY_NSCANS_START)) {
return CODE_MEASURING;
} else if (strcmp(buf, "e\n") == 0) {
return CODE_RESPONSE_BEGIN;
} else if ((strcmp(buf, "*\n") == 0 || strcmp(buf, "-\n") == 0)) {
return CODE_MEASUREMENT_DONE;
} else if (strcmp(buf, "\n") == 0) {
return CODE_RESPONSE_END;
} else if (buf[0] == REPLY_MEASURE_DP) {
return CODE_OK;
} else {
printf("Unexpected response from ES Pico: \"%s\"\n", buf);
return CODE_NOT_IMPLEMENTED;
}
}
}
} while (i < (READ_BUFFER_LENGTH - 1));
buf[i] = '\0';
return CODE_NULL;
}