Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

digital thermometer

digital thermometer

2009-05-18 by alex levenie

hi everybody,i hope you all be fine
my circuit is a digital thermometer using two lm35(sensor), atmega8(master), two atmega 32(slaves)
the master must read two sensors output voltage and send each one to different slave ,
the slaves must show the tempreture according to corresponding formula , 
but the circuit dosn't work,it just show the primary data on lcd ("hello...")

but after the turning on the circuit ,I must disconnect and connect the power supply in a very short time to make the circuit show the tempreture,also sometimes one of slaves show (after that work) sometimes two , sometimes none of them
please help me
here is the master program:
/*****************************************************
Chip type           : ATmega8
Program type        : Application
Clock frequency     : 1.000000 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 256
*****************************************************/
#include <mega8.h>
#include <delay.h>
// SPI functions
#include <spi.h>

#define   Slave_select_1  PORTD.7
#define   Slave_select_2  PORTB.0
#define   ADC_VREF_TYPE  0xE0
                          
unsigned char read_adc(unsigned char);
void main(void)
{
 
PORTB=0x00;
DDRB=0x2D;
PORTD=0x00;
DDRD=0x80;
// ADC initialization
// ADC Clock frequency: 125.000 kHz
// ADC Voltage Reference: Int., cap. on AREF
// ADC High Speed Mode: Off
ADMUX=ADC_VREF_TYPE;
ADCSRA=0x83;
SFIOR&=0xEF;
// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 250.000 kHz
// SPI Clock Phase: Cycle Start
// SPI Clock Polarity: High
// SPI Data Order: LSB First
SPCR=0x7C;
SPSR=0x00; 
Slave_select_1=1;
Slave_select_2=1;
while (1)
      {
      Slave_select_1=0;
      spi(read_adc(5));
      Slave_select_1=1;
      
      Slave_select_2=0;
      spi(read_adc(4));
      Slave_select_2=1;
      delay_ms(500);
      };
}
and this is the slave program:
/*****************************************************
Chip type           : ATmega32
Program type        : Application
Clock frequency     : 1.000000 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 256
*****************************************************/
#include <mega32.h>
// SPI functions
#include <spi.h>
#include <stdio.h> 
#include <stdlib.h> 
#include <delay.h>
// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x12
#endasm
#include <lcd.h>

char buffer_lcd[40],lcd[40];
void main(void)
{
PORTB=0x00;
DDRB=0x40;
PORTD=0x00;
DDRD=0x00;
// SPI initialization
// SPI Type: Slave
// SPI Clock Rate: 250.000 kHz
// SPI Clock Phase: Cycle Start
// SPI Clock Polarity: High
// SPI Data Order: LSB First
SPCR=0xEC;
SPSR=0x00;
// Clear the SPI interrupt flag
#asm
    in   r30,spsr
    in   r30,spdr
#endasm
lcd_init(20);
lcd_clear();
lcd_putsf("hello"); 
delay_ms(1000);
lcd_clear();
lcd_putsf("micolab project"); 
delay_ms(1000);
lcd_clear();
lcd_putsf("first semester"); 
delay_ms(1000);
lcd_gotoxy(0,1);
lcd_putsf("2009"); 
delay_ms(2000);
// Global enable interrupts
#asm("sei")
while (1);
}
//------------------------------------
// SPI interrupt service routine
interrupt [SPI_STC] void spi_isr(void)
{
   unsigned char data;
   float temp ,index;
   data=SPDR;       
   index=data*2.56/256;
   temp=index/0.01;
   lcd_clear();
   ftoa(temp,2,buffer_lcd);
   sprintf(lcd,"temp %2s \xdfc ",buffer_lcd);
   lcd_puts(lcd);
}
that's all , please help me



      

[Non-text portions of this message have been removed]

Re: [AVR-Chat] digital thermometer

2009-05-18 by John Samperi

At 10:24 PM 18/05/2009, you wrote:
>I must disconnect and connect the power supply in a very short time

What does the hardware look like? Do you have a good reset circuit
or use the BOD?

Regards

John Samperi

********************************************************
Ampertronics Pty. Ltd.
11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
Tel. (02) 9674-6495       Fax (02) 9674-8745
Website  http://www.ampertronics.com.au
*Electronic Design * Custom Products * Contract Assembly
********************************************************

Re: digital thermometer

2009-05-19 by Brian

Im not strong in SPI but is there sufficent delay in the spi.h to allow data transfer before you set the slave select high? Try adding a 30 ms delay after the adc mesurement and before setting the slave select to high. this should give enough time for slave 1 to recieve the data before slave 2 sets to recieve data. I cant see nothing else wrong but I am only a beginner.

Brian

--- In AVR-Chat@yahoogroups.com, alex levenie <secret0police@...> wrote:
Show quoted textHide quoted text
>
> hi everybody,i hope you all be fine
> my circuit is a digital thermometer using two lm35(sensor), atmega8(master), two atmega 32(slaves)
> the master must read two sensors output voltage and send each one to different slave ,
> the slaves must show the tempreture according to corresponding formula , 
> but the circuit dosn't work,it just show the primary data on lcd ("hello...")
> 
> but after the turning on the circuit ,I must disconnect and connect the power supply in a very short time to make the circuit show the tempreture,also sometimes one of slaves show (after that work) sometimes two , sometimes none of them
> please help me
> here is the master program:
> /*****************************************************
> Chip type           : ATmega8
> Program type        : Application
> Clock frequency     : 1.000000 MHz
> Memory model        : Small
> External SRAM size  : 0
> Data Stack size     : 256
> *****************************************************/
> #include <mega8.h>
> #include <delay.h>
> // SPI functions
> #include <spi.h>
> 
> #define   Slave_select_1  PORTD.7
> #define   Slave_select_2  PORTB.0
> #define   ADC_VREF_TYPE  0xE0
>                           
> unsigned char read_adc(unsigned char);
> void main(void)
> {
>  
> PORTB=0x00;
> DDRB=0x2D;
> PORTD=0x00;
> DDRD=0x80;
> // ADC initialization
> // ADC Clock frequency: 125.000 kHz
> // ADC Voltage Reference: Int., cap. on AREF
> // ADC High Speed Mode: Off
> ADMUX=ADC_VREF_TYPE;
> ADCSRA=0x83;
> SFIOR&=0xEF;
> // SPI initialization
> // SPI Type: Master
> // SPI Clock Rate: 250.000 kHz
> // SPI Clock Phase: Cycle Start
> // SPI Clock Polarity: High
> // SPI Data Order: LSB First
> SPCR=0x7C;
> SPSR=0x00; 
> Slave_select_1=1;
> Slave_select_2=1;
> while (1)
>       {
>       Slave_select_1=0;
>       spi(read_adc(5));
>       Slave_select_1=1;
>       
>       Slave_select_2=0;
>       spi(read_adc(4));
>       Slave_select_2=1;
>       delay_ms(500);
>       };
> }
> and this is the slave program:
> /*****************************************************
> Chip type           : ATmega32
> Program type        : Application
> Clock frequency     : 1.000000 MHz
> Memory model        : Small
> External SRAM size  : 0
> Data Stack size     : 256
> *****************************************************/
> #include <mega32.h>
> // SPI functions
> #include <spi.h>
> #include <stdio.h> 
> #include <stdlib.h> 
> #include <delay.h>
> // Alphanumeric LCD Module functions
> #asm
>    .equ __lcd_port=0x12
> #endasm
> #include <lcd.h>
> 
> char buffer_lcd[40],lcd[40];
> void main(void)
> {
> PORTB=0x00;
> DDRB=0x40;
> PORTD=0x00;
> DDRD=0x00;
> // SPI initialization
> // SPI Type: Slave
> // SPI Clock Rate: 250.000 kHz
> // SPI Clock Phase: Cycle Start
> // SPI Clock Polarity: High
> // SPI Data Order: LSB First
> SPCR=0xEC;
> SPSR=0x00;
> // Clear the SPI interrupt flag
> #asm
>     in   r30,spsr
>     in   r30,spdr
> #endasm
> lcd_init(20);
> lcd_clear();
> lcd_putsf("hello"); 
> delay_ms(1000);
> lcd_clear();
> lcd_putsf("micolab project"); 
> delay_ms(1000);
> lcd_clear();
> lcd_putsf("first semester"); 
> delay_ms(1000);
> lcd_gotoxy(0,1);
> lcd_putsf("2009"); 
> delay_ms(2000);
> // Global enable interrupts
> #asm("sei")
> while (1);
> }
> //------------------------------------
> // SPI interrupt service routine
> interrupt [SPI_STC] void spi_isr(void)
> {
>    unsigned char data;
>    float temp ,index;
>    data=SPDR;       
>    index=data*2.56/256;
>    temp=index/0.01;
>    lcd_clear();
>    ftoa(temp,2,buffer_lcd);
>    sprintf(lcd,"temp %2s \xdfc ",buffer_lcd);
>    lcd_puts(lcd);
> }
> that's all , please help me
> 
> 
> 
>       
> 
> [Non-text portions of this message have been removed]
>

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.