cancel
Showing results for 
Search instead for 
Did you mean: 

Update parameters with UART

AE104
Senior

Hello,

Currently, I command the sensor with "SendScriptToDevice(Linear_Sweep);" function like that. 

 

char const * Linear_Sweep= "e\n"
                             "var c\n"
                             "var p\n"
                             "set_pgstat_mode 3\n"
                             "set_max_bandwidth 200\n"
                             "set_range ba 500u\n"
                             "set_e -500m\n"
                             "cell_on\n"
                             "wait 1\n"
                             "meas_loop_lsv p c -500m 500m 50m 100m\n"
                             "pck_start\n"
                             "pck_add p\n"
                             "pck_add c\n"
                             "pck_end\n"
                             "endloop\n"
                             "cell_off\n"
                             "\n";

int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART3_UART_Init();
  MX_USART2_UART_Init();

  /* Initialize interrupts */
  MX_NVIC_Init();
  /* USER CODE BEGIN 2 */
  HAL_UART_Receive_IT(&huart3, RX_Data, 1);
  SendScriptToDevice(Linear_Sweep);

 

But now, I want to updated certain numbers in Linear_Sweep with UART receiving. To implement this idea, I wrote the codes like that but it didn't work. Do you have a suggestion about the problem?

 

 

 while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
	  	HAL_StatusTypeDef usart2_status;  // Bluetooth control USART port
	  	usart2_status = HAL_UART_Receive(&huart2, Rx_mux, 58, 50); //receive 58 bytes (0-58) of data from MATLAB off laptop, 60 sec timeout
	  	HAL_Delay(500);

	  	if (usart2_status != HAL_TIMEOUT)
	  	{
	  		HAL_Delay(250);
	  		technique = (Rx_mux[17]<<8) | Rx_mux[16];
	  	    pa100_16 = (Rx_mux[19]<<8) | Rx_mux[18];
	  	    na1_16 = (Rx_mux[21]<<8) | Rx_mux[20];
	  	    na10_16 = (Rx_mux[23]<<8) | Rx_mux[22];
	  	    na100_16 = (Rx_mux[25]<<8) | Rx_mux[24];
	  	    ua1_16 = (Rx_mux[27]<<8) | Rx_mux[26];
	  	    ua10_16 = (Rx_mux[29]<<8) | Rx_mux[28];
	  	    ua100_16 = (Rx_mux[31]<<8) | Rx_mux[30];
	  	    ma1_16 = (Rx_mux[33]<<8) | Rx_mux[32];
	  	    ma10_16 = (Rx_mux[35]<<8) | Rx_mux[34];
	  	    ma100_16 = (Rx_mux[37]<<8) | Rx_mux[36];
	  	    tequil16 = (Rx_mux[39]<<8) | Rx_mux[38];
	  	    Ebegin16 = (Rx_mux[41]<<8) | Rx_mux[40];
	  	    Eend16 = (Rx_mux[43]<<8) | Rx_mux[42];
	  	    Estep16 = (Rx_mux[45]<<8) | Rx_mux[44];
	  	    Scanrate16 = (Rx_mux[47]<<8) | Rx_mux[46];
	  	    AmplitudeSWV = (Rx_mux[49]<<8) | Rx_mux[48];
	  	    FrequencySWV = (Rx_mux[51]<<8) | Rx_mux[50];
	  	    EdcChro = (Rx_mux[53]<<8) | Rx_mux[52];
	  	    tintervalChro = (Rx_mux[55]<<8) | Rx_mux[54];
	  	    trunChro = (Rx_mux[57]<<8) | Rx_mux[56];

	  	    if (pa100_16 == 1){
	  	    	Current_range = 100;
	  	    	Current_unit = 'p';
	  	    }
	  	    else if (na1_16 == 1){
	  	    	Current_range = 1;
	  	    	Current_unit = 'n';
	  	    }
	  	    else if (na10_16 == 1){
	  			Current_range = 10;
	  			Current_unit = 'n';
	  	    }
	  	    else if (na100_16 == 1){
	  			Current_range = 100;
	  			Current_unit = 'n';
	  		}
	  	    else if (ua1_16 == 1){
	  			Current_range = 1;
	  			Current_unit = 'u';
	  		}
	  	    else if (ua10_16 == 1){
	  			Current_range = 10;
	  			Current_unit = 'u';
	  		}
	  	    else if (ua100_16 == 1){
	  			Current_range = 100;
	  			Current_unit = 'u';
	  		}
	  	    else if (ma1_16 == 1){
	  			Current_range = 1;
	  			Current_unit = 'm';
	  		}
	  	    else if (ma10_16 == 1){
	  			Current_range = 10;
	  			Current_unit = 'm';
	  		}
	  	    else {
	  			Current_range = 100;
	  			Current_unit = 'm';
	  		}

	  	    if(isFirstRun) {

	  	    	Linear_Sweep = malloc(200);

				sprintf(Linear_Sweep,"e\n "
									 "var c\n"
									 "var p\n"
									 "set_pgstat_mode 3\n"
									 "set_max_bandwidth 200\n"
									 "set_range ba %d\%c\n"
									 "set_e -500m\n"
									 "cell_on\n"
									 "wait %d\n"
									 "meas_loop_lsv p c %d\m %d\m %d\m %d\m\n"
									 "pck_start\n"
									 "pck_add p\n"
									 "pck_add c\n"
									 "pck_end\n"
									 "endloop\n"
									 "cell_off\n"
									 "\n\0",
									 Current_range,
									 Current_unit,
									 tequil16,
									 Ebegin16,
									 Eend16,
									 Estep16,
									 Scanrate16);

				SendScriptToDevice(Linear_Sweep);

				// Set the flag to 0 so this block won't be executed again
				isFirstRun = 0;
	  	    }
	  	}


	  	// Free the memory allocated to Linear_Sweep
	  	free(Linear_Sweep);

 

12 REPLIES 12

I have another callback to receive the measurements of data:

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{

  if (huart->Instance == USART3)  // check if it's USART3 interrupt
  {
    RX_Buffer[RX_Counter++] = RX_Data[0];  // Store received data in buffer
    HAL_UART_Receive_IT(huart, RX_Data, 1); // Ready to receive next byte
  }

}

Because of that I got an error message : error: redefinition of 'HAL_UART_RxCpltCallback' @Karl Yamashita 

So, I combined with like that:

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
  if (huart->Instance == USART3)  // check if it's USART3 interrupt
  {
    RX_Buffer[RX_Counter++] = RX_Data[0];  // Store received data in buffer
    HAL_UART_Receive_IT(huart, RX_Data, 1); // Ready to receive next byte
  }
  else if(huart == &huart2)
  {
    dataRdy = true;
    UART_EnableInterrupt(); // enable interrupt again
  }
}
AE104
Senior

Sorry the system didn't allow to send more messages @Karl Yamashita 

I use Putty and this is the settings:

AE104_0-1715889836749.png

I use "\t" so there is a tab space between measurement.