- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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));
Solved! Go to Solution.
- Labels:
-
PSOC5 LP MCU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
minodori,
The USBUART has USBUART_PutChar() and USBUART_PutData()
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
May be this is a redundant response, but I tried this with CY8CKIT-059 ... well, just for fun 😉
schematic
pins
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
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
You did it for fun, but this also helped me:-)
Tthank you!