You are here

Use of Uart_PutArray() | Cypress Semiconductor

Use of Uart_PutArray()

Summary: 15 Replies, Latest post by milinds.747_1696896 on 23 Jan 2017 09:05 AM PST
Verified Answers: 2
Last post
Log in to post new comments.
theosel92_1467891's picture
User
4 posts

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[i]=0;
         }
        
       }
/* [] END OF FILE */

user_1377889's picture
User
10803 posts

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

 

theosel92_1467891's picture
User
4 posts

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.

user_1377889's picture
User
10803 posts

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

user_242978793's picture
User
1485 posts

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. 

theosel92_1467891's picture
User
4 posts

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.

luantdoan_1606826's picture
User
14 posts

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. */
    }
}

user_1377889's picture
User
10803 posts

Welcome in the forum!

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

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

 

Bob
 

luantdoan_1606826's picture
User
14 posts

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

luantdoan_1606826's picture
User
14 posts

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

user_1377889's picture
User
10803 posts

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

 

Bob

Log in to post new comments.