- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi gentlemans, here im working with PSoC5LP, I want to print at lcd the answer from an SIM808 module (UART), if I send the string "AT", SIM808 should answer "OK",but the result is a lot of meanless characters.
This is the code that im using for that operation:
UART_PutString("AT");
LCD_Position(1,0);
LCD_PrintString(UART_GetChar);
CyDelay(100);
PLease assist me to find the way to put "OK" in the LCD.
Thanks a lot!!!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
If the module, SIM808? works just like hayes modem,
I think that we need to add a newline after "AT"
or it will wait for additional options, such as "+" or "T" or.. you name it.
So I made a sample project which will send "AT\n"
and try to receive a string then show it to either LCD or UART.
(As I don't have LCD, I used UART again with preceding string "LCD:")
Meantime, I cheated to use my uart sample
tty_utils a utility sample for CLI type program
with this tty_utils.h and tty_utils.c were added to the project.
As I placed both files in the "sources" folder in the project,
include path needed to be added.
To avoid it just copy these 2 files in your project folder, where main.c resides.
So the main.c looks like
===============
#include "project.h"
#include "stdio.h"
#include "string.h"
#include "tty_utils.h"
#define USE_LCD 0
void init_hardware(void)
{
tty_init() ;
CyGlobalIntEnable; /* Enable global interrupts. */
}
int main(void)
{
init_hardware() ;
splash("SIM808 Test using tty_utils") ; /* you may want to comment out this */
for(;;)
{
UART_PutString("AT\n") ;
while(get_string() == 0) { /* wait for a string to arive from UART */
; /* wait for a string to arrive */
}
// when get_string() returns, the string is in "str[]" buffer
#if USE_LCD
LCD_Position(1, 0) ;
LCD_PrintString(str) ;
#else // as I don't have LCD, again use UART to reflect the received answer
UART_PutString("LCD: ") ;
UART_PutString(str) ;
UART_PutString("\n") ;
#endif
CyDelay(1000) ;
}
}
===============
When ran with CY8CKIT-059 the Tera Term Log was
What happning here are
(1) "AT\n" was sent from PSoC to PC (let's assume it a SIM808)
(2) I pretended to be SIM808 and typed "OK" + Enter
(3) PSoC 5LP received a string and tried to write it on LCD,
(here UART is pretending to be LCD with "LCD: ")
(4) PSoC sent "AT\n" again
(5) I answered "NO\n"
(6) "NO" is written on the LCD
and so on.
NOTE: To use on a system with LCD, please change following line
from
#define USE_LCD 0
to
#define USE_LCD 1
Also in the schematic I used rx_interrupt of UART as tty_rx_int
Hope this can be a little hint.
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There are two problems.
1. The UART_GetChar is a function returning a received character. The function call is described as UART_GetChar()
2. The LCD_PrintString() function accepts a string, a pointer to an array of char type values. If you want to print a single character, use LCD_PutChar()
If you want to receive two characters and print these two characters, the line should be
LCD_PutChar(UART_GetChar());
LCD_PutChar(UART_GetChar());
Regards,
Noriaki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Noriaki.
Thank you for your reply.
I tried both ways but the difference was the number of characters:
1) Using PrintChar: Pic 1
2) Using PutChar: Pic 2
What I’m trying to do is to communicate between BK-SIM808V2 module and PSoC5LP through the UART, using AT commands, so I’ve put chars in the UART and SIM808 should answer with char, the most simple command is “AT”, SIM808 should answer “OK”, but I’m getting what you can see in the pictures. By the way, I’m trying to do that with 16x2 LCD and also an OLED display at the same time.
The thing with the OLED is that the library just have two ways to print: print() and println(), I’ve tried both but steel see weird characters.
Pic1:
while(UART_GetChar() != '0')
{
gfx_setTextSize(2);
gfx_setTextColor(WHITE);
gfx_setCursor(0,25);
display_clear();
gfx_println("GET CHAR");
LCD_Position(1,0);
//bufi1=UART_GetChar;
LCD_PutChar(UART_GetChar());
LCD_PutChar(UART_GetChar());
gfx_setTextSize(2);
gfx_setTextColor(WHITE);
gfx_setCursor(0,0);
bufi2=UART_GetChar;
gfx_print(bufi2);
display_update();
CyDelay(100);
timeout++;
Pic 2:
while(UART_GetChar() != '0')
{
gfx_setTextSize(2);
gfx_setTextColor(WHITE);
gfx_setCursor(0,25);
display_clear();
gfx_println("GET CHAR");
LCD_Position(1,0);
//bufi1=UART_GetChar;
LCD_PutChar(UART_GetString());
LCD_PutChar(UART_GetString());
gfx_setTextSize(2);
gfx_setTextColor(WHITE);
gfx_setCursor(0,0);
bufi2=UART_GetChar;
gfx_print(bufi2);
display_update();
CyDelay(100);
timeout++;
Thank you so much Noraki, I’m appreciate your help.
Jose Francisco Rodriguez.
De: Noriaki Tanaka
Enviado el: jueves, 18 de julio de 2019 7:34 p. m.
Para: José Francisco Rodríguez Trillos <jrodriguez@colsugar.com>
Asunto: Re: - PSoC 5LP: Print in LCD a SIM808 module (UART) answer
<http://www.cypress.com>
Cypress Developer Community <https://community.cypress.com/?et=watches.email.thread>
PSoC 5LP: Print in LCD a SIM808 module (UART) answer
reply from Noriaki Tanaka<https://community.cypress.com/people/NoriakiT_91?et=watches.email.thread> in PSoC 5LP MCU Community - View the full discussion<https://community.cypress.com/message/203056?et=watches.email.thread#203056>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The UART component Datasheet says about UART_GetChar() function as follows.
UART_GetChar() function returns a character or ZERO. ZERO does not mean a character '0'
Once the UART_GetChar() function returns a character, that character is consumed and disappear from the RX buffer. So, it is required to store the received value into a variable like.
{
uint8 ch;
while ((ch = UART_GetChar()) == 0);
LCD_PutChar(ch);
while ((ch = UART_GetChar()) == 0);
LCD_PutChar(ch);
}
You can get two characters and write into LCD.
Regards,
Noriaki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
If the module, SIM808? works just like hayes modem,
I think that we need to add a newline after "AT"
or it will wait for additional options, such as "+" or "T" or.. you name it.
So I made a sample project which will send "AT\n"
and try to receive a string then show it to either LCD or UART.
(As I don't have LCD, I used UART again with preceding string "LCD:")
Meantime, I cheated to use my uart sample
tty_utils a utility sample for CLI type program
with this tty_utils.h and tty_utils.c were added to the project.
As I placed both files in the "sources" folder in the project,
include path needed to be added.
To avoid it just copy these 2 files in your project folder, where main.c resides.
So the main.c looks like
===============
#include "project.h"
#include "stdio.h"
#include "string.h"
#include "tty_utils.h"
#define USE_LCD 0
void init_hardware(void)
{
tty_init() ;
CyGlobalIntEnable; /* Enable global interrupts. */
}
int main(void)
{
init_hardware() ;
splash("SIM808 Test using tty_utils") ; /* you may want to comment out this */
for(;;)
{
UART_PutString("AT\n") ;
while(get_string() == 0) { /* wait for a string to arive from UART */
; /* wait for a string to arrive */
}
// when get_string() returns, the string is in "str[]" buffer
#if USE_LCD
LCD_Position(1, 0) ;
LCD_PrintString(str) ;
#else // as I don't have LCD, again use UART to reflect the received answer
UART_PutString("LCD: ") ;
UART_PutString(str) ;
UART_PutString("\n") ;
#endif
CyDelay(1000) ;
}
}
===============
When ran with CY8CKIT-059 the Tera Term Log was
What happning here are
(1) "AT\n" was sent from PSoC to PC (let's assume it a SIM808)
(2) I pretended to be SIM808 and typed "OK" + Enter
(3) PSoC 5LP received a string and tried to write it on LCD,
(here UART is pretending to be LCD with "LCD: ")
(4) PSoC sent "AT\n" again
(5) I answered "NO\n"
(6) "NO" is written on the LCD
and so on.
NOTE: To use on a system with LCD, please change following line
from
#define USE_LCD 0
to
#define USE_LCD 1
Also in the schematic I used rx_interrupt of UART as tty_rx_int
Hope this can be a little hint.
moto