Use of Uart_PutArray()

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

cross mob
Anonymous
Not applicable

I'm a beginner using PSOC 3 to complete a project for my masters. I've been trying to use to the Uart_PutArray function to transmit an Array to the PC using Uart.

   

here's some code I've used to simulate an application segment

   

#include <project.h>
#include <stdio.h>
#include <stdlib.h>

   


uint8 count[256];
uint8 channel;
int i,x,j;

   

int main()
{
    CyGlobalIntEnable; /* Enable global interrupts. */
    init();
   
   
    for(j=0;J<10000;j++)
    {
       channel=rand()%255;
       //UART_1_PutChar(channel);
       x=count[channel]+1;
    
       if(x>=0&&x<255)
       {
       
        //x=count[channel]+1;
        count[channel]++;
        //UART_1_PutChar(x);
        //UART_1_PutChar(0x0A);
        //CyDelay(200);
      
         }
       else
        break;
    }

   

        UART_1_PutArray(const uint8 count[],uint8 256);

   

}

   

    void init()
     {
        UART_1_Start();
        for(i=0;i<=255;i++)
        {
            count=0;
         }
        
       }
/* [] END OF FILE */

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

Welcome in the forum!

   

... and what does not work as you expect? Keep in mind that serial interface of a PC is at +-12V which might destroy your PSoC which has got a TTL level of 5V(as max), so you will need a level-shifter as MAX232. When you are using a CY8CKIT-030 there already is a level shifter on it, you just have to enable it and jumper Tx and Rx. Alternatively you an use an USBUART component, use the second USB-port of the board and using an emulated com-port on the PC side.

   

Can you please post your complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

   

 

   

Bob

View solution in original post

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

Welcome in the forum!

   

... and what does not work as you expect? Keep in mind that serial interface of a PC is at +-12V which might destroy your PSoC which has got a TTL level of 5V(as max), so you will need a level-shifter as MAX232. When you are using a CY8CKIT-030 there already is a level shifter on it, you just have to enable it and jumper Tx and Rx. Alternatively you an use an USBUART component, use the second USB-port of the board and using an emulated com-port on the PC side.

   

Can you please post your complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Thanks Sir for the quick response. I'm trying to use the above code to simulate the array count data, and then to implement it into my project code to see if my project is capable of using the simulated array to transmit to the PC using the UART. The problem that I'm facing is that the TERA Term doesn't get any output from the PSOC 3. The Aim is to transfer the array data to The PC and Labview will be used to plot count vs count index.

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

I would suggest you to start with a simple "Hello world" program.

   

Do not forget that in the world of embeddeds there usually is an infinite loop preventing main() to be exited.

   

So you can check out if your wiring is correct.

   

You transmit non-ascii data which your teraterm will show as garbage.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Theosel: I don't have a PSOC 3 board but this PSOC 5 program should help you in the UART area.  I tried your program on a PSOC 4 Pioneer board and it seemed to have an issue with the Void call.  This program sends ADC data from the PSOC 5 to the Putty terminal and has some control keys to output the data.  Like S for free run of the data and X stops the data dump.  Please read the PDF file with the program for more info. 

Anonymous
Not applicable

Thank you for your valuable insights. I've worked with an DAC,ADC coupled together and their output is can be viewed on the Character LCD.. However the scope of my project is to use the PSOC 3 to store ADC output data in various bins and send it as a bulk ie the Array. Since I'm hard pressed on the Application data, I'm trying to simulate the input and output sections of my project.

0 Likes
Anonymous
Not applicable

I am working on a PSoC 3 design using CY8C3866AXI-040 chip to monitor voltage rails on the board and would like to format string with voltage reading and send to UART Console for display but encountered issue with sprintf(). I am using PSoC Creator 3.3.

   

With the code below, I'm expecting "Line 0", "Line 1",... "Line 7" to be shown on the UART Console but instead I got these "Line 0", "Line 256", "Line 512", Line 768", "Line 1024", "Line 1280", "Line 1536", "Line 1792". I don't really know what was wrong. Please help.

   

int main()
{
    uint8 ii;
    char msgbuf[128];

   

    CyGlobalIntEnable; /* Enable global interrupts. */

   

    UART_Start(); /* init and start uart */
    CyDelay(10);  /* allow uart init time */
    
    for (ii = 0; ii < 8; ii++) {
        sprintf(msgbuf, "Line %d\r\n", ii);
        UART_PutArray(msgbuf, strlen(msgbuf));
    }
   
    for(;;)
    {
        /* Place your application code here. */
    }
}

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

Welcome in the forum!

   

%d format expects an int to display. So better use

   

        sprintf(msgbuf, "Line %d\r\n", (int)ii);

   

 

   

Bob
 

0 Likes
Anonymous
Not applicable

Thank you Bob. This was it. Really appreciated your help!

0 Likes
Anonymous
Not applicable

Hi Everyone,

   

I am encounter sprintf issue with format %08X to print 32bit hex value. The formatted string displayed on UART port shows only upper 16bit value. Please help. My simple test code is as follow:

   

void my_test_func (void)

   

{

   

    const uint8 msgbuf[128];       

   

    uint32 expected_val = 0x874810B5; /* PEX8748 MFR & DEV ID */

   

    sprintf(&msgbuf[0], "PEX8748 MFR&DEV ID expected 0x%08X\r\n", (uint32) expected_val);

   

    UART_PutArray((const uint8 *)&msgbuf[0], strlen(msgbuf));

   

}

   

The output string shown on the uart console:

   

PEX8748 MFR&DEV ID expected 0x00008748

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

You probably need to use lX (small letter "L") to indicate that it is a long value. See C-manual excerpt.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thanks Bob. That was it. Appreciate your help!

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

You are always welcome!

   

I have to admit that for getting answers for exactly these questions I have to look into the manual also. Cannot keep them in mind...

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello. I am new to the forum and I am working on a similar project using CY8C3866AXI-040. The aim is to acquire data from ADC, convert it and transmit it through UART. Please tell me,

   

@theosel92_1467891, Were you able to run it successfully? I would be grateful if you could share your work.
Could you share the link for labview? I made a software using visual studio but I am not satisfied with it. Here is the link: https://1drv.ms/u/s!AmTOHfqkfh3SvHtBHJ2YzOvrLyl0 
what changes may be required for using the ADC in a 16 bit resolution?

   

I have a schematic diagram of the kit I am using. While I could obtain data from ADC, I am unable to transmit it through UART. I say this because I could not see any result on TeraTerm.

0 Likes
Anonymous
Not applicable
        Hello milinds, it's been a while since I worked with the psoc3.. Will definitely get back to you on my project work.. As far as I remember teraterm couldn't display the output of the ADC, something to the output being ASCII coded .. However preliminary results were observed on LabVIEW a LCD compatible with the Psoc3 kit - Selwyn   
0 Likes
Anonymous
Not applicable

thank you. waiting for your reply.

0 Likes