|
|
View previous topic :: View next topic |
Author |
Message |
qwwe
Joined: 17 Sep 2017 Posts: 59
|
Problem in uart communication programming |
Posted: Sun Sep 17, 2017 7:48 am |
|
|
Hello
I have written the following program.
In this program I would like to send information to the sim900 module and display the information received on an LCD. But in the Proteus simulator, in the debug mode, the line 26 reaches the program. And rs232 gives Error.
What do you think is the problem ?
Code: |
#include <16f1829.h>
#include <stdio.h>
#include <string.h>
#fuses HS,wdt
#use delay(crystal=12000000,restart_wdt)
#use RS232(baud=9600,xmit=PIN_C4,RCV=PIN_C5,parity=n,bits=8,errors,ENABLE=PIN_A0,restart_wdt)
#define lcd_use_portb_lcd true
#define LCD_ENABLE_PIN PIN_C0
#define LCD_RS_PIN PIN_C1
#define LCD_RW_PIN PIN_C2
#define LCD_DATA4 PIN_B4
#define LCD_DATA5 PIN_B5
#define LCD_DATA6 PIN_B6
#define LCD_DATA7 PIN_B7
#include <lcd.c>
char recive[10];
char dq=34,enter=13,cz=26,linfeed=10;
#int_EXT
void EXT_isr(){
disable_interrupts(INT_EXT);
printf("AT%c",enter);
delay_ms(1000);
printf("AT+IPR=0%c",enter);
delay_ms(1000);
printf("ATE0%c",enter);
delay_ms(1000);
printf("AT+CMGF=1%c",enter);
delay_ms(1000);
if (kbhit()){
gets(recive);
delay_ms(10);
lcd_gotoxy(1,1);
delay_ms(10);
printf(lcd_putc,"a=%s",recive);
}
delay_ms(10);
enable_interrupts(INT_EXT);
}
void main()
{
lcd_init();
enable_interrupts(INT_EXT);
ext_int_edge(l_to_h);
enable_interrupts(GLOBAL);
while(true){
restart_wdt();
}
}
|
Simulation images in proteus.
[img]
http://uupload.ir/files/24te_sd.png
[/img]
[img]
http://uupload.ir/files/zlt2_sd2.png
[/img] |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19512
|
|
Posted: Sun Sep 17, 2017 8:09 am |
|
|
Code: |
//These:
#include <stdio.h>
#include <string.h>
|
Should be _after_ all fuses, serial setup, clock setup etc..
You shouldn't really be doing all the work in the interrupt.
The rule for writing interrupt handlers, is that they should contain the smallest amount of code possible to handle the hardware event only.
Interrupts are already disabled once you are in an interrupt handler anyway.
Set a flag when the interrupt triggers and do the rest in the main, or simply monitor the input pin, and trigger the code when it changes.
Carriage return, codes in C as '\r'. So:
printf("AT+IPR=0%c",enter);
Just needs:
printf("AT+IPR=0\r");
etc..
Line feed is '\n'. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Sun Sep 17, 2017 8:17 am |
|
|
couple of other points...
In the USE RS232(....) you have a pin designated for enable. This implies and RS485 style interface...does your SIM900 have this abilty ?
also
get rid of the WDT code. Until your program runs flawlessly a WDT is not required and could cause problems.
also
most peripherals these days are 3 volts, is your SIM900 3 volts?
good news is that PIC is 3 volt !
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19512
|
|
Posted: Sun Sep 17, 2017 8:38 am |
|
|
There is also another point.
Unless it has a hardware reset circuit, the SIM900, normally needs to be woken up. You have to either manually operate the wake up connection, or have a PIC connection to operate this, or it won't talk. It switches on in the 'idle' state. |
|
|
qwwe
Joined: 17 Sep 2017 Posts: 59
|
Problem in uart communication programming |
Posted: Sun Sep 17, 2017 10:57 am |
|
|
Thank you for answering
I changed the programming as follows, and the rest of the program does not stand in the order I said before.
But this time it stands in the line outlined in the screenshots below.
Namely, as it is known, it sends commands in the terminal and receives the response.
But the turn of the display shows the amount received on the LCD as you can see.
Meanwhile, I disabled the wdt, but it did not work
I simulate this in Proteus software, not in practice. As a result, the sim900 module does not need to turn on.
Thanks for the last help
Thanks for helping again
Code: |
#include <16f1829.h>
#fuses HS,wdt
#use delay(crystal=12000000,restart_wdt)
#use RS232(ENABLE=PIN_A0,baud=9600,xmit=PIN_C4,RCV=PIN_C5,parity=n,bits=8,errors,restart_wdt)
#include <stdio.h>
#include <string.h>
#define lcd_use_portb_lcd true
#define LCD_ENABLE_PIN PIN_C0
#define LCD_RS_PIN PIN_C1
#define LCD_RW_PIN PIN_C2
#define LCD_DATA4 PIN_B4
#define LCD_DATA5 PIN_B5
#define LCD_DATA6 PIN_B6
#define LCD_DATA7 PIN_B7
#include <lcd.c>
#include <stdio.h>
#include <string.h>
char recive[10];
char dq=34,enter=13,cz=26,linfeed=10,i=0;
#int_EXT
void EXT_isr(){
disable_interrupts(INT_EXT);
i=1;
delay_ms(10);
enable_interrupts(INT_EXT);
}
void main()
{
lcd_init();
enable_interrupts(INT_EXT);
ext_int_edge(l_to_h);
enable_interrupts(GLOBAL);
while(true){
if(i==1)
{
printf("AT%c",enter);
delay_ms(1000);
printf("AT+IPR=0%c",enter);
delay_ms(1000);
printf("ATE0%c",enter);
delay_ms(1000);
printf("AT+CMGF=1%c",enter);
delay_ms(1000);
if (kbhit()){
gets(recive);
delay_ms(10);
lcd_gotoxy(1,1);
delay_ms(10);
printf(lcd_putc,"a=%s",recive);
}
i=0;
}
restart_wdt();
}
}
|
[img]
http://uupload.ir/files/nidh_untitled5.png
[/img]
[img]
http://uupload.ir/files/k6b2_untitled4.png
[/img]
In addition, ccs also gives the following warnings
>>> Warning 216 "test5.c" Line 57(1,2): Interrupts disabled during call to prevent re-entrancy: (@delay_ms1)
>>> Warning 202 "test5.c" Line 19(6,8): Variable never used: dq
>>> Warning 202 "test5.c" Line 19(21,23): Variable never used: cz
>>> Warning 202 "test5.c" Line 19(27,34): Variable never used: linfeed
Memory usage: ROM=10% RAM=3% - 6%
0 Errors, 4 Warnings.
Build Successful. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19512
|
|
Posted: Sun Sep 17, 2017 11:03 am |
|
|
That is because you have put a delay in the interrupt.
Get rid of it.
Also you are still pointlessly disabling interrupts.
Code: |
int1 have_interrupt=FALSE;
#int_EXT
void EXT_isr(void)
{
have_interrupt=TRUE;
}
//Other stuff omitted
while(true)
{
if(have_interrupt)
{
have_interrupt=FALSE; //otherwise it'll repeat forever
printf("AT\r");
delay_ms(1000);
//etc..
|
The other errors are because you have declared three variables you don't use.... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Sun Sep 17, 2017 2:38 pm |
|
|
The BIG problem is that you're using a defective 'simulator', aka Proteus ! Do NOT trust that Proteus actually works, it doesn't even simulate a PIC properly, I seriously doubt they can emulate the SIM900 die.
Also you need to tell us WHICH 'SIM900' you're trying to use, the actual hardware as I still don't see why you need an 'enable' pin if using true RS232.
Without seeing a schematic as well as true parts lists, fixing code ,line by line, is a futile effort.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19512
|
|
Posted: Sun Sep 17, 2017 2:45 pm |
|
|
He doesn't need an enable pin. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Sun Sep 17, 2017 3:03 pm |
|
|
But we don't know where he's using it... without a schematic, it's anybody's guess....
then again this is a 'Proteus Project' so it'll work no matter what ! |
|
|
qwwe
Joined: 17 Sep 2017 Posts: 59
|
Problem in uart communication programming |
Posted: Sun Sep 17, 2017 11:04 pm |
|
|
I myself thought that the problem was from Proteus, but I wanted to make sure that the program I wrote did not have a problem.
Schematic circuit is also available at the following link.
I used an active pin to turn on an LED to indicate that the microcontroller is sending data, just that.
thank you
http://uupload.ir/files/q74h_untitled5.png |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|