-
1. Re: How to read characters (string) in PSoC from Serial
user_14586677 Sep 15, 2015 6:28 PM (in response to j.ortunogonzalez.1994_1446731)Use an Rx interrupt, or poll, and fill an array byte by byte as they
are received. You would use a pointer into the array and inc it each
time you write a byte. There are example projects in Creator, on start
page "Find Example Projects" link.
S No
Date
Project Title
1
01-May-2013
2
02-May-2013
3
03-May-2013
4
06-May-2013
5
07-May-2013
6
08-May-2013
7
09-May-2013
8
10-May-2013
9
13-May-2013
10
14-May-2013
11
15-May-2013
12
16-May-2013
13
17-May-2013
14
20-May-2013
15
21-May-2013
16
22-May-2013
17
23-May-2013
18
24-May-2013
19
28-May-2013
20
29-May-2013
21
30-May-2013
22
31-May-2013
23
03-Jun-2013
24
04-Jun-2013
25
05-Jun-2013
26
06-Jun-2013
27
07-Jun-2013
28
10-Jun-2013
29
11-Jun-2013
30
12-Jun-2013
31
13-Jun-2013
32
14-Jun-2013
33
17-Jun-2013
34
18-Jun-2013
35
19-Jun-2013
36
20-Jun-2013
37
21-Jun-2013
38
24-Jun-2013
39
25-Jun-2013
40
26-Jun-2013
41
27-Jun-2013
42
28-Jun-2013
43
01-Jul-2013
44
02-Jul-2013
45
03-Jul-2013
46
05-Jul-2013
47
08-Jul-2013
48
09-Jul-2013
49
11-Jul-2013
50
12-Jul-2013
S No
Date
Project Title
51
15-Jul-2013
52
16-Jul-2013
53
17-Jul-2013
54
18-Jul-2013
55
19-Jul-2013
56
22-Jul-2013
57
23-Jul-2013
58
24-Jul-2013
59
25-Jul-2013
60
26-Jul-2013
61
29-Jul-2013
62
30-Jul-2013
63
31-Jul-2013
64
01-Aug-2013
65
02-Aug-2013
66
05-Aug-2013
67
06-Aug-2013
68
07-Aug-2013
69
08-Aug-2013
70
09-Aug-2013
71
12-Aug-2013
72
13-Aug-2013
73
14-Aug-2013
74
15-Aug-2013
75
16-Aug-2013
76
19-Aug-2013
77
20-Aug-2013
78
21-Aug-2013
79
22-Aug-2013
80
23-Aug-2013
81
26-Aug-2013
82
27-Aug-2013
83
28-Aug-2013
84
29-Aug-2013
85
30-Aug-2013
86
03-Sep-2013
87
04-Sep-2013
88
05-Sep-2013
89
06-Sep-2013
90
09-Sep-2013
91
10-Sep-2013
92
11-Sep-2013
93
12-Sep-2013
94
13-Sep-2013
95
16-Sep-2013
96
17-Sep-2013
97
18-Sep-2013
98
19-Sep-2013
99
20-Sep-2013
100
23-Sep-2013
Regards, Dana.
-
2. Re: How to read characters (string) in PSoC from Serial
user_342122993 Sep 18, 2015 10:50 PM (in response to j.ortunogonzalez.1994_1446731)martin, Take a look on this thread: http://www.cypress.com/forum/psoc-4-architecture/psoc4-uart-receiving-string There is an example of receiving UART strings and simple commands to control RGB LED on PSOC4 Pioneer Board: UART4_RGB_01-000.cywrk.Archive01.zip -
3. Re: How to read characters (string) in PSoC from Serial
j.ortunogonzalez.1994_1446731 Oct 8, 2015 8:50 AM (in response to j.ortunogonzalez.1994_1446731)Hi again:
Sorry for not answer soon enough, I am trying to do this program to get four characters, and then save the values in an array. In order to do that I'm using an Rx Interrupt on byte received (just like @danaaknight said). I developed the following code and then program my PSoC CYCKIT-049-42xx, then using puTTY, I tried to send this characters from my PC to the PSoC, but I am not getting any answer from the PSoC to my PC.
I would be very grateful if you could give some help or advice about what I am doing wrong.
Martin
P.S. I am attaching the project to this comment.
-
Char_Rx.cywrk_.Archive02.zip 456.5 K
-
-
4. Re: How to read characters (string) in PSoC from Serial
user_1377889 Oct 8, 2015 10:31 AM (in response to j.ortunogonzalez.1994_1446731)Are you trying to use the UART bridge that connects the USB interface to a (virtual) Com-port on your PC? Then you need to use the SCB - based component and connect Tx and Rx to Port4_0 and _1
When using a direct connection from your Tx and Rx pins P0_5 and _4 you will need a level shifter to convert the 5V signal to a +-12v RS232 level and back.
Bob
-
5. Re: How to read characters (string) in PSoC from Serial
j.ortunogonzalez.1994_1446731 Oct 8, 2015 10:45 AM (in response to j.ortunogonzalez.1994_1446731)I am using the USB-Serial Bridge (CY7C65211) that is included with the prototyping kit, and just wiring P0.4 and P0.5 to the Serial Bridge. But I've never heard that it's necessary to use the SCB component, in other projects I used the UART v2.5 component, and it worked just fine, What is the difference? . However, I am going to try the SCB component.
Thanks
Martin
-
6. Re: How to read characters (string) in PSoC from Serial
user_1377889 Oct 8, 2015 12:05 PM (in response to j.ortunogonzalez.1994_1446731)Maybe I misunderstood you, you are talking about " just wiring P0.4 and P0.5 to the Serial Bridge" which pins do you use?.
Did you confirm that the baud-rate for USB-chip is same as for your UART? Did you check using Cypress USB Configuration Utility?
Bob
-
7. Re: How to read characters (string) in PSoC from Serial
j.ortunogonzalez.1994_1446731 Oct 8, 2015 4:17 PM (in response to j.ortunogonzalez.1994_1446731)I am connecting P0.4 and P0.5 of the PSoC4200 to SCB.4 and SCB.0 of the Serial Bridge (CY7C65211) respectively, I am attaching a diagram of my connections.
By the way, yes. I'm using puTTY as virtual serial monitor, with 115200 Bauds. And I have set the baud rate from the USB Configuration Utility (I will attach an image of this too).
Martin
-
8. Re: How to read characters (string) in PSoC from Serial
user_1377889 Oct 9, 2015 12:47 AM (in response to j.ortunogonzalez.1994_1446731)Your variable "send" is defined too short, so sprintf() will overwrire data.
Declaring a local variable as "volatile" is of no use, it cannot get changed from the outside, but your variable "i" can.
Bob
-
9. Re: How to read characters (string) in PSoC from Serial
user_1377889 Oct 9, 2015 5:10 AM (in response to j.ortunogonzalez.1994_1446731)´Concerning the "wiring": Sorry I was darn wrong with that. For the CY8CKIT-049-42xx prototyping kit P4_0 and P4_1 are correct.
No external wire needed, both pins are already connected to the USB-bridge. Just built and tested a project - attached.
Bob
-
Kit-049UART.cyprj_.Archive01.zip 122.0 K
-
-
10. Re: How to read characters (string) in PSoC from Serial
user_365962704 Oct 10, 2015 8:53 AM (in response to j.ortunogonzalez.1994_1446731)I have a project that use "commands" to turn on the corresponding led on the RGB Led of the Pioneer Kit, i haven´t seen yours, but maybe it can help you, find it attached.
PD: en ese proyecto estaba tratando de entender las funciones de string.h asi que trae varias cosas que ni al caso xD
-
11. Re: How to read characters (string) in PSoC from Serial
j.ortunogonzalez.1994_1446731 Oct 11, 2015 7:29 PM (in response to j.ortunogonzalez.1994_1446731)Hey:
First of all, thank you for all your help. I really tried to do this program with the SCB UART, I don't know why it didn't work with this component; nevertheless, with the UART v2.5 worked perfectly, and now I can read strings inputs with a length of 4. The thing is that now, when I try to convert the string to an integer using a C function, sometimes it works, but sometimes the conversion is totally wrong. I proved this function in the compiler in my PC and I am pretty sure that it worked.
What could be happening here?
Martin
P.S. I am attaching the project.
-
Char_Rx_v3.cywrk_.Archive01.zip 486.1 K
-
-
12. Re: How to read characters (string) in PSoC from Serial
user_1377889 Oct 12, 2015 2:36 AM (in response to j.ortunogonzalez.1994_1446731)You are overdoing too much.
First the UART send:
Do not use delay functions, do not use UART_ClearTxBuffer() except in case of an error.
Instead use UART_ReadTxStatus() and check for completed transfer- Since UART_PutString is a blocking function not even that is needed.
Next the UART receive:
You do not need to use an interrupt, you may increase the Rx buffer in the UART component and look wit UART_GetRxBufferSize() for data received. Only difficulty is here to find out when a transmission is finished. Easiest is when a delimiter as \r or \n is received.
When using the interrupt the first thing in the handler is to clear the interrupt source using UART_ReadRxStatus().
Look into the UART's datasheet for explanations of the functions and the status registers.
What if you receive more than 5 bytes? Then you are destroying data!!!
You may, but you do not need to write your own conversion routines. There is the scanf() library routine which will do, have a look here.
Happy coding
Bob
-
13. Re: How to read characters (string) in PSoC from Serial
user_475055874 Mar 3, 2018 11:41 PM (in response to j.ortunogonzalez.1994_1446731)You can also get the standard C puts, gets, scanf, printf stuff working with some pain
https://iotexpert.com/2017/05/10/implementing-psoc-printf/
Note: be sure to increase the heap size to at least 400 under Design Wide Resources, System, Configuration, Heap Size (bytes)_read generally stolen from here. Assumes that an incoming 0 is nothing recieved (e.g. can't support binary data).
https://mcuoneclipse.com/2014/07/11/printf-and-scanf-with-gnu-arm-libraries/
#include "project.h" #include "stdio.h" //Replace the gcc default connectors for stdin and stdout int _write(int file, char *ptr, int len) { int i; file = file; for (i = 0; i < len; i++) { UART_UartPutChar(*ptr++); } return len; } int _read (int fd, const void *buf, size_t count) { size_t CharCnt = 0x00; (void)fd; /* Parameter is not used, suppress unused argument warning */ for (;count > 0x00; --count) { /* Save character received by UARTx device into the receive buffer */ while(!(*(uint8_t*)buf = (unsigned char)UART_UartGetChar())); CharCnt++; /* Increase char counter */ /* Stop reading if CR (Ox0D) character is received */ if (*(uint8_t*)buf == 0x0DU) { /* New line character (CR) received ? */ *(uint8_t*)buf = '\n'; /* Yes, convert LF to '\n' char. */ break; /* Stop loop and return received char(s) */ } buf++; /* Increase buffer pointer */ } //return 1; /* WRONG! */ return CharCnt; } //and now all the standard c io stuff works. int main(void) { char buf[100]=""; CyGlobalIntEnable; /* Enable global interrupts. */ UART_Start(); printf("Hello World\n\r"); for(;;) { // char c = UART_UartGetChar(); // UART_UartPutChar(toupper(c)); //gets(buf); //bad idea. No size limit, no\r on input fgets(buf, sizeof(buf), stdin); for (int i=0;i<sizeof(buf) && buf[i];i++) { buf[i] = toupper(buf[i]); } printf(buf); //not secure } }