|
|
View previous topic :: View next topic |
Author |
Message |
Mahdi
Joined: 21 Aug 2012 Posts: 47
|
gets() problem |
Posted: Sun Dec 29, 2013 5:24 am |
|
|
hi buddies
i want to send string and receive with uart protocol in isis simulator
transmitter code :
Code: | #include <33FJ32MC204.h>
#use delay(crystal=80M)
#pin_select U1TX=PIN_C6
#pin_select U1RX=PIN_C7
#use rs232(UART1, baud=230400,errors)
#include <stdio.h>
#include <string.h>
#INCLUDE <stdlib.h>
#include <LCD.C>
void main()
{
lcd_init();
signed int8 x=10,y=-20,z=35,a=0;
unsigned int8 trt,batt;
char trt1[40],x1[10],y1[10],z1 [10],crt[2];
strcpy(trt1,"");
strcpy(x1,"");
strcpy(y1,"");
strcpy(crt,",");
while(TRUE)
{
itoa(trt,10, trt1);
itoa(x,10, x1);
itoa(y,10, y1);
itoa(z,10, z1);
strcat(trt1,crt);
strcat(trt1,x1);
strcat(trt1,crt);
strcat(trt1,y1);
strcat(trt1,crt);
strcat(trt1,z1);
lcd_gotoxy(1,1);
printf(lcd_putc,"%s",trt1);
puts(trt1);
delay_ms(10);
}
} |
receiver code :
Code: |
#include <33fj32mc204.h>
#use delay(crystal=80m)
#use i2c(MASTER,I2C1,FAST)
#pin_select U1RX=PIN_C7
#pin_select U1TX=PIN_C6
#use rs232(UART1,baud=230400,errors)
#define gyro_xsens 6
#define gyro_ysens 6
#define gyro_zsens 6
#include <var.c>
#INCLUDE <lcd.c>
char x1 [40],bb;
#INT_RDA
void rda_isr(void)
{
output_high(pin_a1);
gets(x1);
bb=getc();
output_low(pin_a1);
}
#INT_TIMER3
void timer3_isr(void)
{
output_high(pin_a0);
i2c_start();
i2c_write(0xd0);
i2c_write(0x43);
i2c_start();
i2c_write(0xd1);
gxh=i2c_read(1);
gxl=i2c_read(0);
i2c_stop();
i2c_start();
i2c_write(0xd0);
i2c_write(0x45);
i2c_start();
i2c_write(0xd1);
gyh=i2c_read(1);
gyl=i2c_read(0);
i2c_stop();
i2c_start();
i2c_write(0xd0);
i2c_write(0x47);
i2c_start();
i2c_write(0xd1);
gzh=i2c_read(1);
gzl=i2c_read(0);
i2c_stop();
gx = make16(gxh,gxl) - gx_OFFSET;
gy = make16(gyh,gyl) - gy_OFFSET;
gz = make16(gzh,gzl) - gz_OFFSET;
gxrate = gx/gyro_xsens;
gyrate = gy/gyro_ysens;
gzrate = gz/gyro_zsens;
output_low(pin_a0);
}
void main(){
lcd_init();
setup_timer3(TMR_INTERNAL | TMR_DIV_BY_64, 1562);
enable_interrupts(INT_timer3);
enable_interrupts(INT_RDA);
enable_interrupts(INTR_GLOBAL);
while(TRUE){
}
}
|
i use pin a1 for rda interrupt to measure period of interrupt(blue line)
and pina0 for timer3 interrupt to measure............. (yellow line)
in rda interrupt i have 500 us delay until data received
in timer3 interrupt i have 90 us delay until interrupt finished and timer3 set to 2.5 ms and fire.
all things is work but After a period of time, rda interrupt lock for 10 ms why?
ccs v 5
thanks |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Sun Dec 29, 2013 6:13 am |
|
|
Thats one strange baud rate.
Read the sticky post related to Proteus.
Why not just make a small sample program to comunicate between the pics first and then include all the other stuff you are doing? That way you know your comms are working.
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Sun Dec 29, 2013 8:19 am |
|
|
A number of comments ignoring Proteus....
1) What is the maximum crystal frequency the chip supports?......
This will stop the code working in a real chip.
2) INT_RDA, implies _one_ character is available to be read. Do a search here for why you should not use 'gets' in this interrupt, and for replacements.
INT_RDA used like this will lock the receive chip, till a line feed is seen. |
|
|
Mahdi
Joined: 21 Aug 2012 Posts: 47
|
|
Posted: Sun Dec 29, 2013 12:30 pm |
|
|
Ttelmah wrote: | A number of comments ignoring Proteus....
1) What is the maximum crystal frequency the chip supports?......
This will stop the code working in a real chip.
2) INT_RDA, implies _one_ character is available to be read. Do a search here for why you should not use 'gets' in this interrupt, and for replacements.
INT_RDA used like this will lock the receive chip, till a line feed is seen. |
thanks
when i disable timer3 interrupt the rda interrupt work without any problem.
In my opinion the getc() clear buffer and flag of interrupt but gets() cant it.
now i should clear flag of uart receiver but how ? |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Mon Dec 30, 2013 12:59 am |
|
|
Mahdi wrote: | when i disable timer3 interrupt the rda interrupt work without any problem.
In my opinion the getc() clear buffer and flag of interrupt but gets() cant it. | gets will clear the buffer and interrupt flag, but it's the wrong function for a serial interrupt handler. You might think it's working, but it isn't. INT_RDA is called for each character and you need to call getc() exactly once for each interrupt. Usually your interrupt handler will put each character into a buffer which your mainline loop will read. See the CCS example "EX_SISR.C". If you need gets() functionality, you will need to write it yourself. _________________ Andrew |
|
|
|
|
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
|