CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

sht11 with rs232 communication problem! Please Help!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
softjad



Joined: 21 Sep 2006
Posts: 3

View user's profile Send private message

sht11 with rs232 communication problem! Please Help!
PostPosted: Wed Jun 13, 2007 5:45 am     Reply with quote

Hello.

Driver for SHT: http://www.ccsinfo.com/forum/viewtopic.php?t=28564

I tried this driver with sht11, and I had a problem:

In my project, I have an interruption int_rda (reception of data rs232), but when I execute the function sht_rd (restemp, truehumid);, the interruption stops working.
I get to send data by int_tbe (transmitting of data rs232), but I don't get to receive data after the first reading of the sensor.

Somebody know because it is that the interruption stops working?

Thanks
Ttelmah
Guest







PostPosted: Wed Jun 13, 2007 7:12 am     Reply with quote

My guess would be, that you have something called in both the INT_RDA function, and in the rest of the code, which results in the interrupt being disabled in the sht_rd function. then when the interrupt is re-enabled, the UART has suffered an overrun error, and you do not have 'errors' set in your USE RS232 setup, so it never recovers.

Best Wishes
Guest








PostPosted: Thu Jun 14, 2007 4:04 am     Reply with quote

what alterations do have to do for the interruption int_rda not to stop?
My program is the next:
Code:

#include <18F4550.h>

#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,PLL5,CPUDIV1,VREGEN
#use delay(clock = 48000000)

#include "../include\picram18F4550.h"
#include "../include\types.h"
#include "../include\lcd.c"


#include <sht.h>

int16 contagem = 0, contagem2 =0;
int8 recebido = 0;

int16 adc[4] = {0,0,0,0};
int8 canal=0;

float sht_temperatura, sht_humidade;

void actualizar_dados(void);

//Timer 1
#INT_TIMER1
void rsi_t1 (void)
{

   if (contagem >= 500)
   {
   output_toggle(PIN_C0);
   contagem = 0;

   }

   if (contagem2 >=300)
   {
   enable_interrupts(int_tbe);
   contagem2 = 0;
   }


   contagem++;
   contagem2++;


   TMR1H = 0xF1;
   TMR1L = 0x5A;
}

//RX interrupt
#int_RDA
void RDA_isr(void)
{
   recebido=RCREG;
}

//TX interrupt
#int_TBE
void TBE_isrb(void)
{
TXREG = adc[0];
}

#INT_AD
void rsi_ad(void)
{
ADFM = 1;
adc[0] = (ADRESH*256) + ADRESL;
GODONE=1;
}


void main(void)
{

   TRISD=0b00000000;
   TRISB=0b00000000;
   TRISC=0b11111000;
   TRISA=0b11111111;

   //Timer1
   T1CON = 0b11110000;
   TMR1H = 0xF1;
   TMR1L = 0x5A;

   //ADC
   ADCON0=0b00000000;
   ADCON1=0b00011011;
   ADCON2=0b10111110;

   //RS-232
   SPBRG=77;   //9600
   BRG16=0;
   BRGH=0;
   SYNC=0;     //assincrono
   SPEN=1;
   TXEN=1;     //TX
   RX9=0;      //TX a 9bits
   TX9=0;      //RX a 9bits
   CREN=1;     //RX
   SENDB=1;



   TMR1IE=1;
   PEIE=1;
   ADIE=1;
   GIE=1;
   RCIE=1;
   ENABLE_INTERRUPTS(INT_TBE);

   TMR1ON=1;
   ADON=1;
   GODONE=1;


   lcd_init();
   sht_init();

   delay_ms(500);
   lcd_putc('\f');
   lcd_putc("Projecto:");
   lcd_gotoxy(1,2);
   lcd_putc("Sensor Test");
   delay_ms(500);
   lcd_putc('\f');


   while (true)
   {

   lcd_gotoxy(12,1);
   printf(lcd_putc,"%d",recebido);
   lcd_gotoxy(1,1);
   printf(lcd_putc, "%3.1f%cC", sht_temperatura, 223);
   printf(lcd_putc, "%3.1f%%", sht_humidade);
   lcd_gotoxy(1,1);

   }

}
[/quote]
Ttelmah
Guest







PostPosted: Thu Jun 14, 2007 4:35 am     Reply with quote

Seriously, write the code again.....
If you want to do all these bitwise accesses to things, then use assembler. You have a high level language, so use it...

Add a #use RS232, get rid of all the bit operations on the transmitter and receiver registers, add 'errors' to the use RS232, which will clear the overrun error, and use getc, to fetch the character, so the extra code needed for this is called.
Your ADC code, and INT_TBE code, are the big lumps, of what is causing the problem. INT_AD, is called whenever the ADC completes a conversion. You are triggering a conversion inside the ADC code, so once this code is triggered, the routine will hardly exit. If you want repeated ADC conversions at a fast interval, use the CCP module, programmed to the required interval, and the special event trigger to operate the ADC. Otherwise this will lead to a huge bottleneck. The second problem though isthe INT_TBE. You enable it's interrupt in the timer, but do not _disable_ it, once a character has been sent. Hence it'll also keep calling repeatedly.
This code is a _mess_ I'm afraid...

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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