This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software:
Hi TI tech Team,
I am working with the CC3220MODASF launchpad and trying to communicate with a GSM modem using AT commands. My question is how to initialize the UART and handle reading when the GSM modem's response is a large string?
my UART initilization for GSM menttioned below
UART_init();
UART_Params_init(&uartParams);
uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readDataMode = UART_DATA_BINARY;
uartParams.readReturnMode = UART_RETURN_FULL;
uartParams.readEcho = UART_ECHO_OFF;
uartParams.baudRate = 115200;
uartParams.readTimeout = UART_WAIT_FOREVER; // 500
Gsm_uart= UART_open(CONFIG_UART_1, &uartParams);
if (Gsm_uart == NULL) {
// UART_open() failed
while (1);
}
UART reading handle
void printBuffer() { buffer[buffer_index] = '\0'; // Null-terminate the buffer //Display_printf(display, 0, 0, "%s", buffer); // Print the buffer as a string strcat(UART_READ, buffer); buffer_index = 0; // Reset buffer index for next data } int readGSMUART(char *output, size_t max_length, int timeout_ms) { unsigned long start_time = Timer_getMillis(); while (Timer_getMillis() - start_time < timeout_ms) { if (UART_read(Gsm_uart, &input, 1) > 0) { if (input >= 32 && input <= 126) { buffer[buffer_index++] = input; // Store the character in the buffer if (buffer_index >= MAX_BUFFER_SIZE - 1) { printBuffer(); } } else if (input == '\n' || input == '\r') { printBuffer(); // Handle newline or carriage return if (strlen(UART_READ) > 0) { // Check if the response is complete (usually by checking for specific patterns or length) if (strstr(UART_READ, "OK") || strstr(UART_READ, "ERROR") || strstr(UART_READ, ">") || (strlen(UART_READ) >= max_length - 1)) { strncpy(output, UART_READ, max_length - 1); // Copy to output output[max_length - 1] = '\0'; // Ensure null-terminated string memset(UART_READ, 0, MAX_BUFFER_SIZE); return 1; // Successfully read response } } } } } if (strlen(UART_READ) > 0) { removeOKFromResponse(UART_READ); strncpy(output, UART_READ, max_length - 1); // Copy to output output[max_length - 1] = '\0'; // Ensure null-terminated string memset(UART_READ, 0, MAX_BUFFER_SIZE); return 1; // Successfully read response } output[0] = '\0'; // In case of timeout or failure Display_printf(display, 0, 0, "UART_READ TIMEOUT or FAILURE\n"); return 0; }
Hello,
The CC3220MODASF uses the UART2 driver, documentation for the driver can be found here.
You can also reference our UART examples
Best.
Rogelio