- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Rach_4524011,
You need to select the chip MPN and not the kit no. By device, I meant the PSoC Chip and not the kit.
Choose the MPN (Manufacturer part number). The code doesn't vary depending on the kit. You can use the same kit for these code example as well.
Refer:
CY8CKIT-049-4xxx PSoC® 4 Prototyping Kit Guide
AN79953 - Getting Started with PSoC® 4
https://www.cypress.com/documentation/application-notes/an79953-getting-started-psoc-4
Watch the video -
PSoC Creator 101: 0. CY8CKIT-049 Prototyping Kit Getting Started
https://www.cypress.com/video-library/PSoC-Software/psoc-creator-101-cy8ckit-049-prototyping-kit-get...
Regards,
Bragadeesh
Bragadeesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Rach_4524011,
Please refer the following code example :
https://www.cypress.com/documentation/code-examples/ce224406-psoc-4-uart
Alternatively, Open PSoC Creator -> File -> Code Example.
Regards,
Bragadeesh
Bragadeesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
BUT THE KIT IS DIFFERENT, I WANT IT FOR 49 KIT.. PLEASE HELP... I M USING PSOC FOR 1ST TIME
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi user_63541,
The code example is made for all the PSoC 4 devices. It is not kit specific. To make the kit work for your device, do the following:
1. Right click on the project name and choose device selector.
2. Select the part number of the device you are using in the dialog that opens. It is printed on top of the PSoC 4 device. Example CY8C4245AXI-483 44TQFP. Click OK.
3. Make proper pins assignment in the Pins tab of Design wide resources. Choose the UART pins of your choice.
Regards,
Bragadeesh
Bragadeesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
no my kit no. is not there in the device selector option.. please help me i have to write it for cy8ckit 049
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Rach_4524011,
You need to select the chip MPN and not the kit no. By device, I meant the PSoC Chip and not the kit.
Choose the MPN (Manufacturer part number). The code doesn't vary depending on the kit. You can use the same kit for these code example as well.
Refer:
CY8CKIT-049-4xxx PSoC® 4 Prototyping Kit Guide
AN79953 - Getting Started with PSoC® 4
https://www.cypress.com/documentation/application-notes/an79953-getting-started-psoc-4
Watch the video -
PSoC Creator 101: 0. CY8CKIT-049 Prototyping Kit Getting Started
https://www.cypress.com/video-library/PSoC-Software/psoc-creator-101-cy8ckit-049-prototyping-kit-get...
Regards,
Bragadeesh
Bragadeesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
THANKS A LOT, GOT THE KIT IN THE DEVICE SELECTOR, CAN YOU TELL ME HOW TO SELECT THE DMA PIN IN THIS EXAMPLE. AND HOW MANY UART'S ARE THERE IN THIS EXAMPLE.
HOW TO SELECT DMA PIN AS I AM NOT ABLE TO DO THAT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Rach_4524011,
PSoC 4200 family doesn't have DMA in it.
Can you please elaborate your question?
Do you want to assign pins for the UART?
There is only one UART block in the example. There are two SCB (Serial Communication Block) in PSoC 4200 device that can be configured as UART, I2C or SPI. Hence you can have two UART blocks in the design.
Refer device datasheet for details.
https://www.cypress.com/file/138656/download
Regards,
Bragadeesh
Bragadeesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
this code example is not helping me.. i want to do interrupt programming using 2 uart's and simple programming of interrupt in one uart.
just a simple programming of uart interrupt i want
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Rach_4524011,
It will be helpful if you could provide more information on your requirement.
How many PSoCs / devices (IC) do have in your design? I believe you want two UART blocks to communicate with one another (Reference : i want to send one data from uart 1 to uart 2 and again that data from uart 2 to uart 1.. kind of cr... ) Does this mean two PSoC devices or two UART blocks in the same device PSoC device. Show us a schematic/ block diagram. We might need information on your setup so that we can guide you better.
What I think you would be requiring is to trigger an Rx interrupt whenever you receive a character (a byte) in the RX FIFO.
void ISR_UART()
{
/* Returns the status/identity of which enabled RX interrupt source caused interrupt event */
uint32 source = UART_GetRxInterruptSource();
/* Checks for "RX FIFO AND not empty" interrupt */
if(0ul != (UART_INTR_RX_NOT_EMPTY & source))
{
/* Get the character from terminal */
read_character = UART_UartGetChar();
/* Clear UART "RX FIFO not empty interrupt" */
UART_ClearRxInterruptSource(UART_INTR_RX_NOT_EMPTY);
/* Sets received_character flag */
received_character = 1;
}
else
{
error_uart = 1;
}
UART_ClearPendingInt();
}
The example I shared in the previous message does the same. As and when it receives a character in the RX FIFO, it triggers the RX FIFO NOT EMPTY event. The ISR is executed which takes care of clearing the interrupt and taking the character from the RX FIFO. You can also choose to trigger interrupts on other events. Ensure to turn them ON in the advanced tab of the UART component.
Please let us know if this helps.
Further Reading:
1. PSoC 4 Interrupts https://www.cypress.com/documentation/application-notes/an90799-psoc-4-interrupts
2. PSoC 4200 Architecture TRM: https://www.cypress.com/documentation/technical-reference-manuals/psoc-41004200-family-psoc-4-archit...
We understand that the learning curve could take more time with PSoC. But once you are familiar, you can do amazing stuff.
Regards,
Bragadeesh
Bragadeesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yes bragadeesh, two uart blocks communicating with one another tho=rough interrupt programming. the above image i have put is only one uart device's interrupt programming.
now i want two uart devices to communicate like
if uart 1 sends a then uart 2 shld get b and then again to 1 which sends b and so on...
it involves interrupt programming...
the code which you have sent shld i add that code in the before code which i have written or that is the whole program from starting?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Rach_4524011,
Do you want both the UART blocks to be in the same chip or different chip? Example:
The code I have sent is the UART Interrupt Service Routine. The complete code is in the Code example I shared in the previous response.
Regards,
Bragadeesh
Bragadeesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
same chip....cross communication between the two uarts but there is only psoc kit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi user_63541,
Do the following:
1. Drag and drop two UART blocks in the design
2. Configure them to the same baud rates
3. Enable Rx interrupt - RX FIFO not empty in both
4. Assign the UART TX and RX to appropriate GPIOs. Note: Dedicated UART blocks go to dedicated GPIOs. You can find this information in device datasheet pinouts section
https://www.cypress.com/file/138656/download
PSoC Creator also shows you the correct pins in the drop down.
5. Connect Tx of first block to Rx of second block. Similarly Rx of 1st block to Tx of 2nd block externally using wires
Refer attached main.c file for programming part and project for reference. You need to have separate ISRs for handling interrupts of each UART block.
Thanks,
Bragadeesh
Bragadeesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
getting 13 errors as it is showing maximu resource limit reached macro cells.. and please specify the gpio pins too...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please share your project file. Follow the below steps:
Archiving a PSoC Creator Design
There are two dedicated SCB (Serial Communication Blocks) in the PSoC device you have chosen. I hope you have other SCB block (I2C/ SPI) in your design. If that is the case, you can try to use an UDB block for UART - UART [v2.50] . A UDB is a flexible, programmable digital block inside a PSoC device that is designed to realize synchronous State Machines such as UART, Counter etc when dedicated resources are exhausted.
The code for handling the ISR could be different. Use the component datasheet (Right click component in Top design and choose datasheet) for programming.
Let us know if this helps
Regards,
Bragadeesh
Bragadeesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
successfully done using another method. but my new task is now that
i have two uarts assigned in it and now i have named on of them as gsm uart as i have to connect "gsm modem" to the "microcontroller" and micro controller is connected to pc..
now i have to write at cammands from pc which goes to micro controller and from micro controller to gsm modem, which then replies to the AT commands i have written and the reply goes to the micro controller and micro controller to pc.
for eg :
I WRITE"AT" FROM PC..
GOES TO MICRO CONTROLLER AND THEN FROM MICRO CONTROLLER TO GSM
GSM GETS AT AS THE COMMAND..
NOW GSM RESPONDS "OK" WHICH GOES TO MICRO CONTROLLER AND MICRO CONTROLLER TO PC..
INTERRUPTS ARE THERE ALREADY..
PLEASE GIVE ME A PROGRAM AS I M STUCK WITH PROGRAMMING..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please refer the Application Programming Interface section from the component datasheet to send and receive data using the UART component.
https://www.cypress.com/documentation/component-datasheets/psoc-4-serial-communication-block-scb
You can refer the below post for reference :
tty_utils a utility sample for CLI type program
We will be able to help you if you run into any specific issues while programming. Use the Code example shared previously to send and receive data using UART.
Regards,
Bragadeesh
Bragadeesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
no bragadeesh still not getttingi it.. please help.. the example showed is not of my use any how..
please where to start help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
If you directly connect 2 uarts out of available 2 uarts, debugging may not be very easy.
So I used CY8CKIT-044 which has 3 UARTs and made the following sample.
Note: I also mad one for CY8C4125AXI-483 at the bottom, so don't go now 😉
=== CY8CKIT-044 Version ===
The schematic,
Pins
main.c
==============
#include "project.h"
#include "stdio.h"
#define TAB '\t'
#define SPACE ' '
#define CR '\r'
#define LF '\n'
static inline int is_delimiter(char c)
{
return((c == TAB)||(c == SPACE)||(c == CR)||(c == LF)) ;
}
static inline int is_eol(char c)
{
return((c == CR) || (c == LF)) ;
}
#define RX_BUF_LEN 32
#define STR_LEN 32
volatile uint8_t cmd_buf[RX_BUF_LEN] ;
volatile uint8_t gsm_buf[RX_BUF_LEN] ;
volatile int cmd_write_index = 0 ;
volatile int gsm_write_index = 0 ;
int cmd_read_index = 0 ;
int gsm_read_index = 0 ;
int str_gsm_index = 0 ;
int str_cmd_index = 0 ;
char cmd_str[STR_LEN+1] ;
char gsm_str[STR_LEN+1] ;
char str[STR_LEN+1] ;
void print(char *str)
{
UART_UartPutString(str) ;
}
void cls(void)
{
print("\033c") ; /* reset */
CyDelay(20) ;
print("\033[2J") ; /* clear screen */
CyDelay(20) ;
}
CY_ISR(ISR_CMD_Handler)
{
if (UART_CMD_SpiUartGetRxBufferSize()) {
cmd_buf[cmd_write_index] = UART_CMD_UartGetByte() ;
cmd_write_index = (cmd_write_index + 1) % RX_BUF_LEN ;
}
UART_CMD_ClearRxInterruptSource(UART_CMD_INTR_RX_NOT_EMPTY) ;
}
CY_ISR(ISR_GSM_Handler)
{
if (UART_GSM_SpiUartGetRxBufferSize()) {
gsm_buf[gsm_write_index] = UART_GSM_UartGetByte() ;
gsm_write_index = (gsm_write_index + 1) % RX_BUF_LEN ;
}
UART_GSM_ClearRxInterruptSource(UART_GSM_INTR_RX_NOT_EMPTY) ;
}
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
ISR_CMD_ClearPending() ;
ISR_CMD_StartEx(ISR_CMD_Handler) ;
ISR_GSM_ClearPending() ;
ISR_GSM_StartEx(ISR_GSM_Handler) ;
UART_CMD_Start() ;
UART_GSM_Start() ;
UART_Start() ; // for CY8CKIT-044
}
int cmd_get_string(void)
{
int result = 0 ;
if (cmd_read_index != cmd_write_index) {
if (is_eol(cmd_buf[cmd_read_index])) {
cmd_str[str_cmd_index] = 0 ;
result = str_cmd_index ;
str_cmd_index = 0 ;
} else {
cmd_str[str_cmd_index++] = cmd_buf[cmd_read_index] ;
if (str_cmd_index >= STR_LEN) {
cmd_str[STR_LEN] = 0 ;
str_cmd_index = 0 ;
result = -1 ;
}
}
cmd_read_index = (cmd_read_index + 1) % RX_BUF_LEN ;
}
return(result) ;
}
int gsm_get_string(void)
{
int result = 0 ;
if (gsm_read_index != gsm_write_index) {
if (is_eol(gsm_buf[gsm_read_index])) {
gsm_str[str_gsm_index] = 0 ;
result = str_gsm_index ;
str_gsm_index = 0 ;
} else {
gsm_str[str_gsm_index++] = gsm_buf[gsm_read_index] ;
if (str_gsm_index >= STR_LEN) {
gsm_str[STR_LEN] = 0 ;
str_gsm_index = 0 ;
result = -1 ; /* buffer over flow */
}
}
gsm_read_index = (gsm_read_index + 1) % RX_BUF_LEN ;
}
return(result) ;
}
int main(void)
{
int cmd_count = 0 ;
int gsm_count = 0 ;
init_hardware() ;
cls() ;
print("Cross UART Test ") ;
snprintf(str, STR_LEN, "(%s %s)\n\r", __DATE__, __TIME__) ;
print("\n\r") ;
UART_CMD_UartPutString("Hello!\n") ;
CyDelay(10) ;
for(;;)
{
if (gsm_get_string()) { /* uart_gsm got a word */
// received word is gsm_str[]
snprintf(str, STR_LEN, "gsm received \"%s\"\n\r", gsm_str) ;
print(str) ;
snprintf(str, STR_LEN, "Kon-nichi-wa %d !\n",gsm_count++) ;
UART_GSM_UartPutString(str) ;
if (gsm_count > 100) {
gsm_count = 0 ;
}
CyDelay(10) ;
}
if (cmd_get_string()) { /* uart_cmd got a word */
// received word is cmd_str[]
snprintf(str, STR_LEN, "cmd recived \"%s\"\n\r", cmd_str) ;
print(str) ;
CyDelay(10) ;
snprintf(str, STR_LEN, "Hello %d !\n", cmd_count++) ;
UART_CMD_UartPutString(str) ;
if (cmd_count > 100) {
cmd_count = 0 ;
}
CyDelay(1000) ;
}
}
}
==============
Tera Term log
Note: "Kon-nichi-wa" means "Hello" in Japanese.
So at least on CY8CKIT-044 two uarts are communicating OK.
Now time for CY8C4125AXI-483
schematic
pins
NOTE: Since I don't know which pin you need to use, I just let the compiler assign the pins.
So please assign pins you need to use.
main.c
Note: This is the version I removed the third UART form the project.
And it is compile-able, but I have not test it.
======================
#include "project.h"
#include "stdio.h"
#define TAB '\t'
#define SPACE ' '
#define CR '\r'
#define LF '\n'
static inline int is_delimiter(char c)
{
return((c == TAB)||(c == SPACE)||(c == CR)||(c == LF)) ;
}
static inline int is_eol(char c)
{
return((c == CR) || (c == LF)) ;
}
#define RX_BUF_LEN 32
#define STR_LEN 32
volatile uint8_t cmd_buf[RX_BUF_LEN] ;
volatile uint8_t gsm_buf[RX_BUF_LEN] ;
volatile int cmd_write_index = 0 ;
volatile int gsm_write_index = 0 ;
int cmd_read_index = 0 ;
int gsm_read_index = 0 ;
int str_gsm_index = 0 ;
int str_cmd_index = 0 ;
char cmd_str[STR_LEN+1] ;
char gsm_str[STR_LEN+1] ;
char str[STR_LEN+1] ;
CY_ISR(ISR_CMD_Handler)
{
if (UART_CMD_SpiUartGetRxBufferSize()) {
cmd_buf[cmd_write_index] = UART_CMD_UartGetByte() ;
cmd_write_index = (cmd_write_index + 1) % RX_BUF_LEN ;
}
UART_CMD_ClearRxInterruptSource(UART_CMD_INTR_RX_NOT_EMPTY) ;
}
CY_ISR(ISR_GSM_Handler)
{
if (UART_GSM_SpiUartGetRxBufferSize()) {
gsm_buf[gsm_write_index] = UART_GSM_UartGetByte() ;
gsm_write_index = (gsm_write_index + 1) % RX_BUF_LEN ;
}
UART_GSM_ClearRxInterruptSource(UART_GSM_INTR_RX_NOT_EMPTY) ;
}
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
ISR_CMD_ClearPending() ;
ISR_CMD_StartEx(ISR_CMD_Handler) ;
ISR_GSM_ClearPending() ;
ISR_GSM_StartEx(ISR_GSM_Handler) ;
UART_CMD_Start() ;
UART_GSM_Start() ;
}
int cmd_get_string(void)
{
int result = 0 ;
if (cmd_read_index != cmd_write_index) {
if (is_eol(cmd_buf[cmd_read_index])) {
cmd_str[str_cmd_index] = 0 ;
result = str_cmd_index ;
str_cmd_index = 0 ;
} else {
cmd_str[str_cmd_index++] = cmd_buf[cmd_read_index] ;
if (str_cmd_index >= STR_LEN) {
cmd_str[STR_LEN] = 0 ;
str_cmd_index = 0 ;
result = -1 ;
}
}
cmd_read_index = (cmd_read_index + 1) % RX_BUF_LEN ;
}
return(result) ;
}
int gsm_get_string(void)
{
int result = 0 ;
if (gsm_read_index != gsm_write_index) {
if (is_eol(gsm_buf[gsm_read_index])) {
gsm_str[str_gsm_index] = 0 ;
result = str_gsm_index ;
str_gsm_index = 0 ;
} else {
gsm_str[str_gsm_index++] = gsm_buf[gsm_read_index] ;
if (str_gsm_index >= STR_LEN) {
gsm_str[STR_LEN] = 0 ;
str_gsm_index = 0 ;
result = -1 ; /* buffer over flow */
}
}
gsm_read_index = (gsm_read_index + 1) % RX_BUF_LEN ;
}
return(result) ;
}
int main(void)
{
int cmd_count = 0 ;
int gsm_count = 0 ;
init_hardware() ;
UART_CMD_UartPutString("Hello!\n") ;
CyDelay(10) ;
for(;;)
{
if (gsm_get_string()) { /* uart_gsm got a word */
// received word is gsm_str[]
snprintf(str, STR_LEN, "Kon-nichi-wa %d !\n",gsm_count++) ;
UART_GSM_UartPutString(str) ;
if (gsm_count > 100) {
gsm_count = 0 ;
}
CyDelay(10) ;
}
if (cmd_get_string()) { /* uart_cmd got a word */
// received word is cmd_str[]
snprintf(str, STR_LEN, "Hello %d !\n", cmd_count++) ;
UART_CMD_UartPutString(str) ;
if (cmd_count > 100) {
cmd_count = 0 ;
}
CyDelay(1000) ;
}
}
}
======================
Use two_uart_200419_044 for CY8CKIT-044
Use tow_uart_200419 for CY8CKIT-049,
if your MPU is not CY8C4125AXI-483, change the device and pin assignment.
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I HAVE MADE A PROGRAM TO SEND AT COMMAND AND GET OK IN RESPONSE.. I HAVE DEVELOPED IT BUT WHEN I TYPE AT
I DONT GET AT IN RESPONSE..
WHEN I PRESS ENTER IT JUST GETS TO NEW LINE AND DOESNT NOT GET OK..
CAN IT BE DUE TO LOOSE CONNECTION OR ANY OTHER ISSUE IS THERE??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
As far as I know of many (if not all) programs do not work correctly at first,
then you need to perform an operation called "debugging."
If you could attach your project with your response,
others may be able to check the code.
But without seeing your project or code, all we can say is
"Yes, it may be the connection and it may be because of other issues, too."
Well, at least what I can say now is,
Have you tried a loop back test?
Which you connect tx and rx of one uart, so that any input of the uart
should be echoed back to the same uart.
And have you tried my sample code?
Did it work or it did not work as I showed in my response?
Or was my work just in vain?
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
SO IHAVE NOT TRIED YOUR CODE BT I WANT TO NOW DO A NEW TASKK IN WHICH I HAVE 2 UART, A PC, PSOC AND GSM MODEM...
AS FOR NOW I AM SENDING COMMANDS THROUGH PC BUT NOW I WANT TO SEND COMMANDS DIRECTLY MICRONTROLLER TO GSM AND THE PORT IS OPENED AND ETC. '
FOR EG: I WRITE CONNECT ON PUTTY.. DIRECTLY MICROCONTROLLER GETS CONNECTED TO GSM AND THE COMMANDS PROGRAM TAKE PLACE AND PORT IS OPENED DIRECTLY...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So you are not willing to listen to us / me.
Then I wonder how we can be any help of you?
Having written above, since I have spent rather long time to prepare the samples, let me write the following.
But as always, you are free to ignore anything.
From your last reply, I imaged that you can do
But you are not able to do
So I think I wrote another sample which will do the above.
But as I don't have a board with the PSoC device,
I could not test it at my side.
I hope that you will download and try the sample, but as usual, it's not mandatory 😉
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
can ypu explain me the project you have sent.. as i am very new to programming.. i wasnt able to understand some of the lines in the main.. so if i type connect then the microcontroller directly gets connected to gsm modem and etc... ??
plz explain me your code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
for eg: i write connect in putty, then thr micro controller does it job, of directly connecting the microcontroller to gsm modem..
all the cammds gets executed automcatically and it open the port of server and etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I'm not sure how far we need to go.
But anyway let me try.
I'm going to try to explain the newest project "two_uart_200425."
It has two uarts,
(1) UART_CMD
This is supposed to be connected to your PC.
So your serial terminal program, such as Putty(?) (I usually use Tera Term here) talk and listen with this UART component.
(2) UART_GSM
This is suppoed to be connected to your GSM modem.
So MCU and GSM modem will talk/listen via this UART component.
And each components has interrupt connected.
The interrupt is configured to let the program jump to its associated interrupt service routine (ISR).
Since both UART_CMD and UART_GSM works the same way, let's only talk about UART_CMD here.
If in your PC, you type a letter into Putty, a letter is sent to UARD_CMD's rx (receiver)
and it causes the interrupt triggered.
Then ISR_CMD_Handler is called automatically.
In ISR_CMD_Handler, if there is a byte (or more) received by UART_CMD
the size of it's RxBuffer is more than 0, so I take one byte for the buffer by
cmd_buf[cmd_write_index] = UART_CMD_UartGetByte() ;
And I increase cmd_write_indx by 1, but if it gets the last byte, it will start from the first byte again,
so that it will form what we call "ring buffer".
After doing above, I clear the interrupt flag then return from ISR_CMD_Handler
Note: Although I'm clearing interrupt flag for UART_CMD_INTR_RX_NOT_EMPTY,
if there is/are left over received byte(s) this interrupt will be called again.
===================
CY_ISR(ISR_CMD_Handler)
{
if (UART_CMD_SpiUartGetRxBufferSize()) {
cmd_buf[cmd_write_index] = UART_CMD_UartGetByte() ;
cmd_write_index = (cmd_write_index + 1) % RX_BUF_LEN ;
}
UART_CMD_ClearRxInterruptSource(UART_CMD_INTR_RX_NOT_EMPTY) ;
}
===================
Then I prepared a function "int cmd_get_string()", which will copy a letter
from the ring-buffer to a string array "cmd_str[]".
During the receiving loop, it always returns 0,
but when it notices that an EOL letter such as '\r' or '\n' is received,
then it terminates the string with copying a NULL (0) at the last byte of cmd_str[]
and returns the length of the string, which is str_cmd_index.
Or in case the length of cmd_str[] which is counted by using str_cmd_index
exceeds the STR_LEN, it forces to close the string by writing NULL (0)
at cmd_str[STR_LEN]. and returns -1.
===================
int cmd_get_string(void)
{
int result = 0 ;
if (cmd_read_index != cmd_write_index) {
if (is_eol(cmd_buf[cmd_read_index])) {
cmd_str[str_cmd_index] = 0 ;
result = str_cmd_index ;
str_cmd_index = 0 ;
} else {
cmd_str[str_cmd_index++] = cmd_buf[cmd_read_index] ;
if (str_cmd_index >= STR_LEN) {
cmd_str[STR_LEN] = 0 ;
str_cmd_index = 0 ;
result = -1 ;
}
}
cmd_read_index = (cmd_read_index + 1) % RX_BUF_LEN ;
}
return(result) ;
}
===================
Now from the main loop, I can only call and check the return value of cmd_get_string() repeatedly.
Something like
int main(void)
{
...
for ( ; ; ) {
if (cmd_get_string()) {
/* if we came here, this means there is a received string in the "cmd_str[]"
}
}
}
Then if cmd_get_string() returned non-zero value, I'm sending the string to the GSM modem by calling
UART_GSM_UartPutSring(cmd_str) ;
and added an EOL by
UART_GSM_UartPutString("\n\r") ;
For receiving answer from GSM modem, I did the same thing, but function names were
ISR_GSM_Handler
gsm_get_string
so the main loop can test and notice if GSM returned something.
then I returned the gsm_str to the UART_CMD by using "print()" funciton.
print(gsm_str) ;
print("\n\r") ;
Additionally I added a utility function "prompt()" which only writes "> "
to notice the user that the program is ready to receive a new command.
Finally the main() looked like
======================
int main(void)
{
init_hardware() ;
splash("PC to GSM modem test") ;
prompt() ;
for(;;)
{
if (gsm_get_string()) { /* got a string from GSM Modem */
print(gsm_str) ;
print("\n\r") ;
prompt() ;
CyDelay(10) ;
}
if (cmd_get_string()) { /* got a string form PC */
UART_GSM_UartPutString(cmd_str) ;
UART_GSM_UartPutString("\r\n") ; /* send a terminator */
}
}
}
======================
Now if you'd like to have some macro or sequence type operation,
you could do
UART_GST_UartPutSTring("AT....") ;
while(gsm_get_seting()) {} ; /* wait for gsm to answer */
if (strcmp(gsm_str, "OK")==0) { /* gsm answered "OK" */
// do something next
} else { /* gsm answered otherwise */
// take care of error situation
}
Anyway, from here, it's your "Project".
So you are on your own.
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
UART_GST_UartPutSTring("AT....") ;
while(gsm_get_seting()) {} ; /* wait for gsm to answer */
if (strcmp(gsm_str, "OK")==0) { /* gsm answered "OK" */
// do something next
} else { /* gsm answered otherwise */
// take care of error situation
}
WHERE TO PUT THE ABOVE CAMMND IN THE PROGRAM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
> WHERE TO PUT THE ABOVE CAMMND IN THE PROGRAM
It's totally up to you.
But saying this won't answer you.
So let's see...
If I were you, I would write something like
===============
/*
* do_gsm_init()
* Note: "command to initialize" should be replaced with some meaningful command
* such as "AT"
*/
void do_gsm_init(void)
{
UART_GSM_UartPutString("command to initialize") ;
UART_GSM_UartPutString("\r\n") ;
while(gsm_set_string() == 0) { /* wait for gsm to answer */ }
print(gsm_str) ;
print("\n\r") ;
}
/*
* do_gsm_commandA()
* Note: "command to command A" should be replaced with some meaningful command
* such as "ATA", "ATDT12346", (btw, I don't know about your GSM modem command)
*/
void do_gsm_commandA(void)
{
UART_GSM_UartPutString("command for command A") ;
UART_GSM_UartPutString("\r\n") ;
while(gsm_set_string() == 0) { /* wait for gsm to answer */ }
print(gsm_str) ;
print("\n\r") ;
}
int main(void)
{
...
prompt() ;
for (;;) {
if (cmd_get_string()) {
if (strcmp(cmd_str, "init") == 0) { /* init command for gsm */
do_gsm_init() ;
} else if (strcmp(cmd_str, "commandA") == 0) { /* commandA for gsm */
do_gsm_commandA() ;
} else {
print("Unknown command: ") ;
print(cmd_str) ;
print("\n\r") ;
}
prompt() ;
}
}
}
===============
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
in the whole program, where to put the above.. after which line.. ?? programming is notmy cup oftea.. but still if you helpme by just putting the above command in proper place in program? then i would study the whole..
after this once the program is build.. what should be the next step.. how to connect and all..?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Can you give me same samples (2~3) of the commands?
Such as from your putty,
if you type "xxx" -> GSM answers "zzz"
Then I will put them into the sample.
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content