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

cross mob
minodori
Level 1
Level 1
5 likes given First like received First reply posted

Below source code is that sends decimal 65 to the terminal with USBUART by USBUART_1_PutData or USBUART_1_PutString function.

In my understanding, 6 and 4 are encoded as ascii 54 and 52 respectively and sent to the termnal,

and then the terminal decodes the values of 6 and 4 with this ascii code and finally displays 64 on the terminal

Can I send decimal 65 to the terminal as number 65 without encoding with ascii?

At this time, I suppose that 'A'(ASCII code:65) may be displayed on the terminal.

 

Arduino has Serial.print and Serial.Write funciton.

If you write Serail.print(65), 65 is displayed on the terminal and Serial.write(65) show charater 'A'.

Is there a function in PSoC 5LP can write binary data to serial port like Serial.write() of Arduino?

 

I would appreciate if you let me know if there is any possible way.

-------------------------------------------------------------------------------

uint8_t wrBuffer[USBUART_BUFFER_SIZE];

uint16_t rtnCmd = 65;

sprintf((char *)wrBuffer,"%d",rtnCmd);

USBUART_1_PutData((uint8 *)wrBuffer, strlen(char *) wrBuffer));

0 Likes
1 Solution
roboteux
Level 3
Level 3
10 replies posted 10 sign-ins 5 replies posted

the USBUART_1_PutChar will take a binary data and send it as is.

The function USBUART_1_Putdata take a binary table and send the data as is.

In your exemple, the conversion from binary to ascii is donne via the sprintf call.

so USBUART_1_PutChar (65) will send the binary 65 to the uart, so the terminal will display A.

and your example will write 65 (in letters) to the terminal.

 

View solution in original post

7 Replies
roboteux
Level 3
Level 3
10 replies posted 10 sign-ins 5 replies posted

the USBUART_1_PutChar will take a binary data and send it as is.

The function USBUART_1_Putdata take a binary table and send the data as is.

In your exemple, the conversion from binary to ascii is donne via the sprintf call.

so USBUART_1_PutChar (65) will send the binary 65 to the uart, so the terminal will display A.

and your example will write 65 (in letters) to the terminal.

 

Hi roboteux,

As you commented, I modified my source as below and confirmed that the byte data is transmitted to the terminal as it is.

------------------------------------------------

uint8_t rtnCmd [1]= {65};

USBUART_1_PutData((rtnCmd, 1));

------------------------------------------------

I didn't really understand the behavior of sprintf and USBUART_1_PutData.

Thanks for your teaching.

 

0 Likes
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

minodori,

As roboteux indicated you can use _PutChar() with any 8-bit data. 

_PutString() is not a good function for sending just any byte value.  NULLs are potentially a problem since they signal the end of the string.

You can also use _PutArray() or _WriteTxData() for sending all 256 variations of a byte.

Len
"Engineering is an Art. The Art of Compromise."

Hi Len_CONSULTRON,


Thank you foryour replay.

I am now using USBFS macro for USBUART transmission.

In this case, there is no _PutArray() or _WriteTxData() funciton, which are included in UARTmacro.

Anyway when I use UART  instead USBFS macro, let me try above 2 functions.

 

 

Let me try to test _PutArray() or _WriteTxData

0 Likes

minodori,

The USBUART has USBUART_PutChar() and USBUART_PutData()

Len
"Engineering is an Art. The Art of Compromise."
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

May be this is a redundant response, but I tried this with CY8CKIT-059 ... well, just for fun 😉

schematic

002-schematic.JPG

pins

003-Pins.JPG

main.c

#include "project.h"
#include "stdio.h"

#define STR_BUF_LEN 64
char str[STR_BUF_LEN+1] ; /* 1 for NULL */

int main(void)
{
    uint16_t rtnCmd = 65 ;
    
    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;
    
    UART_PutString("\x1b[2J\x1b[;H") ; /* Clear Screen */
    UART_PutString("Uart Print Test ") ;
    snprintf(str, STR_BUF_LEN, "(%s %s)\n\r", __DATE__, __TIME__) ;
    UART_PutString(str) ;
    
    // Writing 65 as 'A'
    UART_PutChar(rtnCmd) ;
    UART_PutString("\n\r") ;
    
    // Writing 65 as decimal string "65"
    snprintf(str, STR_BUF_LEN, "%d\n\r", rtnCmd) ;
    UART_PutString(str) ;
   
    for(;;)
    {
        /* Place your application code here. */
    }
}

Result Tera Term log

001-TeraTerm-log.JPG

moto

Hi,

You did it for fun, but this also helped me:-)

Tthank you!