Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[AVR] Help me on Atmega32 interface with SHT25 sensor through I2C protocol !!!

Status
Not open for further replies.

zeshan_hyder@hotmail.com

Newbie level 3
Joined
Feb 14, 2014
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
34
hi all,

I am new to micro-controller projects. for my semester project, i want to interface atmega32 with SHT25 tempreture sensor through i2c protocol. i m using proteus ISIS for simulation before implementation.

i want to get tempreture readings from SHT25 and display the readings on portA in binary format. but my circuit and codes are not working and i dont know what is the problem.

code:
=====

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <util/delay.h>
 
 
void i2c_init (void)
{
    TWSR = 0x00;
    TWBR = 0x47;
    TWCR = 0x04;
}
 
void i2c_start (void)
{
    TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
    while ((TWCR & (1<<TWINT)) == 0);
}
 
void i2c_write (unsigned char data)
{
    TWDR = data;
    TWCR = (1 << TWINT) | (1 << TWEN);
    while ((TWCR & (1<<TWINT)) == 0);
}
 
unsigned char i2c_read (unsigned char isLast)
{
    if (isLast == 0)
        
    TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWEA);
    
    else
    
    TWCR = (1<<TWINT) | (1<<TWEN);
    
    while ((TWCR & (1 << TWINT)) == 0);
        
    return TWDR;
}
 
void i2c_stop()
{
    TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);
}
 
int main()
 { 
unsigned char i = 0;
     DDRA = 0xFF;
     i2c_init();
     i2c_start();
     i2c_write(0b00000101);
     i=i2c_read(1);
     PORTA = 1;
     i2c_stop();
     
     while(1);
        return 0; 
 }

 

Attachments

  • i2c_1.png
    i2c_1.png
    109 KB · Views: 142
Last edited by a moderator:

Check this one...
Code:
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <util/delay.h>
 
 
void i2c_init (void)
{
    TWSR = 0x00;
    TWBR = 0x47;
    TWCR = 0x04;
}
 
void i2c_start (void)
{
    TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
    while ((TWCR & (1<<TWINT)) == 0);
}
 
void i2c_write (unsigned char data)
{
    TWDR = data;
    TWCR = (1 << TWINT) | (1 << TWEN);
    while ((TWCR & (1<<TWINT)) == 0);
}
 
unsigned char i2c_read (unsigned char isLast)
{
    if (isLast == 0)
        
    TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWEA);
    
    else
    
    TWCR = (1<<TWINT) | (1<<TWEN);
    
    while ((TWCR & (1 << TWINT)) == 0);
        
    return TWDR;
}
 
void i2c_stop()
{
    TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);
}
 
int main()
 { 
unsigned char i = 0;
     DDRA = 0xFF;
     i2c_init();
     i2c_start();
     i2c_write(0b00000101);
     i=i2c_read(1);
     PORTA = i;
     i2c_stop();
     
     while(1);
        return 0; 
 }
 

the code, circuit digram and simulation log has been attached with the post. what else you need dear???
 

ok, probably I did´t clearly gave the point, but once you said that circuit and codes are not working, it is necessary know what debug tests you already performed at each part. This way we can focus attention at the hardware or at the firmware.

I could suggest you try separate each critical routine ( e.g : LCD, I2C, etc... ) in order to individually approve working of each one, because simulating entire program at once become difficult to determine exactly on what point the code fails.




+++
 

i like your problem finding approach, but what i m trying to do has very simple setup and it couldnt be much more simpler to test the working of each part. you can take a look on my circuit, codes and simulation log to see whats wrong.

it has no lcd, eprom etc.

**broken link removed**

also take a look at datasheet, if you like to..

Thanks
zeeshan haider
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top