How to display data UART coming from another PsoC on LCD

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

cross mob
Anonymous
Not applicable

Hello,

   

I'm a student on internship and my teacher want me to use two PsoC in order to display the current and the voltage of a battery. The values are converted and sent by the UART of the first PsoC, received and handled by the second PsoC. I want to display these values on a LCD screen but all the program I've developed until now doesn't seems to work.

   

More specifically, the first PsoC convert  a data from float to ASCII using the function ftoa()  and send it to the second PsoC in order to display it on the LCD screen. The problem is that the value printed by the LCD doesn't match what I am supposed to have. 

   

I'm not using any development kit but instead, I'm using a PCB which was developed by my university.

   

Until now, I've managed to display a unsigned float variable.

   

The code below my message is supposed to store the data send by the Rx buffer  in a table and show the content of the table in the LCD Screen. But my LCD Screen display some hex value like : 

   

"F4000000000" for the first line 

   

"03072B2B00" for the second line.

   

What I expect is a value like : "11,4578"

   

Can you help me please ?

   

void main(void)
{
     
    char* strPtr; // Parameter pointer
    char tab [100];
    int i;
    int byte_length = 256;
 

   


    // Initialize receiver/cmd buffer
    UART_CmdReset(); 
    
     //Turn on interrupts
    M8C_EnableGInt ;
    
    
    //Enable RX interrupts
    UART_IntCntl(UART_ENABLE_RX_INT);       
    //set parity as zero and start the UART 
    UART_Start(UART_PARITY_EVEN);            
    LCD_1_Start();                  // Initialize LCD 
   
    //Clear the screen in Hyper terminal window
    UART_PutChar(12); 

   

    
        while(1) {
         UART_CmdReset();
   
        LCD_1_Position (0,0);
        LCD_1_PrCString ("tension :");

            
        LCD_1_Position (9,0);
       
            

   

            for (i=0;i<byte_length;i++)
            {
               //tab = UART_cGetChar ()/0xA; //test pour récupérer des caractere
                 strPtr = UART_cGetChar ()/0xA;
                //tab = UART_bReadRxData();
                //strPtr =& tab;
                //strPtr = &UART_aRxBuffer;
                //UART_aRxBuffer = UART_bReadRxData ();
               //tab = UART_iReadChar();    // Get a character from UART RX data register
            }  
            
            for (i=0;i<byte_length;i++) 
            {
                Delay10msTimes (50);
                //itoa(strPtr,tab,10);
                //LCD_1_PrString (strPtr);
                //LCD_1_WriteData (tab);
                //tab = tab/0xA;
                LCD_1_PrHexByte (tab);
                 UART_CmdReset();
            }
                    
        
       
       //Reset command buffer and flags
            UART_CmdReset();
    
    
    }
}

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the forum.

   

You are a bit wrong here, this is the PSoC5 forum which is a bit different from a PSoC1.

   

Your LCD shows hex characters because you use LCD_PrintHex().

   

As you stated, you already did a conversion at the first PSoC to ASCII, so you just need to send the received characters to the LCD.

   

The problem lies in the question: What character you send ends the number? Might be that you have to send something additional (\r or \n)

   

Next question: How will you distinguish in the stream of characters the Volts from the Amperes? Maybe you have to insert something before you send a value (V or A)

   

Now you can wait for a 'V' and fill a string with the next characters you receive until you get a '\r' (or whatever you chose)

   

This string you can send with a single API to your LCD.

   

 

   

Bob

View solution in original post

0 Likes
5 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the forum.

   

You are a bit wrong here, this is the PSoC5 forum which is a bit different from a PSoC1.

   

Your LCD shows hex characters because you use LCD_PrintHex().

   

As you stated, you already did a conversion at the first PSoC to ASCII, so you just need to send the received characters to the LCD.

   

The problem lies in the question: What character you send ends the number? Might be that you have to send something additional (\r or \n)

   

Next question: How will you distinguish in the stream of characters the Volts from the Amperes? Maybe you have to insert something before you send a value (V or A)

   

Now you can wait for a 'V' and fill a string with the next characters you receive until you get a '\r' (or whatever you chose)

   

This string you can send with a single API to your LCD.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Hello and thank you for welcoming me and for your quick answer.

   

I'm using two PsoC 5 device I've forgot to mention it in my last message so I think I'm in the right place.

   

My first goal is to display the voltage of a battery on LCD screen so the current value on UART isn't sent for the moment.

   

I assumed that I already converted the voltage value of my battery and that I've done the distinguish part because I've managed to show theses values on Hyperterminal. But when I handle this variable (even with a function different than LCD_PrintHex()) on the second PsoC, it shows some random static values like "00C8" or "420" depending on the LCD function I use (I will give to you some screen of the LCD Screen and the hyperterminal latter so you can understand the problem more clearly).

   

The code I've given previously is one  among other I've tried to resolve this issue.

   

Which API are you referring in your last sentence ? a UART module ?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The code you showed in your last post is for PSoC1 and Cypress PSoC Designer 5.4.

   

When you use PSoC5 you need to use PSoC Creator 4.0 as IDE.

   

The APIs I was referring to are indeed the UART APIs which you should read up in the datasheet.

   

Do not use LCD_PrintHex(), this is only meant to display numbers in hexadecimal format. Best for you on a PSoC5 will be to use formatted I/O which is supported when using #include <stdio.h>,  sprintf() and UART_PutString().

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I've used another approach to solve this problem by using the Uart example provided by PsoC.

   

I've managed to run the code example but when  I try to use it to display the value I want, there are some errors which display (see below) :

   


#include <m8c.h>        // part specific constants and macros
#include "PSoCAPI.h"    // PSoC API definitions for all User Modules
#include "delay.h"
#include "stdio.h"
#include "stdlib.h"

   


void main(void)
{
    int InputChar;
    char *strPtr; // Parameter pointer
    
    
    // Initialize receiver/cmd buffer
    UART_CmdReset(); 
    
     //Turn on interrupts
    M8C_EnableGInt ;
    
    Delay50uTimes (1);  
    //Enable RX interrupts
    UART_IntCntl(UART_ENABLE_RX_INT);       
    //set parity as zero and start the UART 
    UART_Start(UART_PARITY_NONE);            

   

   
    //Clear the screen in Hyper terminal window
    UART_PutChar(12); 
    
    
    while(1) {
        
         Delay10msTimes (10);                
                   
 
        if (UART_bCmdCheck()) {                  // Wait for command Terminator
            if( strPtr = UART_cGetChar()  ) {     // More than delimiter?
                LCD_1_PrString(strPtr); // Print out command
                
                // loop on each parameter till a null pointer is returned
                while(strPtr = UART_cGetChar()) { 
                    UART_PutString(strPtr); // Print each parameter
                    UART_CPutString(">\r\n");
                }   
            }
            
            //Reset command buffer and flags
            UART_CmdReset();
        }

   

        }
    }    

   

!E C:\Users\BENOIT~1\Desktop\test\UART_T~4\UART_T~1\main.c(242): operands of = have illegal types `pointer to char' and `signed char'
!E C:\Users\BENOIT~1\Desktop\test\UART_T~4\UART_T~1\main.c(246): operands of = have illegal types `pointer to char' and `signed char'
make: *** [obj/main.o] Error 1
 
uart_test_affichage_lcd - 3 error(s) 0 warning(s) 11:42:20

   

By the way, I don't understand what do you mean by "using formatted I/O" , can you explain this part to me please? 

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

There is a link in my previous post for formatted I/O, click on the "sprintf()". But as I see you are not at a PSoC5 but a PSoC1, probably a CY8C29466 there is no formatted I/O.

   

Take the errormessage literally: if( strPtr = UART_cGetChar()  ) { teC

   

will not work. str is defined as a pointer to a char and  UART_cGetChar()  delivers a char. This will not match.

   

I would suggest you to read (use a translator !) the descriptions for the UART APIs until understanding them in full. The link I supplied is a complete C-language manual, there are some helpful explanations.

   

 

   

Bob

0 Likes