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.
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
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.
P.S. I am attaching the project to this comment.
Char_Rx.cywrk_.Archive02.zip 456.5 K
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.
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.
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?
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).
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.
´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.
Kit-049UART.cyprj_.Archive01.zip 122.0 K
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
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?
P.S. I am attaching the project.
Char_Rx_v3.cywrk_.Archive01.zip 486.1 K
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.