Skip to content

Commit

Permalink
Update example_rawTeros21.c
Browse files Browse the repository at this point in the history
  • Loading branch information
gxjacobs authored Oct 18, 2024
1 parent 170abc2 commit 1b14f38
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions stm32/Src/examples/example_rawTeros21.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,35 +75,47 @@ int main(void)
HAL_UART_Transmit(&huart1, (const uint8_t *)info_str, info_len, 1000);
char success[] = "HAL_OK\n";
char failure[] = "HAL_FAIL\n";
char buffer[20];
char buffer[5];
uint8_t addr = '0';
SDI12_Measure_TypeDef measurment_info;
HAL_StatusTypeDef returnCode;
//HAL_StatusTypeDef returnCode;

// Set Up and transmit
char identify[] = "0M!"; //command to read water potential and temp
SDI12WakeSensors();
returnCode = HAL_UART_Transmit(&huart2, identify, sizeof(identify), HAL_MAX_DELAY);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_1, GPIO_PIN_SET); // Set to RX mode
//char identify[] = "0M!"; //command to read water potential and temp
// SDI12WakeSensors();
//returnCode = HAL_UART_Transmit(&huart2, identify, sizeof(identify), HAL_MAX_DELAY);
//HAL_GPIO_WritePin(GPIOC, GPIO_PIN_1, GPIO_PIN_SET); // Set to RX mode

//Now recieve data
char recieveBuff[50];
__HAL_UART_FLUSH_DRREGISTER(&huart2);
returnCode = HAL_UART_Receive(&huart2, recieveBuff, sizeof(recieveBuff), 3000);
HAL_UART_Transmit(&huart1, recieveBuff, sizeof(recieveBuff), 1000);
//char recieveBuff[50];
//__HAL_UART_FLUSH_DRREGISTER(&huart2);
//returnCode = HAL_UART_Receive(&huart2, recieveBuff, sizeof(recieveBuff), 3000);
//HAL_UART_Transmit(&huart1, recieveBuff, sizeof(recieveBuff), 1000);

// Infinite loop
while (1)
{
char identify[] = "0M!"; //command to read water potential and temp
SDI12WakeSensors();
returnCode = HAL_UART_Transmit(&huart2, identify, sizeof(identify), HAL_MAX_DELAY);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_1, GPIO_PIN_SET); // Set to RX mode
//char identify[] = "0M!"; //command to read water potential and temp
//SDI12WakeSensors();
//returnCode = HAL_UART_Transmit(&huart2, identify, sizeof(identify), HAL_MAX_DELAY);
//HAL_GPIO_WritePin(GPIOC, GPIO_PIN_1, GPIO_PIN_SET); // Set to RX mode

//Now recieve data
__HAL_UART_FLUSH_DRREGISTER(&huart2);
returnCode = HAL_UART_Receive(&huart2, recieveBuff, sizeof(recieveBuff), 3000);
HAL_UART_Transmit(&huart1, recieveBuff, sizeof(recieveBuff), 1000);
//__HAL_UART_FLUSH_DRREGISTER(&huart2);
//returnCode = HAL_UART_Receive(&huart2, recieveBuff, sizeof(recieveBuff), 3000);
//HAL_UART_Transmit(&huart1, recieveBuff, sizeof(recieveBuff), 1000);

// Print voltage level
char buf[32];
int buf_len = sprintf(buf, "0M!");


if (SDI12GetMeasurment(addr, &measurment_info, buffer, 3000) == HAL_OK){
HAL_UART_Transmit(&huart1, (const uint8_t *) success, 7, 100);
HAL_UART_Transmit(&huart1, buffer, 18, 100);
} else {
HAL_UART_Transmit(&huart1, (const uint8_t *) failure, 10, 100);
};

//Sleep
for (int i = 0; i <= 1000000; i++)
Expand Down

0 comments on commit 1b14f38

Please sign in to comment.