sherazi
Banned
- Joined
- Feb 15, 2010
- Messages
- 388
- Helped
- 61
- Reputation
- 126
- Reaction score
- 61
- Trophy points
- 1,318
- Location
- Muscat, Oman, Oman
- Activity points
- 0
Regards All!
i am tring to make a simple circuit that has ds1820 thats interfaced to atmega8, and atmega8 has a rs485 interface with pc.
i have the circuit as shown in attached pdf, sensor is fine and transmit is also fine , i am having problems with rx, the circuit should give the temperature when it resscieves the character 's' but it dosent respond or some times start giving temp by itself, can u check the code and circuit, code is ok in proteus ... iam attaching that also.
2shared - download sim-mega8.DSN
plz check if there is problem with hardware or code for 485
i am tring to make a simple circuit that has ds1820 thats interfaced to atmega8, and atmega8 has a rs485 interface with pc.
i have the circuit as shown in attached pdf, sensor is fine and transmit is also fine , i am having problems with rx, the circuit should give the temperature when it resscieves the character 's' but it dosent respond or some times start giving temp by itself, can u check the code and circuit, code is ok in proteus ... iam attaching that also.
Code:
#include "definitions.h"
#include <avr/io.h>
#include <inttypes.h>
#include <stdio.h>
#include "init.h"
#include "ds18x20.h"
#include "onewire.h"
#include "delayintr.h"
#include "util/delay.h"
uint8_t gSensorIDs[MAXSENSORS][OW_ROMCODE_SIZE];
void recieve_enable()
{
_delay_ms(3);
PORTC&=0xDF;
}
uint8_t search_sensors(void)
//Searches for sensors on the bus.
{
PORTC|=0x20;
uint8_t i;
uint8_t id[OW_ROMCODE_SIZE];
uint8_t diff, nSensors;
nSensors = 0;
for( diff = OW_SEARCH_FIRST;
diff != OW_LAST_DEVICE && nSensors < MAXSENSORS ; )
{
DS18X20_find_sensor( &diff, &id[0] );
if( diff == OW_PRESENCE_ERR ) {
tx( "No Sensors found " );
tx( " " );
return 255;
}
if( diff == OW_DATA_ERR ) {
tx( "Bus Error " );
tx( " " );
return 255;
}
for (i=0;i<OW_ROMCODE_SIZE;i++)
gSensorIDs[nSensors][i]=id[i];
nSensors++;
}
return nSensors;
}
void USART0_Transmit(unsigned char data)
{
while (!(UCSRA & (1<<UDRE))) ;
UDR = data;
}
void tx(char *data)
{
while (*data) USART0_Transmit(*data++);
}
unsigned char rx(void)
{
while (!(UCSRA & (1<<RXC))) ;
return UDR;
}
void USART0_Init(void)
{
UCSRB |= (1 << RXEN) | (1 << TXEN);
UCSRC |= (1<<URSEL) |(1 << UCSZ0)| (1 << UCSZ1);//Use 8-bit char
UBRRL = 207;
UBRRH = 0x00;
PORTC|=0x20;
tx('a');
_delay_ms(50);
recieve_enable();
}
int main ( void )
//The program itself
{
USART0_Init();
uint8_t nSensors, i;
uint8_t subzero, cel, cel_frac_bits;
uint8_t state = 0;
DDRB = 128; // oiiiiiii
PORTB = 0; // iiiiiiii
DDRD = 68; // ioiiioii
PORTD = 0; // iiiiiiii
PORTB=255;
PORTC |=0x20;
tx("POWER IS DOWN");
PORTB=00; _delay_ms(50);
char s [16];
unsigned char degree_sign = 0x01;
init();
abc:
PORTC=255;
tx("enter s\r\n");
PORTC=0;
char b=rx();
//PORTC=255;
if (b!='s')
{
goto abc;
}
for (ever)
{
nSensors = search_sensors();
delayintr(200);
if (nSensors != 255)
{
if ( DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL ) == DS18X20_OK)
{
// delay_ms(DS18B20_TCONV_12BIT);
for ( i=0; i<nSensors; i++ )
{
if ( DS18X20_read_meas( &gSensorIDs[i][0], &subzero, &cel, &cel_frac_bits) == DS18X20_OK )
{
if (cel_frac_bits > 9)
cel_frac_bits = cel_frac_bits / 10;
if (subzero == 0)
sprintf(s, "S%d = %d.%d %cC ", i+1, cel, cel_frac_bits, degree_sign );
else sprintf(s, "S%d = -%d.%d %cC ", i+1, cel, cel_frac_bits, degree_sign);
tx(s);
tx("\r");
}
PORTB=255;
}
tx(".\n");
goto abc;
}
}
// }
//
}
return 0;
}
2shared - download sim-mega8.DSN
plz check if there is problem with hardware or code for 485