Random Symbols in Tera Term/Putty Window when Printing using UART

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I am using ADC to monitor the voltage of an analog input value to my BLE Pioneer Kit. I want to print the voltage value every 10 milliseconds. When I click the program button while in the main.c file under source code, the program doesn't seem to start right away. Only after a few minutes does "Voltage is 0 mV" start to print in Tera Term. After printing for about 30 seconds, symbols begin to appear in the Tera Term window. I've attached a text file of the serial data that prints to Tera Term. I've made sure that the baud rates match in tera term and in the ADC settings. The code that I use in main.c is below. Any idea what the problem might be?

   

/* ========================================
 *
 * Copyright YOUR COMPANY, THE YEAR
 * All Rights Reserved
 * UNPUBLISHED, LICENSED SOFTWARE.
 *
 * CONFIDENTIAL AND PROPRIETARY INFORMATION
 * WHICH IS THE PROPERTY OF your company.
 *
 * ========================================
*/
#include "project.h"
#include "stdio.h"

   

 

   

int main()

   

{
   ADC_Start(); //start ADC
   float x; 
   char tempStr[10];
    
   CyGlobalIntEnable; /* Enable global interrupts. */
   UART_Start(); //Starts Serial communication
    
   ADC_StartConvert(); //Starts ADC Conversion

   

//infinite Loop begins to acquire voltage values

   

 

   

    for (;;)
    {
  
    ADC_IsEndConversion(ADC_WAIT_FOR_RESULT); //Waits for ADC value to be calculated   

   

    x=ADC_GetResult16(0); //Sets x to the value of channel 0 (analog input channel is channel 0)
    
   float y = (ADC_CountsTo_mVolts(0,x)); //converts ADC value to millivolts
   int n = y;
   
    sprintf(tempStr, " Voltage is %-d mV", n);
    
    UART_UartPutString(tempStr); //Sends string with mV value to UART
    UART_UartPutString("\r\n");
    
   CyDelay(10); //Delay before reading next value

   

    }
}

   

/* [] END OF FILE */

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
cadi_1014291
Level 6
Level 6
25 likes received 10 likes received 10 likes given

Hi,

   

Find attached a project i used to read an analog pin and send the value via UART to the PC. I used the bridge between the PSoC4BLE module and the KitProg for UART <-> PC communication, the kit is configured to work on 3.3v.

   

The UART is 115200 bps and 8n1, so configure the terminal on your PC using the same parameters.

   

On your code i see some issues, you are casting a float to a int, tempStr is small, i should increase it to 20 elements.

   

Let me know if the attached project works for you.

View solution in original post

0 Likes
4 Replies
lock attach
Attachments are accessible only for community members.
cadi_1014291
Level 6
Level 6
25 likes received 10 likes received 10 likes given

Hi,

   

Find attached a project i used to read an analog pin and send the value via UART to the PC. I used the bridge between the PSoC4BLE module and the KitProg for UART <-> PC communication, the kit is configured to work on 3.3v.

   

The UART is 115200 bps and 8n1, so configure the terminal on your PC using the same parameters.

   

On your code i see some issues, you are casting a float to a int, tempStr is small, i should increase it to 20 elements.

   

Let me know if the attached project works for you.

0 Likes
Anonymous
Not applicable

Thanks so much got it to work.

0 Likes
Anonymous
Not applicable

One quick question. The code works great, but when there is no analog input, voltage high is printed (3.3V). Is there a way to get the code to print 0V when there is no connection to the analog input? Thanks.

0 Likes
Anonymous
Not applicable

You can try changing the "Initial Drive State" under the ADC_in1 analog input pin to "Low (0)". Otherwise, you would be manipulating the adc readings and trying to predict whether the adc readings are accurate or not without any feedback from the hardware to tell if a device is connected or not.