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.

TM4C1292NCPDT: Problems with UART transmission

Part Number: TM4C1292NCPDT
Hello!

I have a problem with the UART transmission of my microcontroller, when sending data through the UART0 
and observing it in the TERMITE terminal, some data strings are cut in half (image 1) or with spaces in the strings (image 2), could you give me any suggestions to solve this? :) Mayra

Image 1
Image 1


image 2
image 2

  • Hello Mayra,

    Have you checked that your UART configuration matches the configuration your terminal window?

    Also can you try another Terminal software like TeraTerm? While I don't think it's quite related in this case I've had some quirks with Termite display before.

    Best Regards,

    Ralph Jacobi

  • Hello!

    I've checked the Termite configs and they look fine, 
    I've also tried TeraTerm and the data also looks messy.
    mayra


  • Hi Mayra,

    Can you send the code you are using so I can run it on my board? It will be easiest for me if I can debug it that way.

    https://e2e.ti.com/support/site-support-group/site-support/f/site-support-forum/812271/faq-how-do-i-add-a-code-snippet-to-my-post

    Best Regards,

    Ralph Jacobi

  • #include <stdint.h>
    #include <stdbool.h>
    #include <string.h>
    #include <math.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include "inc/hw_types.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_gpio.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/gpio.h"
    #include "driverlib/adc.h"
    #include "driverlib/debug.h"
    #include <driverlib/uart.h>
    #include <driverlib/interrupt.h>
    #include "inc/hw_ints.h"          //librería para interrupciones
    #include <stdbool.h>
    
    #define NORM_MSG_LEN    26
    #define ERR_MSG_LEN     8
    
    uint32_t g_ui32SysClock; //variable para configurar el reloj del microcontrolador
    uint32_t ui32Status;
    
    uint32_t buffer_ADC[24]; // arreglo para guardar datos entrantes del ADC
    //uint32_t pui32ADC0Value[20];
    
    
    
    volatile int i_rx=0;
    volatile bool flag_rx=false;
    char BUFFER_UART[27];
    char BUFFER[27];
    int i_Rx=0,lim=0;
    int i_y=0;
    int flagUART_P=0;
    
    int coincidencia=0;
    int impedimenta=0;
    int lumos=0, t=0;
    char S_P1 [] = "?V913\r\n";//solicitud de respuesta al Edwards para el sensor de presion 1
    char S_P2 [] = "?V914\r\n";//solicitud de respuesta al Edwards para el sensor de presion 2
    char S_P4 [] = "!S925 5\r\n";//Instrucción para subir o bajar el contraste a la pantalla del edwards
    int recepcion=0;
    int contadordeborrado=0;
    int flag_UART=0; //bandera para detectar coincidencia entre las posiciones del arreglo
    float a,b,c,d,e,E,F,G,H,p1,p=0;
    int bandera=0,banderanum;
    float arregloP[2]; //arreglo para guardar los datos de presion
    
    
     float arreglo[12]; //arreglo para guardar los datos de los termistores
     float vol_T=0.0; //guarda el dato de voltaje
     float RT=0.0;//guarda el dato de resistencia del termistor
     float mu_T; //guarda el promedio de muestreo del adc
     float T=0.0;//guarda el dato de temperatura
    
    
    //-----------------------------------------------------------------------------------------------------------------
    //                                               ADC
    //------------------------------------------------------------------------------------------------------------------
    
     //función de autoria propia
     void INIT_ADC() //inicializa el ADC
     {
         SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); //habilita el periferico para ADC0
         SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
         while(!SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0));
    
         GPIOPinTypeADC(GPIO_PORTE_BASE,GPIO_PIN_3); //PINES PARA ENTRADA ADC0
       //ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR,0);
     }
    
     //Función copiada
     void TEMP_TERMISTOR() //configura la secuencia de muestreo del adc y procesa los datos entrantes del adc
     {
        int i_adc;
    
        for(i_adc=0; i_adc<12; i_adc++)
         {
            ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR,0);
            ADCSequenceStepConfigure(ADC0_BASE, 0,0, i_adc);//(paso 1)
            ADCSequenceStepConfigure(ADC0_BASE, 0,1, i_adc);//(paso 2)
            ADCSequenceStepConfigure(ADC0_BASE, 0,2, i_adc);//(paso 3)
            ADCSequenceStepConfigure(ADC0_BASE, 0,3, i_adc);//(paso 4)
            ADCSequenceStepConfigure(ADC0_BASE, 0,4, i_adc);//(paso 5)
            ADCSequenceStepConfigure(ADC0_BASE, 0,5, i_adc);//(paso 6)
            ADCSequenceStepConfigure(ADC0_BASE, 0,6, i_adc);//(paso 7)
            ADCSequenceStepConfigure(ADC0_BASE, 0,7, i_adc|ADC_CTL_IE|ADC_CTL_END);//(paso 8)
    
            ADCSequenceEnable(ADC0_BASE,0);
            ADCIntClear(ADC0_BASE,0); //limpia las banderas de interrupción del ADC
            ADCProcessorTrigger(ADC0_BASE,0); //Causa un trigger para una secuencia de muestreo
            while(!ADCIntStatus(ADC0_BASE,0,false)) //indica el estado de las interrupciones
              {
    
              }
            ADCSequenceDataGet(ADC0_BASE,0,buffer_ADC);//obtiene los datos capturados por el adc
    
             mu_T=(buffer_ADC[0]+buffer_ADC[1]+buffer_ADC[2]+buffer_ADC[3]+buffer_ADC[4]+buffer_ADC[5]+buffer_ADC[6]+buffer_ADC[7])/8;
             vol_T=mu_T*3.3/4096; //aqui hubo breakpoint
             RT=((3900*(3.3-vol_T))/vol_T);
             T=(1/(0.000634544+(0.000321866*log(RT))+(-0.000000306*pow(log(RT),3))))-273.15;//aqui hubo breakpoint
    
             arreglo[i_adc]=T; //aqui hubo breakpoint
          }
     }
    //---------------------------------------------------------------------------------------------------------------
    //                                                  UART
    //----------------------------------------------------------------------------------------------------------------
    
     void INIT_UART() //HABILITA LOS MÓDULOS UART0 Y UART1
     {
         SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2);//Habilitación del módulo UART2
         SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
         SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);//Habilitación del módulo UART1 (Recepción y transmisión de datos de presión)
         SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
         SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);//Habilitación del módulo UART0 (conexión USB)
         SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
         while(!SysCtlPeripheralReady(SYSCTL_PERIPH_UART1));
         GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_6 | GPIO_PIN_7); //Configurar los pines a usar en UART0
         GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); //Configurar los pines a usar en UART1
         GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); //Configurar los pines a usar en UART0
     }
    
     void CONFIG_UART()
     {
         //ASIGNACIÓN DE PINES? RX y TX
         GPIOPinConfigure(GPIO_PA6_U2RX); //Configurar terminal de RX UART2
         GPIOPinConfigure(GPIO_PA7_U2TX); //Configurar terminal de TX UART2
         GPIOPinConfigure(GPIO_PB0_U1RX); //Configurar terminal de RX UART1
         GPIOPinConfigure(GPIO_PB1_U1TX); //Configurar terminal de TX UART1
         GPIOPinConfigure(GPIO_PA0_U0RX); //Configurar terminal de RX UART0
         GPIOPinConfigure(GPIO_PA1_U0TX); //Configurar terminal de TX UART0
    
    
         //configuración de dirección del puerto UART, reloj del modulo, baudrate, tamaño de bit y bit de paridad
         UARTConfigSetExpClk(UART2_BASE,g_ui32SysClock,9600,(UART_CONFIG_WLEN_8|UART_CONFIG_STOP_ONE|UART_CONFIG_PAR_NONE)); //configuración de dirección del puerto UART1
         UARTConfigSetExpClk(UART1_BASE,g_ui32SysClock,9600,(UART_CONFIG_WLEN_8|UART_CONFIG_STOP_ONE|UART_CONFIG_PAR_NONE)); //configuración de dirección del puerto UART1
         UARTConfigSetExpClk(UART0_BASE,g_ui32SysClock,9600,(UART_CONFIG_WLEN_8|UART_CONFIG_STOP_ONE|UART_CONFIG_PAR_NONE)); //configuración de dirección del puerto UART0
    
    
         IntEnable(INT_UART2);     //habilitación de interrupción por UART1
         UARTIntEnable(UART2_BASE,UART_INT_RX);  //habilitar interrupción por recepción y transmision UART1
         IntEnable(INT_UART1);     //habilitación de interrupción por UART1
         UARTIntEnable(UART1_BASE,UART_INT_RX);  //habilitar interrupción por recepción y transmision UART1
         IntEnable(INT_UART0);     //habilitación de interrupción por UART0
         UARTIntEnable(UART0_BASE,UART_INT_RX|UART_INT_RT);  //habilitar interrupción por recepción y transmision  UART0
         IntMasterEnable(); //Habilita las interrupciones globales
     }
    
    void sendDataUART1(uint32_t c) //envia la petición de respuesta al sensor de presión por UART1 al Edwards dato por dato
    {
        UARTCharPut(UART1_BASE, c);
    }
    
    void sendStringUART1(char* txt) //envia la petición de respuesta al sensor de presión por UART1 al Edwards dato en arreglo
    {
      while(*txt!=0x00)
        {
            sendDataUART1(*txt);
            txt++;
        }
    }
    
    void sendDataUART0(uint32_t c) //envia la petición de respuesta al sensor de presión por UART0 al Edwards dato por dato
    {
        UARTCharPut(UART0_BASE, c);
    }
    
    void sendStringUART0(char* txt) //envia la petición de respuesta al sensor de presión por UART0 al Edwards en arreglo
    {
       while(*txt!=NULL)
        {
            sendDataUART0(*txt);
            txt++;
        }
    }
    
    
    //función de autoria propia
    void convertir_hexadecimal(uint32_t ui32Base, float number)
    {
          int32_t entero;
       // uint32_t entero;
          float auxiliar;
          uint32_t decimal;
        //char digito;
          char ad;
          char ad2;
    
    
         if(number>0) //coloca el signo (si es mayor o menor a cero) a la temperatura
            {
              UARTCharPut(ui32Base,0x2B);//+
            }
       else
           {
             UARTCharPut(ui32Base,0x2D);//-
             number=number*-1;
           }
    
          auxiliar=number;
          entero=number;
          decimal=(auxiliar-entero)*100;
    
    
        //AQUI VA LA CONVERSIÓN DE LA PARTE ENTERA A HEXADECIMAL
           UARTCharPut(ui32Base,(char)(entero));
           ad=(char)(entero);
           UARTCharPut(ui32Base,0x2E);//.
        //AQUI VA LA CONVERSIÓN DE LA PARTE DECIMAL A HEXADECIMAL
           UARTCharPut(ui32Base,(char)(decimal));
           ad2=(char)(decimal);
    }
    
    //funcion de autoria propia
    void cabecera(uint32_t ui32Base, char letra)  //envía los datos en formato hexadecimal T+0x32.0x87
    {
        int y=0, z=0;
        switch(letra)
           {
            case 'I':
               UARTCharPut(ui32Base,0x49);//cabecera para corriente (I)
    
            break;
    
            case 'P':
    
              if(arregloP[0]!=0x00 && arregloP[1]!=0x00)
                {
                   UARTCharPut(ui32Base,0x50);//cabecera para presion (P)
    
                      for(z=0;z<2;z++)//envia los datos de temperatura
                       {
                         convertir_hexadecimal(UART0_BASE,arregloP[z]);//manda a llamar a la funcion convertir_hexadecimal2
                       }
                      UARTCharPut(UART0_BASE,0x0A);//salto de linea
               }
    
            break;
    
            case 'R':
               UARTCharPut(ui32Base,0x52);//cabecera para el RTD (R)
            break;
    
            case 'T':
               UARTCharPut(UART0_BASE,0x0A);//salto de linea
               UARTCharPut(ui32Base,0x54);//cabecera para el termistor(T)
               for(y=0;y<12;y++)//envia los datos de temperatura
                  {
                     convertir_hexadecimal(UART0_BASE,arreglo[y]);//manda a llamar a la funcion convertir_hexadecimal
                  }
               UARTCharPut(UART0_BASE,0x0D);//retorno de carro
            break;
    
            case'V':
               UARTCharPut(ui32Base,0x56);//V para el volaje
            break;
    
            default:
    
                break;
    
            //default, que no haga algo
          }
    }
    
    //-----------------------------------------------------------------------------------------------------------------
    //                                                  TERMISTOR
    //-----------------------------------------------------------------------------------------------------------------
    
    
    //------------------------------------------------------------------------------------------------------------------
    //                                                   RTD
    //------------------------------------------------------------------------------------------------------------------
    
    
    
    
    //-----------------------------------------------------------------------------------------------------------------
    //                                                  PRESION
    //-----------------------------------------------------------------------------------------------------------------
    
    
    //función para limpiar los buffer y el contador de UART
    void clear_variables()
    {
      i_rx=0; //pone en cero el contador
      lumos=0;
      impedimenta=0;
        for(i_Rx=0;i_Rx<=25;i_Rx++)
          {
            BUFFER_UART[i_Rx]=0;    //Limpia el buffer de UART     breakpoint
            BUFFER[i_Rx]=0;         //Limpia el buffer de proceso
          }
    }
    
    
    //Procesa los datos de presión
    void calculo()
    {
    
        if ( BUFFER[6]>=0x30 && BUFFER[6] <= 0x39 ) banderanum=1; //verifica que el dato en la posición [6] sea un numero
    
          t=8;
         do
          {
            if(BUFFER[t]>=0x30 && BUFFER[t] <= 0x39)////verifica que los datos desde la posición [8] a [11] sean numeros
             {
               banderanum=1;// bandera se pone en 1
             }
             else
              {
                banderanum=0; // bandera se pone en 0
              }
             t++;
          }while(t<=11);
    
         if(banderanum==1) //si los datos son mumeros
         {
           if(BUFFER[15] >=0x30 && BUFFER[15] <= 0x39 ) bandera=1;// verifica que el dato en la posición [15] sea un numero
         }
    
    
         if(banderanum==1)
         {
    
                if(bandera==1)
                 {                   //resta 48 a los datos del arreglo para convertir los caracteres en numeros
                   a=1*(BUFFER[6]-48);// numero*1=numero
                   b=0.1*(BUFFER[8]-48); //numero*0.1=0.numero
                   c=0.01*(BUFFER[9]-48);//numero*0.01=0.0numero
                   d=0.001*(BUFFER[10]-48);//numero*0.001=0.00numero
                   e=0.0001*(BUFFER[11]-48);//numero*0.0001=0.000numero
                   G=BUFFER[15]-48; // exponente de la presion
                   E=a+b+c+d+e; //suma los numeros
                   //G=ver[15]-48;
                   F=pow(10,G);//eleva el 10 al exponente de la presion
    
                  if(BUFFER[13]==0x2D) //breakpoint (posición [13] del arreglo) si el signo de la presión es negativo
                   {
                      p1=E/F; //breakpoint presion en el sensor 1 = suma de los numeros dividido entre el exponente de la presion
                      p=p1/1000;//breakpoint
                     // convertir_hexadecimal(UART0_BASE, p1);
    
                   }
                   else if (BUFFER[13]==0x2B)  //(posición [13] del arreglo) si el signo de la presión es positivo
                   {
                      p1=E*F; //presion en el sensor 2 = suma de los numeros multiplicado por el exponente de la presion
                      p=p1/1000;//breakpoint
    
                   }
    
                }
              if(contadordeborrado==0)
              {
                  arregloP[0]=p;
              }
              else if(contadordeborrado==1)
              {
                  arregloP[1]=p;
              }
           }
    }
    
    
    //Guarda los datos procedentes del UART en un nuevo arreglo y vacía los buffer
    void GUARDA_ARREGLO()
    {
        if(lumos==1)
         {
           if(BUFFER_UART[0]==0x3D && BUFFER_UART[18]==0x39)//compara si la posicion 0 del arreglo es = y la posición 19 es ;
              {
                coincidencia=1; //breakpoint pone en uno la bandera de coincidencia
                flag_UART=1;   //pone en uno la bandera de flag_UART
                i_rx=0;   //reinicia el contador
              }
           else
              {
    
                clear_variables(); //limpia los buffer y reinicia el contador i_rx
              }
         }
    
        if(flag_UART==1)
          {
              flag_UART=0; //breakpoint
             if(coincidencia==1)//si la posición 0 y 25 del arreglo entrante son iguales
              {
                 coincidencia=0;
                 i_rx=0; //reinicia el contador
                 for(i_y=0;i_y<=25;i_y++)//Guarda el contenido del buffer de uart en un buffer para procesar los datos
                     {
                       BUFFER[i_y]=BUFFER_UART[i_y];
                     }
                      calculo();
               }
             else
              {
                 clear_variables(); //limpia los buffer y reinicia el contador i_rx
              }
    
             contadordeborrado++;
             if(contadordeborrado==2) contadordeborrado=0;//lleva el conteo de las posiciones del arreglo de presion
         }
    
         clear_variables();
    
    //Limpia los buffer y el contador cuando la trama es erronea o está cortada.
    
            if(BUFFER_UART[0]==0x2A) //compara si la posicion 0 del arreglo es igual a "*"
            {
                clear_variables(); //limpia los buffer y reinicia el contador i_rx
            }
    }
    
    
    
    //----------------------------------------------------------------------------------------------------------------------------
    //                                             MAIN
    //----------------------------------------------------------------------------------------------------------------------------
    int main(void)
    {
       //configurar el reloj del microcontrolador
         g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN |SYSCTL_USE_PLL |SYSCTL_CFG_VCO_240), 120000000);//120 MHz
    
        INIT_ADC(); //inicializa el ADC
        INIT_UART();
        CONFIG_UART();
      //sendStringUART1(S_P4);
    
        while(1)
       {
          TEMP_TERMISTOR();//configura las caracteristicas de las funciones de ADC del micro y procesa los datos entrantes a temperatura
          SysCtlDelay(10000);
          sendStringUART1(S_P1);
          SysCtlDelay(21000000);//514ms
          GUARDA_ARREGLO();
          SysCtlDelay(10000000);//514ms
          sendStringUART1(S_P2);
          SysCtlDelay(21000000);//514ms
          GUARDA_ARREGLO();
          SysCtlDelay(17000000);//514ms
          cabecera(UART0_BASE,0x54);// Manda a llamar a la funcion "cabecera"
          cabecera(UART0_BASE,0x50);
       }
    }
    
    //------------------------------------------------------------------------------------------------------------------------------
    //                                              ISR
    //------------------------------------------------------------------------------------------------------------------------------
    
    //i_rx=0;
    //int variable=0;
    void ISR_UART0(void)
    {
    
    
    }
    
    void ISR_UART1(void)
    {
        ui32Status = UARTIntStatus(UART1_BASE,true);
           UARTIntClear(UART1_BASE, ui32Status);        //limpia las banderas de interrupción?
    
           if (UARTCharsAvail(UART1_BASE))
           {
               char rxData = UARTCharGetNonBlocking(UART1_BASE); //recibe el dato UART entrante
    
               if (flag_rx)
               {
                   if (rxData == 0x0D)
                   {
                       flag_rx = false;
                   }
                   BUFFER_UART[i_rx++]=rxData;// Guarda el dato recibido en un arreglo
               }
               else
               {
                   if (rxData == '=')
                        {
                          flag_rx = true;
                          i_rx = 0;
                          BUFFER_UART[i_rx++]=rxData;// Guarda el dato recibido en un arreglo
                         }
               }
               impedimenta=1; //breakpoint
           }//cierra if(charsAvail)
           lumos=1; //breakpoint
    }
    
    void ISR_UART2(void)
    {
    
    }
    //
    

    Hi!

    This is my code!

    Mayra

  • Hello Mayra,

    Thanks, I was hoping to easily run the code and replicate it but I am not sure that will be simple here. If I am reading the code correctly, you are at times receiving UART messages which dictates the UART output as well?

    If so, I won't be able to fully replicate your system setup.

    Though knowing that then brings a different question of whether or not the areas you see erroneous output are related to something received over UART, something related to the thermistor reading, or something related to static messages that are stored in the device? 

    Best Regards,

    Ralph Jacobi

  • Hello!
    
    Yes, the microcontroller using the UART1, sends a response request to an external device (S_P1), 
    this device is a pressure controller that takes 500 milliseconds to respond, therefore the microcontroller
    waits 500 milliseconds, and calls the function GUARDA_ARREGLO() to process the data it received from the
    external device. Then it sends another response request (S_P2) , waits 500 milliseconds and calls the GUARDA_ARREGLO()
    function, this is because it requests the pressure from two different sensors. The data from both pressure sensors is
    sent by UART0 as a string starting with the letter "P". There is a temperature sensor (thermistor) whose value is received by the microcontroller through the ADC,
    in total there are 12 thermistors but at the moment I am only testing with 1. The temperature data processed
    by the program is sent through the UART0 in a data string starting with the letter "T", Pressure and temperature data strings are sent out the UART0 to display the data in the LABVIEW interface. I hope I have explained myself correctly, Best regards, Mayra
    
    
  • Hello Mayra,

    Yeah that mostly makes sense - enough to give me sufficient idea about the application.

    So looking at the source code and understanding that its based on measurements and such, I think what's happening is that since you are just sending the raw characters over UART, sometimes your data ends up being a character that the terminal displays as a space or as a line feed instead of outputting the hex value.

    I think if you use a function like UARTprintf where you can specify how you want the string to be output, you would be able to avoid that sort of issue occurring.

    One thing you could do to check for this is to have a little check and run a counter with how many times something like '0x20' (Space) gets sent and see if you run it and see 4 messages with spaces and the counter reads 4 then... that'd explain the output you are seeing and you can then try and account for that?

    That's my leading guess at this point given the code seems to be pretty well written with the right initializations and the I don't think there are any buffer overflow or data corruption issues. I think it's just a case of the raw character printing causing the terminal to take some data and instead output it not as a raw hex value but interpret it otherwise.

    Best Regards,

    Ralph Jacobi

  • hi!
    
    Excuse me, could you explain the suggestions a little more?

    Best Regards. Mayra
  • Hello Mayra,

    Effectively what I think is happening is at times you receive a data value of 0x20.

    When you send 0x20 to Termite with UARTCharPut, it just prints a space instead of displaying the data value.

    So my suggestion is to check if you are sending 0x20 as data like by looking at the data before you send it and increment a counter is the data value equals 0x20. If so that would explain the problem.

    Then you can resolve the problem by using UARTprintf.

    Best Regards,

    Ralph Jacobi

  • Hi!
    
    I tried with UARTprintf() but it does not send anything to the terminal, 
    the libraries are recognized in the program and also the function, but the test phrase does not appear in the terminal.

    Mayra



    Sorry if I have many doubts, I don't have much experience programming :(
    
    
     
  • Hi Mayra,

    You will need to initialize the UART differently before you can use that call. UARTStdioConfig needs to be called to allow the UART stdio functions to know which UART to use. See the following code snippet.

    void prvConfigureUART(void)
    {
        /* Enable GPIO port A which is used for UART0 pins.
         * TODO: change this to whichever GPIO port you are using. */
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    
        /* Configure the pin muxing for UART0 functions on port A0 and A1.
         * This step is not necessary if your part does not support pin muxing.
         * TODO: change this to select the port/pin you are using. */
        GPIOPinConfigure(GPIO_PA0_U0RX);
        GPIOPinConfigure(GPIO_PA1_U0TX);
    
        /* Enable UART0 so that we can configure the clock. */
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    
        /* Use the internal 16MHz oscillator as the UART clock source. */
        UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    
        /* Select the alternate (UART) function for these pins.
         * TODO: change this to select the port/pin you are using. */
        GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
        /* Initialize the UART for console I/O. */
        UARTStdioConfig(0, 115200, 16000000);
    }

    Best Regards,

    Ralph Jacobi

  • Hi!
    Thanks for the code snippet. I tried the UARTprintf() function but still the strings get cut off :(

     Best regards
    Mayra  
  • Hello Mayra,

    Can you post the UARTprintf function as you are using it in your application? 

    Best Regards,

    Ralph Jacobi

  • Hello!
    
    I added the UARTStdioConfig() function in the CONFIG_UART() 
    function that configures the UART functions, I also replaced the UARTCharPut()
    function with UARTPrintf() in the "cabecera" and "convertir_hexadecimal" functions.
    void CONFIG_UART()
     {
         //ASIGNACIÓN DE PINES? RX y TX
         GPIOPinConfigure(GPIO_PA6_U2RX); //Configurar terminal de RX UART2
         GPIOPinConfigure(GPIO_PA7_U2TX); //Configurar terminal de TX UART2
         GPIOPinConfigure(GPIO_PB0_U1RX); //Configurar terminal de RX UART1
         GPIOPinConfigure(GPIO_PB1_U1TX); //Configurar terminal de TX UART1
         GPIOPinConfigure(GPIO_PA0_U0RX); //Configurar terminal de RX UART0
         GPIOPinConfigure(GPIO_PA1_U0TX); //Configurar terminal de TX UART0
    
    
         //configuración de dirección del puerto UART, reloj del modulo, baudrate, tamaño de bit y bit de paridad
         UARTConfigSetExpClk(UART2_BASE,g_ui32SysClock,9600,(UART_CONFIG_WLEN_8|UART_CONFIG_STOP_ONE|UART_CONFIG_PAR_NONE)); //configuración de dirección del puerto UART1
         UARTConfigSetExpClk(UART1_BASE,g_ui32SysClock,9600,(UART_CONFIG_WLEN_8|UART_CONFIG_STOP_ONE|UART_CONFIG_PAR_NONE)); //configuración de dirección del puerto UART1
         UARTConfigSetExpClk(UART0_BASE,g_ui32SysClock,9600,(UART_CONFIG_WLEN_8|UART_CONFIG_STOP_ONE|UART_CONFIG_PAR_NONE)); //configuración de dirección del puerto UART0
    
    
         IntEnable(INT_UART2);     //habilitación de interrupción por UART1
         UARTIntEnable(UART2_BASE,UART_INT_RX);  //habilitar interrupción por recepción y transmision UART1
         IntEnable(INT_UART1);     //habilitación de interrupción por UART1
         UARTIntEnable(UART1_BASE,UART_INT_RX);  //habilitar interrupción por recepción y transmision UART1
         IntEnable(INT_UART0);     //habilitación de interrupción por UART0
         UARTIntEnable(UART0_BASE,UART_INT_RX|UART_INT_RT);  //habilitar interrupción por recepción y transmision  UART0
         IntMasterEnable(); //Habilita las interrupciones globales
         UARTStdioConfig(0,9600,120000000);
     }
    
    
    void convertir_hexadecimal(float number)
    {
          int32_t entero;
       // uint32_t entero;
          float auxiliar;
          uint32_t decimal;
        //char digito;
          char ad;
          char ad2;
    
    
         if(number>0) //coloca el signo (si es mayor o menor a cero) a la temperatura
            {
              //+
              UARTprintf("\%c",0x2B);
            }
       else
           {
             //-
             UARTprintf("\%c",0x2D);
             number=number*-1;
           }
    
          auxiliar=number;
          entero=number;
          decimal=(auxiliar-entero)*100;
    
    
        //AQUI VA LA CONVERSIÓN DE LA PARTE ENTERA A HEXADECIMAL
          // UARTCharPut(ui32Base,(char)(entero));
           UARTprintf("\%c",(char)(entero));
           ad=(char)(entero);
         //  UARTCharPut(ui32Base,0x2E);//.
           UARTprintf("\%c",0x2E);
        //AQUI VA LA CONVERSIÓN DE LA PARTE DECIMAL A HEXADECIMAL
         //  UARTCharPut(ui32Base,(char)(decimal));
           UARTprintf("\%c",(char)(decimal));
           ad2=(char)(decimal);
    }
    
    void cabecera(char letra)  //envía los datos en formato hexadecimal T+0x32.0x87
    {
        int y=0, z=0;
        switch(letra)
           {
            case 'I':
              //cabecera para corriente (I)
               UARTprintf("\%c",0x49);
    
            break;
    
            case 'P':
    
    
               if(arregloP[0]!=0x00 && arregloP[1]!=0x00)
                {
                  //cabecera para presion (P)
                   UARTprintf("\%c",0x50);
    
                      for(z=0;z<2;z++)//envia los datos de temperatura
                       {
                         convertir_hexadecimal(arregloP[z]);//manda a llamar a la funcion convertir_hexadecimal2
                       }
                     //salto de linea
                      UARTprintf("\%c",0x0A);
               }
             break;
    
            case 'R':
               //cabecera para el RTD (R)
               UARTprintf("\%c",0x52);
            break;
    
            case 'T':
    
             //salto de linea
               UARTprintf("\%c",0x0A);
             //cabecera para el termistor(T)
               UARTprintf("\%c",0x54);
               for(y=0;y<3;y++)//envia los datos de temperatura
                  {
                     convertir_hexadecimal(arreglo[y]);//manda a llamar a la funcion convertir_hexadecimal
                  }
               //retorno de carro
              UARTprintf("\%c",0x0D);
    
            break;
    
            case'V':
             //V para el volaje
               UARTprintf("\%c",0x56);
            break;
    
            default:
    
                break;
    
            //default, que no haga algo
          }
    }
    
    
    int main(void)
    {
       //configurar el reloj del microcontrolador
         g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN |SYSCTL_USE_PLL |SYSCTL_CFG_VCO_240), 120000000);//120 MHz
    
        INIT_ADC(); //inicializa el ADC
        INIT_UART();
        CONFIG_UART();
      //sendStringUART1(S_P4);
    
      //  int holaa=3;
    
        while(1)
       {
    
          TEMP_TERMISTOR();//configura las caracteristicas de las funciones de ADC del micro y procesa los datos entrantes a temperatura
          SysCtlDelay(10000);
          sendStringUART1(S_P1);
          SysCtlDelay(21000000);//514ms
          GUARDA_ARREGLO();
          SysCtlDelay(10000000);//514ms
          sendStringUART1(S_P2);
          SysCtlDelay(21000000);//514ms
          GUARDA_ARREGLO();
          SysCtlDelay(17000000);//514ms
    
          cabecera(0x54);//Manda a llamar a la funcion "cabecera" (T)
          cabecera(0x50);//Manda a llamar a la funcion "cabecera" (P)
    
       }
    }
    
    

    
    
  • Hello Mayra,

    Okay that's what I expected to see as far as the UARTprintf calls. Unfortunately the way you have that set up is no different from how you did it before. Printing a character will prompt the terminal to break up the display if you send certain characters over UART.

    To demonstrate this, I filled a 50 byte buffer with 'data' that starts at 0x00 and ends at 0x49.

    I then output that buffer in two manners. The first is using the %c to send a character:

        for(ui32LoopCount=0; ui32LoopCount<50; ui32LoopCount++)
        {
            UARTprintf("[ 0x%c ]", ui32DataBuffer[ui32LoopCount]);
        }

    The resulting output of the data was the following:

    [ 0x ][ 0x[01] ][ 0x[02] ][ 0x[03] ][ 0x[04] ][ 0x[05] ][ 0x[06] ][ 0x[07] ][ 0x[08] ][ 0x ][ 0x
    ][ 0x[0B] ][ 0x[0C] ][ 0x
    ][ 0x[0E] ][ 0x[0F] ][ 0x[10] ][ 0x[11] ][ 0x[12] ][ 0x[13] ][ 0x[14] ][ 0x[15] ][ 0x[16] ][ 0x[17] ][ 0x[18] ][ 0x[19] ][ 0x[1A] ][ 0x[1B] ][ 0x[1C] ][ 0x[1D] ][ 0x[1E] ][ 0x[1F] ][ 0x ][ 0x! ][ 0x" ][ 0x# ][ 0x$ ][ 0x% ][ 0x& ][ 0x' ][ 0x( ][ 0x) ][ 0x* ][ 0x+ ][ 0x, ][ 0x- ][ 0x. ][ 0x/ ][ 0x0 ][ 0x1 ]

    You can see two broken lines, and it doesn't show on E2E but there was a space that was notable in there too from the tab character (I previously indicated I thought that was 0x20 for space but I was wrong, it's 0x09 which is tab that is doing that).

    Then I did the same but output the decimal value - i.e. the raw data value.

        for(ui32LoopCount=0; ui32LoopCount<50; ui32LoopCount++)
        {
            UARTprintf("[ 0x%d ]", ui32DataBuffer[ui32LoopCount]);
        }

    The resulting output of the data was now this:

    [ 0x0 ][ 0x1 ][ 0x2 ][ 0x3 ][ 0x4 ][ 0x5 ][ 0x6 ][ 0x7 ][ 0x8 ][ 0x9 ][ 0x10 ][ 0x11 ][ 0x12 ][ 0x13 ][ 0x14 ][ 0x15 ][ 0x16 ][ 0x17 ][ 0x18 ][ 0x19 ][ 0x20 ][ 0x21 ][ 0x22 ][ 0x23 ][ 0x24 ][ 0x25 ][ 0x26 ][ 0x27 ][ 0x28 ][ 0x29 ][ 0x30 ][ 0x31 ][ 0x32 ][ 0x33 ][ 0x34 ][ 0x35 ][ 0x36 ][ 0x37 ][ 0x38 ][ 0x39 ][ 0x40 ][ 0x41 ][ 0x42 ][ 0x43 ][ 0x44 ][ 0x45 ][ 0x46 ][ 0x47 ][ 0x48 ][ 0x49 ]

    So you have to use the right output format for UARTprintf to avoid getting linebreaks etc.

    Just for full illustration here is Termite after both outputs:

    Best Regards,

    Ralph Jacobi

  • Hi!
    
    Thanks for the suggestion, I tried changing the format code of the UARTprintf function, 
    it does send the complete strings. Excuse me, if it's not too much to ask, could you tell me why it's called "raw data"?
    Best Regards,

    Mayra
    
    
  • Hi Mayra,

    Sure. Raw data generally means any data that hasn't be processed / analyzed. Since you mentioned you were reading a thermistor which would mean that you are trying to get temperature data - but the output you had been showing was all hexadecimal characters and the issue was seemingly (and now confirmed to be) stemming from output characters that were not typical ASCII numbers/letters. So to me, that makes it look like the data hasn't been processed to convert the sensor reading into an actual temperature like '35 degrees Celsius'. I could be wrong about that, but that was just how it looked to me. Slight smile

    Best Regards,

    Ralph Jacobi